fix(sqllab): run previous state query (#29230)
This commit is contained in:
parent
f2d5bbc671
commit
a88979631e
|
|
@ -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),
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue