fix(sqllab): run previous state query (#29230)

This commit is contained in:
JUST.in DO IT 2024-06-12 15:04:19 -07:00 committed by GitHub
parent f2d5bbc671
commit a88979631e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 40 additions and 4 deletions

View File

@ -134,11 +134,12 @@ export const convertQueryToClient = fieldConverter(queryClientMapping);
export function getUpToDateQuery(rootState, queryEditor, key) {
const {
sqlLab: { unsavedQueryEditor },
sqlLab: { unsavedQueryEditor, queryEditors },
} = rootState;
const id = key ?? queryEditor.id;
return {
...queryEditor,
id,
...queryEditors.find(qe => qe.id === id),
...(id === unsavedQueryEditor.id && unsavedQueryEditor),
};
}

View File

@ -36,6 +36,29 @@ import {
const middlewares = [thunk];
const mockStore = configureMockStore(middlewares);
describe('getUpToDateQuery', () => {
test('should return the up to date query editor state', () => {
const outOfUpdatedQueryEditor = {
...defaultQueryEditor,
schema: null,
sql: 'SELECT ...',
};
const queryEditor = {
...defaultQueryEditor,
sql: 'SELECT * FROM table',
};
const state = {
sqlLab: {
queryEditors: [queryEditor],
unsavedQueryEditor: {},
},
};
expect(actions.getUpToDateQuery(state, outOfUpdatedQueryEditor)).toEqual(
queryEditor,
);
});
});
describe('async actions', () => {
const mockBigNumber = '9223372036854775807';
const queryEditor = {
@ -715,7 +738,13 @@ describe('async actions', () => {
it('updates the tab state in the backend', () => {
expect.assertions(2);
const store = mockStore(initialState);
const store = mockStore({
...initialState,
sqlLab: {
...initialState.sqlLab,
queryEditors: [queryEditor],
},
});
const request = actions.queryEditorSetAndSaveSql(queryEditor, sql);
return request(store.dispatch, store.getState).then(() => {
expect(store.getActions()).toEqual(expectedActions);
@ -731,7 +760,13 @@ describe('async actions', () => {
feature => !(feature === 'SQLLAB_BACKEND_PERSISTENCE'),
);
const store = mockStore(initialState);
const store = mockStore({
...initialState,
sqlLab: {
...initialState.sqlLab,
queryEditors: [queryEditor],
},
});
const request = actions.queryEditorSetAndSaveSql(queryEditor, sql);
request(store.dispatch, store.getState);