From 9063106f44d4e00a748854485a062c49063e64d6 Mon Sep 17 00:00:00 2001 From: "Michael S. Molina" Date: Tue, 1 Aug 2023 19:05:15 -0300 Subject: [PATCH] Adds test --- .../src/explore/components/SaveModal.test.jsx | 55 ++++++++++++------- 1 file changed, 34 insertions(+), 21 deletions(-) diff --git a/superset-frontend/src/explore/components/SaveModal.test.jsx b/superset-frontend/src/explore/components/SaveModal.test.jsx index d9d6f2983d67b..bdb93e542935d 100644 --- a/superset-frontend/src/explore/components/SaveModal.test.jsx +++ b/superset-frontend/src/explore/components/SaveModal.test.jsx @@ -24,7 +24,6 @@ import { bindActionCreators } from 'redux'; import { shallow } from 'enzyme'; import { Radio } from 'src/components/Radio'; import Button from 'src/components/Button'; -import sinon from 'sinon'; import fetchMock from 'fetch-mock'; import * as saveModalActions from 'src/explore/actions/saveModalActions'; @@ -131,7 +130,7 @@ test('renders a Modal with the right set of components', () => { expect(footerWrapper.find(Button)).toHaveLength(3); }); -test('renders the right footer buttons when existing dashboard selected', () => { +test('renders the right footer buttons', () => { const wrapper = getWrapper(); const footerWrapper = shallow(wrapper.find(StyledModal).props().footer); const saveAndGoDash = footerWrapper @@ -142,18 +141,43 @@ test('renders the right footer buttons when existing dashboard selected', () => expect(saveAndGoDash.props.children).toBe('Save & go to dashboard'); }); -test('renders the right footer buttons when new dashboard selected', () => { +test('does not render a message when overriding', () => { + const wrapper = getWrapper(); + wrapper.setState({ + action: 'overwrite', + }); + expect( + wrapper.find('[message="A new chart will be created."]'), + ).not.toExist(); +}); + +test('renders a message when saving as', () => { + const wrapper = getWrapper(); + wrapper.setState({ + action: 'saveas', + }); + expect(wrapper.find('[message="A new chart will be created."]')).toExist(); +}); + +test('renders a message when a new dashboard is selected', () => { const wrapper = getWrapper(); wrapper.setState({ dashboard: { label: 'Test new dashboard', value: 'Test new dashboard' }, }); - const footerWrapper = shallow(wrapper.find(StyledModal).props().footer); - const saveAndGoDash = footerWrapper - .find('#btn_modal_save_goto_dash') - .getElement(); - const save = footerWrapper.find('#btn_modal_save').getElement(); - expect(save.props.children).toBe('Save to new dashboard'); - expect(saveAndGoDash.props.children).toBe('Save & go to new dashboard'); + expect( + wrapper.find('[message="A new dashboard will be created."]'), + ).toExist(); +}); + +test('renders a message when saving as with new dashboard', () => { + const wrapper = getWrapper(); + wrapper.setState({ + action: 'saveas', + dashboard: { label: 'Test new dashboard', value: 'Test new dashboard' }, + }); + expect( + wrapper.find('[message="A new chart and dashboard will be created."]'), + ).toExist(); }); test('disables overwrite option for new slice', () => { @@ -197,17 +221,6 @@ test('updates slice name and selected dashboard', () => { expect(wrapper.state().dashboard.value).toBe(dashboardId); }); -test('removes alert', () => { - sinon.spy(defaultProps.actions, 'removeSaveModalAlert'); - const wrapper = getWrapper(); - wrapper.setProps({ alert: 'old alert' }); - - wrapper.instance().removeAlert(); - expect(defaultProps.actions.removeSaveModalAlert.callCount).toBe(1); - expect(wrapper.state().alert).toBeNull(); - defaultProps.actions.removeSaveModalAlert.restore(); -}); - test('set dataset name when chart source is query', () => { const wrapper = getWrapper(queryDefaultProps, queryStore); expect(wrapper.find('[data-test="new-dataset-name"]')).toExist();