diff --git a/superset-frontend/src/dashboard/components/nativeFilters/FiltersConfigModal/FiltersConfigModal.test.tsx b/superset-frontend/src/dashboard/components/nativeFilters/FiltersConfigModal/FiltersConfigModal.test.tsx index 9131e591add..36f9977c2ce 100644 --- a/superset-frontend/src/dashboard/components/nativeFilters/FiltersConfigModal/FiltersConfigModal.test.tsx +++ b/superset-frontend/src/dashboard/components/nativeFilters/FiltersConfigModal/FiltersConfigModal.test.tsx @@ -696,56 +696,59 @@ test.skip('updates sidebar title when filter name changes', async () => { test('modifies the name of a filter', async () => { jest.useFakeTimers(); - try { - const nativeFilterConfig = [ - buildNativeFilter('NATIVE_FILTER-1', 'state', []), - buildNativeFilter('NATIVE_FILTER-2', 'country', []), - ]; - const state = { - ...defaultState(), - dashboardInfo: { - metadata: { - native_filter_configuration: nativeFilterConfig, - }, + const nativeFilterConfig = [ + buildNativeFilter('NATIVE_FILTER-1', 'state', []), + buildNativeFilter('NATIVE_FILTER-2', 'country', []), + ]; + + const state = { + ...defaultState(), + dashboardInfo: { + metadata: { + native_filter_configuration: nativeFilterConfig, }, - dashboardLayout, - }; + }, + dashboardLayout, + }; - const onSave = jest.fn(); + const onSave = jest.fn(); - defaultRender(state, { - ...props, - createNewOnOpen: false, - onSave, - }); + defaultRender(state, { + ...props, + createNewOnOpen: false, + onSave, + }); - const filterNameInput = screen.getByRole('textbox', { - name: FILTER_NAME_REGEX, - }); + const filterNameInput = screen.getByRole('textbox', { + name: FILTER_NAME_REGEX, + }); - await userEvent.clear(filterNameInput); - await userEvent.type(filterNameInput, 'New Filter Name'); + await userEvent.clear(filterNameInput); + await userEvent.type(filterNameInput, 'New Filter Name'); - jest.runAllTimers(); + // Flush the 500ms debounce on the filter name input. + // Using advanceTimersByTime instead of runAllTimers to avoid infinite + // loops caused by recursive antd animation timers. + jest.advanceTimersByTime(1000); - await userEvent.click(screen.getByRole('button', { name: SAVE_REGEX })); + // Switch back to real timers so waitFor polling works + jest.useRealTimers(); - await waitFor(() => - expect(onSave).toHaveBeenCalledWith( - expect.objectContaining({ - filterChanges: expect.objectContaining({ - modified: expect.arrayContaining([ - expect.objectContaining({ name: 'New Filter Name' }), - ]), - }), + await userEvent.click(screen.getByRole('button', { name: SAVE_REGEX })); + + await waitFor(() => + expect(onSave).toHaveBeenCalledWith( + expect.objectContaining({ + filterChanges: expect.objectContaining({ + modified: expect.arrayContaining([ + expect.objectContaining({ name: 'New Filter Name' }), + ]), }), - ), - ); - } finally { - jest.useRealTimers(); - } -}); + }), + ), + ); +}, 30000); test('renders a filter with a chart containing BigInt values', async () => { const nativeFilterConfig = [