Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add more tests to Save Modal specs #2313

Merged
merged 1 commit into from
Mar 14, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions superset/assets/javascripts/explorev2/components/SaveModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ class SaveModal extends React.Component {
}
{this.props.slice &&
<Radio
id="overwrite-radio"
disabled={!this.props.can_overwrite}
checked={this.state.action === 'overwrite'}
onChange={this.changeAction.bind(this, 'overwrite')}
Expand All @@ -150,6 +151,7 @@ class SaveModal extends React.Component {
}

<Radio
id="saveas-radio"
inline
checked={this.state.action === 'saveas'}
onChange={this.changeAction.bind(this, 'saveas')}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ const defaultProps = {
saveSlice: sinon.spy(),
},
form_data: defaultFormData,
user_id: 1,
user_id: '1',
dashboards: [],
slice: {},
};

Expand All @@ -31,4 +32,44 @@ describe('SaveModal', () => {
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(<SaveModal {...defaultProps} />);
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(<SaveModal {...defaultProps} />);
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(<SaveModal {...defaultProps} />);
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(<SaveModal {...defaultProps} />);
const overwriteRadio = wrapperForOverwrite.find('#overwrite-radio');
overwriteRadio.simulate('click');
expect(wrapperForOverwrite.state().action).to.equal('overwrite');
});
});