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:
David Aaron Suddjian
2019-09-30 23:09:45 -07:00
committed by Grace Guo
parent d55fe54198
commit fbbc5f0577
10 changed files with 124 additions and 31 deletions

View File

@@ -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);
});
});