feat(frontend): add dataset cache clearing utilities and integration (#35264)

Co-authored-by: Claude <noreply@anthropic.com>
Co-authored-by: Geidō <60598000+geido@users.noreply.github.com>
This commit is contained in:
Mehmet Salih Yavuz
2025-11-12 17:23:37 +03:00
committed by GitHub
parent 9fbfcf0ccd
commit 0b535b792e
6 changed files with 303 additions and 4 deletions

View File

@@ -61,6 +61,10 @@ jest.mock('src/SqlLab/actions/sqlLab', () => ({
jest.mock('src/explore/exploreUtils/formData', () => ({
postFormData: jest.fn(),
}));
jest.mock('src/utils/cachedSupersetGet', () => ({
...jest.requireActual('src/utils/cachedSupersetGet'),
clearDatasetCache: jest.fn(),
}));
// eslint-disable-next-line no-restricted-globals -- TODO: Migrate from describe blocks
describe('SaveDatasetModal', () => {
@@ -336,4 +340,42 @@ describe('SaveDatasetModal', () => {
templateParams: undefined,
});
});
test('clears dataset cache when creating new dataset', async () => {
const clearDatasetCache = jest.spyOn(
require('src/utils/cachedSupersetGet'),
'clearDatasetCache',
);
const postFormData = jest.spyOn(
require('src/explore/exploreUtils/formData'),
'postFormData',
);
const dummyDispatch = jest.fn().mockResolvedValue({ id: 123 });
useDispatchMock.mockReturnValue(dummyDispatch);
useSelectorMock.mockReturnValue({ ...user });
postFormData.mockResolvedValue('chart_key_123');
render(<SaveDatasetModal {...mockedProps} />, { useRedux: true });
const inputFieldText = screen.getByDisplayValue(/unimportant/i);
fireEvent.change(inputFieldText, { target: { value: 'my dataset' } });
const saveConfirmationBtn = screen.getByRole('button', {
name: /save/i,
});
userEvent.click(saveConfirmationBtn);
await waitFor(() => {
expect(clearDatasetCache).toHaveBeenCalledWith(123);
});
});
test('clearDatasetCache is imported and available', () => {
const clearDatasetCache =
require('src/utils/cachedSupersetGet').clearDatasetCache;
expect(clearDatasetCache).toBeDefined();
expect(typeof clearDatasetCache).toBe('function');
});
});