fix(test): fix 3 failing tests in DatasetList.listview.test.tsx
**Problem**: 3 tests failing in CI (sharded-jest-tests shard 4):
1. "selecting all datasets shows correct count" - Multiple "Select all" elements found
2. "duplicate...403 forbidden" - Modal not closing before toast assertion
3. "duplicate...500 error" - Modal not closing before toast assertion
**Root Causes**:
**Issue 1**: Ant Design 5.27.6 renders multiple checkboxes with `aria-label="Select all"`
**Issue 2 & 3**: Modal close animations exceed default 8s waitFor timeout
**Solutions**:
1. Use getAllByLabelText and select first checkbox
2. Increase modal close timeout to 10s (lines 1032, 1097)
3. Add async afterEach cleanup for local development
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
diff --git a/superset-frontend/src/pages/DatasetList/DatasetList.listview.test.tsx b/superset-frontend/src/pages/DatasetList/DatasetList.listview.test.tsx
index 5714366..12bf223 100644
--- a/superset-frontend/src/pages/DatasetList/DatasetList.listview.test.tsx
+++ b/superset-frontend/src/pages/DatasetList/DatasetList.listview.test.tsx
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-import { cleanup, screen, waitFor, within } from '@testing-library/react';
+import { act, cleanup, screen, waitFor, within } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import fetchMock from 'fetch-mock';
import rison from 'rison';
@@ -124,7 +124,11 @@
jest.clearAllMocks();
});
-afterEach(() => {
+afterEach(async () => {
+ // Wait for any pending state updates to complete before cleanup
+ await act(async () => {
+ await new Promise(resolve => setTimeout(resolve, 0));
+ });
cleanup();
fetchMock.reset();
jest.restoreAllMocks();
@@ -489,9 +493,10 @@
expect(checkboxes.length).toBeGreaterThan(0);
});
- // Select all checkbox using semantic selector (not DOM order)
- const selectAllCheckbox = screen.getByLabelText('Select all');
- await userEvent.click(selectAllCheckbox);
+ // Select all checkbox using semantic selector
+ // Note: antd renders multiple checkboxes with same aria-label, use first one (table header)
+ const selectAllCheckboxes = screen.getAllByLabelText('Select all');
+ await userEvent.click(selectAllCheckboxes[0]);
// Should show selected count in toolbar (use data-test for reliability)
await waitFor(() => {
@@ -1027,9 +1032,13 @@
await userEvent.click(submitButton);
// Wait for modal to close (error handler closes it)
- await waitFor(() => {
- expect(screen.queryByRole('dialog')).not.toBeInTheDocument();
- });
+ // antd modal close animation can be slow, increase timeout
+ await waitFor(
+ () => {
+ expect(screen.queryByRole('dialog')).not.toBeInTheDocument();
+ },
+ { timeout: 10000 },
+ );
// Wait for error toast
await waitFor(() =>
@@ -1088,9 +1097,13 @@
await userEvent.click(submitButton);
// Wait for modal to close (error handler closes it)
- await waitFor(() => {
- expect(screen.queryByRole('dialog')).not.toBeInTheDocument();
- });
+ // antd modal close animation can be slow, increase timeout
+ await waitFor(
+ () => {
+ expect(screen.queryByRole('dialog')).not.toBeInTheDocument();
+ },
+ { timeout: 10000 },
+ );
// Wait for error toast
await waitFor(() =>