mirror of
https://github.com/apache/superset.git
synced 2026-04-20 00:24:38 +00:00
Allow overwriting a SQLLab query that has previously been saved (#8298)
* ignore direnv * allow overwriting saved queries * simplify state management a little bit * fix tests and linting
This commit is contained in:
committed by
Grace Guo
parent
d55fe54198
commit
fbbc5f0577
@@ -19,14 +19,18 @@
|
||||
import React from 'react';
|
||||
import { FormControl } from 'react-bootstrap';
|
||||
import { shallow } from 'enzyme';
|
||||
import * as sinon from 'sinon';
|
||||
import SaveQuery from '../../../src/SqlLab/components/SaveQuery';
|
||||
import ModalTrigger from '../../../src/components/ModalTrigger';
|
||||
import Button from '../../../src/components/Button';
|
||||
|
||||
describe('SavedQuery', () => {
|
||||
const mockedProps = {
|
||||
dbId: 1,
|
||||
schema: 'main',
|
||||
sql: 'SELECT * FROM t',
|
||||
query: {
|
||||
dbId: 1,
|
||||
schema: 'main',
|
||||
sql: 'SELECT * FROM t',
|
||||
},
|
||||
defaultLabel: 'untitled',
|
||||
animation: false,
|
||||
};
|
||||
@@ -54,4 +58,27 @@ describe('SavedQuery', () => {
|
||||
const modal = shallow(wrapper.instance().renderModalBody());
|
||||
expect(modal.find(FormControl)).toHaveLength(2);
|
||||
});
|
||||
it('has a save button if this is a new query', () => {
|
||||
const saveSpy = sinon.spy();
|
||||
const wrapper = shallow(<SaveQuery {...mockedProps} onSave={saveSpy} />);
|
||||
const modal = shallow(wrapper.instance().renderModalBody());
|
||||
expect(modal.find(Button)).toHaveLength(2);
|
||||
modal.find(Button).at(0).simulate('click');
|
||||
expect(saveSpy.calledOnce).toBe(true);
|
||||
});
|
||||
it('has an update button if this is an existing query', () => {
|
||||
const updateSpy = sinon.spy();
|
||||
const props = {
|
||||
...mockedProps,
|
||||
query: {
|
||||
...mockedProps.query,
|
||||
remoteId: '42',
|
||||
},
|
||||
};
|
||||
const wrapper = shallow(<SaveQuery {...props} onUpdate={updateSpy} />);
|
||||
const modal = shallow(wrapper.instance().renderModalBody());
|
||||
expect(modal.find(Button)).toHaveLength(3);
|
||||
modal.find(Button).at(0).simulate('click');
|
||||
expect(updateSpy.calledOnce).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user