From 1cf4a1b3ea82aace1d5b416be84f44b55954f522 Mon Sep 17 00:00:00 2001 From: Moriah Kreeger Date: Thu, 17 Dec 2020 23:50:17 -0800 Subject: [PATCH] fix: updates to alert/report modal + more tests (#12045) Co-authored-by: Tai Dupree --- .../CRUD/alert/AlertReportModal_spec.jsx | 88 ++++++++++++++++++- .../src/views/CRUD/alert/AlertReportModal.tsx | 11 ++- 2 files changed, 93 insertions(+), 6 deletions(-) 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 a24b9526a7..8fc01d6548 100644 --- a/superset-frontend/spec/javascripts/views/CRUD/alert/AlertReportModal_spec.jsx +++ b/superset-frontend/spec/javascripts/views/CRUD/alert/AlertReportModal_spec.jsx @@ -23,6 +23,10 @@ import configureStore from 'redux-mock-store'; import fetchMock from 'fetch-mock'; import AlertReportModal from 'src/views/CRUD/alert/AlertReportModal'; import Modal from 'src/common/components/Modal'; +import { AsyncSelect } from 'src/components/Select'; +import { Radio } from 'src/common/components/Radio'; +import { GraySelect as Select } from 'src/common/components/Select'; +import { Switch } from 'src/common/components/Switch'; import waitForComponentToPaint from 'spec/helpers/waitForComponentToPaint'; import { styledMount as mount } from 'spec/helpers/theming'; @@ -49,10 +53,10 @@ const mockedProps = { }; // Related mocks -const ownersEndpoint = 'glob:*/api/v1/dashboard/related/owners?*'; -const databaseEndpoint = 'glob:*/api/v1/dataset/related/database?*'; -const dashboardEndpoint = 'glob:*/api/v1/dashboard?*'; -const chartEndpoint = 'glob:*/api/v1/chart?*'; +const ownersEndpoint = 'glob:*/api/v1/alert/related/owners?*'; +const databaseEndpoint = 'glob:*/api/v1/alert/related/database?*'; +const dashboardEndpoint = 'glob:*/api/v1/alert/related/dashboard?*'; +const chartEndpoint = 'glob:*/api/v1/alert/related/chart?*'; fetchMock.get(ownersEndpoint, { result: [], @@ -127,11 +131,87 @@ describe('AlertReportModal', () => { ).toEqual('Edit Report'); }); + // Fields it('renders input element for name', () => { expect(wrapper.find('input[name="name"]')).toExist(); }); + it('renders three async select elements when in report mode', () => { + expect(wrapper.find(AsyncSelect)).toExist(); + expect(wrapper.find(AsyncSelect)).toHaveLength(3); + }); + + it('renders four async select elements when in alert mode', async () => { + const props = { + ...mockedProps, + isReport: false, + }; + + const addWrapper = await mountAndWait(props); + + expect(addWrapper.find(AsyncSelect)).toExist(); + expect(addWrapper.find(AsyncSelect)).toHaveLength(4); + }); + + it('renders Switch element', () => { + expect(wrapper.find(Switch)).toExist(); + }); + it('renders input element for description', () => { expect(wrapper.find('input[name="description"]')).toExist(); }); + + it('renders input element for sql in alert mode only', async () => { + const props = { + ...mockedProps, + isReport: false, + }; + + const addWrapper = await mountAndWait(props); + + expect(wrapper.find('textarea[name="sql"]')).toHaveLength(0); + expect(addWrapper.find('textarea[name="sql"]')).toExist(); + }); + + it('renders one select element when in report mode', () => { + expect(wrapper.find(Select)).toExist(); + expect(wrapper.find(Select)).toHaveLength(1); + }); + + it('renders two select elements when in alert mode', async () => { + const props = { + ...mockedProps, + isReport: false, + }; + + const addWrapper = await mountAndWait(props); + + expect(addWrapper.find(Select)).toExist(); + expect(addWrapper.find(Select)).toHaveLength(2); + }); + + it('renders value input element when in alert mode', async () => { + const props = { + ...mockedProps, + isReport: false, + }; + + const addWrapper = await mountAndWait(props); + + expect(wrapper.find('input[name="threshold"]')).toHaveLength(0); + expect(addWrapper.find('input[name="threshold"]')).toExist(); + }); + + it('renders four radio buttons', () => { + expect(wrapper.find(Radio)).toExist(); + expect(wrapper.find(Radio)).toHaveLength(4); + }); + + it('renders input element for working timeout', () => { + expect(wrapper.find('input[name="working_timeout"]')).toExist(); + }); + + it('renders input element for grace period', () => { + expect(wrapper.find('input[name="grace_period"]')).toExist(); + }); }); diff --git a/superset-frontend/src/views/CRUD/alert/AlertReportModal.tsx b/superset-frontend/src/views/CRUD/alert/AlertReportModal.tsx index 2daeec6eb6..e8a01a5f6b 100644 --- a/superset-frontend/src/views/CRUD/alert/AlertReportModal.tsx +++ b/superset-frontend/src/views/CRUD/alert/AlertReportModal.tsx @@ -225,7 +225,7 @@ export const StyledInputContainer = styled.div` } textarea { - height: 160px; + height: 300px; resize: none; } @@ -246,6 +246,11 @@ export const StyledInputContainer = styled.div` border: 1px solid ${({ theme }) => theme.colors.grayscale.light2}; border-radius: ${({ theme }) => theme.gridUnit}px; + .ant-select-selection-placeholder, + .ant-select-selection-item { + line-height: 24px; + } + &[name='description'] { flex: 1 1 auto; } @@ -1023,12 +1028,14 @@ const AlertReportModal: FunctionComponent = ({ return ( {isEditMode ? ( @@ -1141,7 +1148,7 @@ const AlertReportModal: FunctionComponent = ({
- {t('Alert If...')} + {t('Trigger Alert If...')} *