diff --git a/superset-frontend/spec/javascripts/views/CRUD/alert/AlertReportModal_spec.jsx b/superset-frontend/spec/javascripts/views/CRUD/alert/AlertReportModal_spec.jsx index 5f413305bfc..3f4931029c3 100644 --- a/superset-frontend/spec/javascripts/views/CRUD/alert/AlertReportModal_spec.jsx +++ b/superset-frontend/spec/javascripts/views/CRUD/alert/AlertReportModal_spec.jsx @@ -105,6 +105,11 @@ describe('AlertReportModal', () => { expect(wrapper.find(Modal)).toExist(); }); + it('render a empty modal', () => { + expect(wrapper.find('input[name="name"]').text()).toEqual(''); + expect(wrapper.find('input[name="description"]').text()).toEqual(''); + }); + it('renders add header for report when no alert is included, and isReport is true', async () => { const addWrapper = await mountAndWait(); @@ -126,10 +131,22 @@ describe('AlertReportModal', () => { ).toEqual('Add Alert'); }); - it.skip('renders edit header when alert prop is included', () => { + it('renders edit modal', async () => { + const props = { + ...mockedProps, + alert: mockData, + }; + + const editWrapper = await mountAndWait(props); expect( - wrapper.find('[data-test="alert-report-modal-title"]').text(), + editWrapper.find('[data-test="alert-report-modal-title"]').text(), ).toEqual('Edit Report'); + expect(editWrapper.find('input[name="name"]').props().value).toEqual( + 'test report', + ); + expect(editWrapper.find('input[name="description"]').props().value).toEqual( + 'test report description', + ); }); // Fields diff --git a/superset-frontend/src/views/CRUD/alert/AlertList.tsx b/superset-frontend/src/views/CRUD/alert/AlertList.tsx index 192b0f5825b..42a91bf6b65 100644 --- a/superset-frontend/src/views/CRUD/alert/AlertList.tsx +++ b/superset-frontend/src/views/CRUD/alert/AlertList.tsx @@ -435,6 +435,7 @@ function AlertList({ layer={currentAlert} onHide={() => { setAlertModalOpen(false); + setCurrentAlert(null); refreshData(); }} show={alertModalOpen} diff --git a/superset-frontend/src/views/CRUD/alert/AlertReportModal.tsx b/superset-frontend/src/views/CRUD/alert/AlertReportModal.tsx index f75f6f99d6a..607f297a467 100644 --- a/superset-frontend/src/views/CRUD/alert/AlertReportModal.tsx +++ b/superset-frontend/src/views/CRUD/alert/AlertReportModal.tsx @@ -104,6 +104,19 @@ const RETENTION_OPTIONS = [ const DEFAULT_RETENTION = 90; const DEFAULT_WORKING_TIMEOUT = 3600; const DEFAULT_CRON_VALUE = '* * * * *'; // every minute +const DEFAULT_ALERT = { + active: true, + crontab: DEFAULT_CRON_VALUE, + log_retention: DEFAULT_RETENTION, + working_timeout: DEFAULT_WORKING_TIMEOUT, + name: '', + owners: [], + recipients: [], + sql: '', + validator_config_json: {}, + validator_type: '', + grace_period: undefined, +}; const StyledIcon = styled(Icon)` margin: auto ${({ theme }) => theme.gridUnit * 2}px auto 0; @@ -563,6 +576,8 @@ const AlertReportModal: FunctionComponent = ({ clearError(); setIsHidden(true); onHide(); + setCurrentAlert({ ...DEFAULT_ALERT }); + setNotificationSettings([]); }; const onSave = () => { @@ -935,19 +950,7 @@ const AlertReportModal: FunctionComponent = ({ !isEditMode && (!currentAlert || currentAlert.id || (isHidden && show)) ) { - setCurrentAlert({ - active: true, - crontab: DEFAULT_CRON_VALUE, - log_retention: DEFAULT_RETENTION, - working_timeout: DEFAULT_WORKING_TIMEOUT, - name: '', - owners: [], - recipients: [], - sql: '', - validator_config_json: {}, - validator_type: '', - }); - + setCurrentAlert({ ...DEFAULT_ALERT }); setNotificationSettings([]); setNotificationAddState('active'); } @@ -1282,7 +1285,7 @@ const AlertReportModal: FunctionComponent = ({