mirror of
https://github.com/apache/superset.git
synced 2024-09-06 22:07:34 -04:00
fix: queryEditor bug (#16452)
* queryEditor bug * update tests Co-authored-by: Elizabeth Thompson <eschutho@gmail.com>
This commit is contained in:
parent
fd6456186d
commit
ee2eccdb67
@ -399,7 +399,7 @@ describe('async actions', () => {
|
|||||||
|
|
||||||
let isFeatureEnabledMock;
|
let isFeatureEnabledMock;
|
||||||
|
|
||||||
beforeAll(() => {
|
beforeEach(() => {
|
||||||
isFeatureEnabledMock = jest
|
isFeatureEnabledMock = jest
|
||||||
.spyOn(featureFlags, 'isFeatureEnabled')
|
.spyOn(featureFlags, 'isFeatureEnabled')
|
||||||
.mockImplementation(
|
.mockImplementation(
|
||||||
@ -407,7 +407,7 @@ describe('async actions', () => {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
afterAll(() => {
|
afterEach(() => {
|
||||||
isFeatureEnabledMock.mockRestore();
|
isFeatureEnabledMock.mockRestore();
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -612,9 +612,29 @@ describe('async actions', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('queryEditorSetSql', () => {
|
describe('queryEditorSetSql', () => {
|
||||||
it('updates the tab state in the backend', () => {
|
describe('with backend persistence flag on', () => {
|
||||||
expect.assertions(2);
|
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 sql = 'SELECT * ';
|
||||||
const store = mockStore({});
|
const store = mockStore({});
|
||||||
const expectedActions = [
|
const expectedActions = [
|
||||||
@ -624,12 +644,12 @@ describe('async actions', () => {
|
|||||||
sql,
|
sql,
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
return store
|
|
||||||
.dispatch(actions.queryEditorSetSql(queryEditor, sql))
|
store.dispatch(actions.queryEditorSetSql(queryEditor, sql));
|
||||||
.then(() => {
|
|
||||||
expect(store.getActions()).toEqual(expectedActions);
|
expect(store.getActions()).toEqual(expectedActions);
|
||||||
expect(fetchMock.calls(updateTabStateEndpoint)).toHaveLength(1);
|
expect(fetchMock.calls(updateTabStateEndpoint)).toHaveLength(0);
|
||||||
});
|
backendPersistenceOffMock.mockRestore();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -898,16 +898,11 @@ export function updateSavedQuery(query) {
|
|||||||
|
|
||||||
export function queryEditorSetSql(queryEditor, sql) {
|
export function queryEditorSetSql(queryEditor, sql) {
|
||||||
return function (dispatch) {
|
return function (dispatch) {
|
||||||
const sync = isFeatureEnabled(FeatureFlag.SQLLAB_BACKEND_PERSISTENCE)
|
if (isFeatureEnabled(FeatureFlag.SQLLAB_BACKEND_PERSISTENCE)) {
|
||||||
? SupersetClient.put({
|
return SupersetClient.put({
|
||||||
endpoint: encodeURI(`/tabstateview/${queryEditor.id}`),
|
endpoint: encodeURI(`/tabstateview/${queryEditor.id}`),
|
||||||
postPayload: { sql, latest_query_id: queryEditor.latestQueryId },
|
postPayload: { sql, latest_query_id: queryEditor.latestQueryId },
|
||||||
})
|
}).catch(() =>
|
||||||
: Promise.resolve();
|
|
||||||
|
|
||||||
return sync
|
|
||||||
.then(() => dispatch({ type: QUERY_EDITOR_SET_SQL, queryEditor, sql }))
|
|
||||||
.catch(() =>
|
|
||||||
dispatch(
|
dispatch(
|
||||||
addDangerToast(
|
addDangerToast(
|
||||||
t(
|
t(
|
||||||
@ -918,6 +913,8 @@ export function queryEditorSetSql(queryEditor, sql) {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
return dispatch({ type: QUERY_EDITOR_SET_SQL, queryEditor, sql });
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user