From 4401ef16885ae472a6048e0a285ed5e196aa4527 Mon Sep 17 00:00:00 2001 From: Vera Liu Date: Mon, 27 Feb 2017 15:32:33 -0800 Subject: [PATCH] Add more tests to Save Modal specs --- .../explorev2/components/SaveModal.js | 2 + .../explorev2/components/SaveModal_spec.js | 43 ++++++++++++++++++- 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/superset/assets/javascripts/explorev2/components/SaveModal.js b/superset/assets/javascripts/explorev2/components/SaveModal.js index 2450ca47e3224..6be46505492a1 100644 --- a/superset/assets/javascripts/explorev2/components/SaveModal.js +++ b/superset/assets/javascripts/explorev2/components/SaveModal.js @@ -141,6 +141,7 @@ class SaveModal extends React.Component { } {this.props.slice && { expect(wrapper.find(Button)).to.have.lengthOf(2); expect(wrapper.find(Radio)).to.have.lengthOf(5); }); + + it('does not show overwrite option for new slice', () => { + defaultProps.slice = null; + const wrapperNewSlice = shallow(); + expect(wrapperNewSlice.find('#overwrite-radio')).to.have.lengthOf(0); + expect(wrapperNewSlice.find('#saveas-radio')).to.have.lengthOf(1); + }); + + it('disable overwrite option for non-owner', () => { + defaultProps.slice = {}; + defaultProps.can_overwrite = false; + const wrapperForNonOwner = shallow(); + const overwriteRadio = wrapperForNonOwner.find('#overwrite-radio'); + expect(overwriteRadio).to.have.lengthOf(1); + expect(overwriteRadio.prop('disabled')).to.equal(true); + }); + + it('saves a new slice', () => { + defaultProps.slice = { + slice_id: 1, + slice_name: 'title', + }; + defaultProps.can_overwrite = false; + const wrapperForNewSlice = shallow(); + const saveasRadio = wrapperForNewSlice.find('#saveas-radio'); + saveasRadio.simulate('click'); + expect(wrapperForNewSlice.state().action).to.equal('saveas'); + }); + + it('overwrite a slice', () => { + defaultProps.slice = { + slice_id: 1, + slice_name: 'title', + }; + defaultProps.can_overwrite = true; + const wrapperForOverwrite = shallow(); + const overwriteRadio = wrapperForOverwrite.find('#overwrite-radio'); + overwriteRadio.simulate('click'); + expect(wrapperForOverwrite.state().action).to.equal('overwrite'); + }); });