mirror of
https://github.com/apache/superset.git
synced 2026-07-16 11:46:09 +00:00
fix(sqllab): reflect query history deletion without page refresh (#41019)
Co-authored-by: Evan Rusackas <evan@rusackas.com> Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -34,6 +34,12 @@ import {
|
||||
import { SupersetClient, isFeatureEnabled } from '@superset-ui/core';
|
||||
import { ADD_TOAST } from 'src/components/MessageToasts/actions';
|
||||
import { EMPTY_STATE_QE_ID } from 'src/SqlLab/hooks/useQueryEditor';
|
||||
import { api } from 'src/hooks/apiResources/queryApi';
|
||||
import {
|
||||
queryHistoryApi,
|
||||
type QueryResult,
|
||||
} from 'src/hooks/apiResources/queries';
|
||||
import { defaultStore } from 'spec/helpers/testing-library';
|
||||
import { ToastType } from '../../components/MessageToasts/types';
|
||||
|
||||
const isFeatureEnabledMock = isFeatureEnabled as unknown as jest.Mock;
|
||||
@@ -1108,6 +1114,80 @@ describe('async actions', () => {
|
||||
});
|
||||
});
|
||||
|
||||
test('removeQuery removes the deleted query from the editorQueries cache', async () => {
|
||||
isFeatureEnabledMock.mockReturnValue(false);
|
||||
const editorId = 'editor1';
|
||||
const queryToRemove = {
|
||||
...query,
|
||||
id: 'queryToRemove',
|
||||
sqlEditorId: editorId,
|
||||
};
|
||||
|
||||
await defaultStore.dispatch(
|
||||
queryHistoryApi.util.upsertQueryData('editorQueries', { editorId }, {
|
||||
count: 2,
|
||||
ids: [],
|
||||
result: [{ id: 'queryToRemove' }, { id: 'keep' }],
|
||||
} as unknown as QueryResult),
|
||||
);
|
||||
|
||||
await defaultStore.dispatch(
|
||||
actions.removeQuery(queryToRemove) as unknown as AnyAction,
|
||||
);
|
||||
|
||||
const { data } = queryHistoryApi.endpoints.editorQueries.select({
|
||||
editorId,
|
||||
})(defaultStore.getState());
|
||||
|
||||
expect(data).toEqual({
|
||||
count: 1,
|
||||
ids: [],
|
||||
result: [{ id: 'keep' }],
|
||||
});
|
||||
|
||||
defaultStore.dispatch(api.util.resetApiState());
|
||||
});
|
||||
|
||||
test('removeQuery removes duplicate cache entries for the deleted query', async () => {
|
||||
isFeatureEnabledMock.mockReturnValue(false);
|
||||
const editorId = 'editor1';
|
||||
const queryToRemove = {
|
||||
...query,
|
||||
id: 'queryToRemove',
|
||||
sqlEditorId: editorId,
|
||||
};
|
||||
|
||||
// The infinite-scroll merge can append the same query twice when
|
||||
// offsets shift between page fetches; deletion must drop every copy.
|
||||
await defaultStore.dispatch(
|
||||
queryHistoryApi.util.upsertQueryData('editorQueries', { editorId }, {
|
||||
count: 3,
|
||||
ids: [],
|
||||
result: [
|
||||
{ id: 'queryToRemove' },
|
||||
{ id: 'keep' },
|
||||
{ id: 'queryToRemove' },
|
||||
],
|
||||
} as unknown as QueryResult),
|
||||
);
|
||||
|
||||
await defaultStore.dispatch(
|
||||
actions.removeQuery(queryToRemove) as unknown as AnyAction,
|
||||
);
|
||||
|
||||
const { data } = queryHistoryApi.endpoints.editorQueries.select({
|
||||
editorId,
|
||||
})(defaultStore.getState());
|
||||
|
||||
expect(data).toEqual({
|
||||
count: 2,
|
||||
ids: [],
|
||||
result: [{ id: 'keep' }],
|
||||
});
|
||||
|
||||
defaultStore.dispatch(api.util.resetApiState());
|
||||
});
|
||||
|
||||
// eslint-disable-next-line no-restricted-globals -- TODO: Migrate from describe blocks
|
||||
describe('queryEditorSetDb', () => {
|
||||
test('updates the tab state in the backend', () => {
|
||||
|
||||
Reference in New Issue
Block a user