fix: queryEditor bug (#16452)

* queryEditor bug

* update tests

Co-authored-by: Elizabeth Thompson <eschutho@gmail.com>
This commit is contained in:
AAfghahi
2021-08-26 18:20:02 -04:00
committed by GitHub
parent fd6456186d
commit ee2eccdb67
2 changed files with 37 additions and 20 deletions

View File

@@ -399,7 +399,7 @@ describe('async actions', () => {
let isFeatureEnabledMock;
beforeAll(() => {
beforeEach(() => {
isFeatureEnabledMock = jest
.spyOn(featureFlags, 'isFeatureEnabled')
.mockImplementation(
@@ -407,7 +407,7 @@ describe('async actions', () => {
);
});
afterAll(() => {
afterEach(() => {
isFeatureEnabledMock.mockRestore();
});
@@ -612,9 +612,29 @@ describe('async actions', () => {
});
describe('queryEditorSetSql', () => {
it('updates the tab state in the backend', () => {
expect.assertions(2);
describe('with backend persistence flag on', () => {
it('does not update the tab state in the backend', () => {
expect.assertions(2);
const sql = 'SELECT * ';
const store = mockStore({});
return store
.dispatch(actions.queryEditorSetSql(queryEditor, sql))
.then(() => {
expect(store.getActions()).toHaveLength(0);
expect(fetchMock.calls(updateTabStateEndpoint)).toHaveLength(1);
});
});
});
});
describe('with backend persistence flag off', () => {
it('updates the tab state in the backend', () => {
const backendPersistenceOffMock = jest
.spyOn(featureFlags, 'isFeatureEnabled')
.mockImplementation(
feature => !(feature === 'SQLLAB_BACKEND_PERSISTENCE'),
);
const sql = 'SELECT * ';
const store = mockStore({});
const expectedActions = [
@@ -624,12 +644,12 @@ describe('async actions', () => {
sql,
},
];
return store
.dispatch(actions.queryEditorSetSql(queryEditor, sql))
.then(() => {
expect(store.getActions()).toEqual(expectedActions);
expect(fetchMock.calls(updateTabStateEndpoint)).toHaveLength(1);
});
store.dispatch(actions.queryEditorSetSql(queryEditor, sql));
expect(store.getActions()).toEqual(expectedActions);
expect(fetchMock.calls(updateTabStateEndpoint)).toHaveLength(0);
backendPersistenceOffMock.mockRestore();
});
});