Skip to content

test: add new RTL and integration tests for DatasetList#36681

Merged
sadpandajoe merged 29 commits into
masterfrom
feat/dataset-rtl-tests
Feb 2, 2026
Merged

test: add new RTL and integration tests for DatasetList#36681
sadpandajoe merged 29 commits into
masterfrom
feat/dataset-rtl-tests

Conversation

@sadpandajoe
Copy link
Copy Markdown
Member

@sadpandajoe sadpandajoe commented Dec 16, 2025

SUMMARY

Adds comprehensive React Testing Library (RTL) and integration tests for the DatasetList page. This replaces the previous Enzyme-based test with 118 tests across 6 test files, organized by responsibility.

Test Files (118 tests total):

File Tests Scope
DatasetList.test.tsx 28 Smoke tests: rendering, filters, columns, search
DatasetList.listview.test.tsx 50 ListView interactions: sort, filter, bulk select, export, delete, pagination
DatasetList.behavior.test.tsx 10 User workflows: search-to-API, row actions, duplicate, badge display
DatasetList.permissions.test.tsx 14 RBAC: admin/read-only/export-only/delete-only UI visibility
DatasetList.integration.test.tsx 2 Multi-component orchestration: filter+sort+pagination merge, bulk action lifecycle
useDatasetLists.test.ts 14 Hook unit tests: pagination, error handling, schema encoding, guard clauses

Shared test infrastructure in DatasetList.testHelpers.tsx:

  • Realistic fixture data matching API response shapes
  • renderDatasetList() with Redux store, Router, and QueryParamProvider
  • setupMocks() / setupBulkDeleteMocks() for fetch-mock configuration
  • Typed helpers (DatasetFixture, UserState, RisonFilter)

Testing patterns used:

  • test() over describe() (flat structure per project guidelines)
  • within() scoping for table/toolbar/modal queries
  • findBy* async queries to avoid race conditions
  • Row-scoped checkbox selection (by dataset name, not array index)
  • Stable testId anchors for modal assertions
  • Real Redux/Router/QueryParam providers (no shallow rendering)

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

Not applicable (test-only changes).

TESTING INSTRUCTIONS

# Run all DatasetList tests
cd superset-frontend
npm test -- src/pages/DatasetList/ --no-coverage

# Run hook tests
npm test -- src/features/datasets/hooks/useDatasetLists.test.ts --no-coverage

All 8 CI shards pass.

ADDITIONAL INFORMATION

  • Has associated issue:
  • Required feature flags:
  • Changes UI
  • Includes DB Migration (follow approval process in SIP-59)
    • Migration is atomic, supports rollback & is backwards-compatible
    • Confirm DB migration upgrade and downgrade tested
    • Runtime estimates and downtime expectations provided
  • Introduces new feature or API
  • Removes existing feature or API

@sadpandajoe sadpandajoe force-pushed the feat/dataset-rtl-tests branch 4 times, most recently from 0e1dc86 to 8278f86 Compare December 19, 2025 00:40
@rusackas rusackas added the review:checkpoint Last PR reviewed during the daily review standup label Jan 5, 2026
@netlify
Copy link
Copy Markdown

netlify Bot commented Jan 6, 2026

Deploy Preview for superset-docs-preview ready!

Name Link
🔨 Latest commit 0d86288
🔍 Latest deploy log https://app.netlify.com/projects/superset-docs-preview/deploys/69794a584026b700080a788c
😎 Deploy Preview https://deploy-preview-36681--superset-docs-preview.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

sadpandajoe and others added 19 commits January 27, 2026 14:15
…or DatasetList

Add complete test coverage for the DatasetList page including:
- Component tests: DatasetList main, behaviors, ListView, permissions, DuplicateDatasetModal
- Integration tests: multi-component orchestration and hook-level state management
- Test helpers: shared fixtures and utilities

Tests breakdown:
- DatasetList.test.tsx: 28 component tests
- DatasetList.behavior.test.tsx: 10 behavior tests
- DatasetList.listview.test.tsx: 36 ListView tests
- DatasetList.permissions.test.tsx: 14 permission tests
- DuplicateDatasetModal.test.tsx: 9 modal tests
- DatasetList.integration.test.tsx: 2 integration tests

Total: 99 tests (97 component + 2 integration)

Includes fixes for:
- antd 5.27.6 compatibility (semantic selectors)
- Async cleanup patterns for reliable test execution
- Test timing and synchronization issues

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Remove explicit cleanup() calls (RTL handles this automatically)
- Add jest.setTimeout(30000) to match ChartList test pattern
- Standardize fetchMock cleanup using resetHistory() + restore()
- Fix eslint warnings by adding explicit assertions to 3 tests
- Remove unused cleanup imports

These changes improve test stability when running in parallel and
align with patterns used in other test files (e.g., ChartList).

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
…cate

- Remove `bulk delete refreshes list with updated count` test - duplicates
  integration test coverage in DatasetList.integration.test.tsx
- Simplify `selecting all datasets shows correct count in toolbar` by removing
  button assertions (tested elsewhere) and 60s timeout
- Simplify `exit bulk select via close button` by combining waitFor blocks
  and removing 60s timeout

Tests now focus on individual behaviors rather than full workflows,
reducing test time and complexity while maintaining coverage.

Note: Parallel execution worker crashes are a pre-existing infrastructure
issue (async cleanup in RTL tests), not related to these changes.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Fix flaky exit bulk select test: use waitFor with combined assertions
- Fix delete error tests: replace setTimeout with SupersetClient call verification
- Fix duplicate error tests: combine toast and modal assertions in waitFor
- Add delete success test with API call, toast, and refresh verification
- Add delete cancel test verifying no API call made
- Add duplicate success test with modal close and list refresh
- Add initial fetch failure test (500 error handling)
- Add feature flag test (PREVENT_UNSAFE_DEFAULT_URLS_ON_DATASET)

Test count: 103 → 108 tests

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Use waitForElementToBeRemoved for bulk select exit test
- Split multi-assert waitFor blocks into toast-first patterns
- Add clearer deterministic anchor comments for error tests
- Document component bug in delete error handler (separate fix)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Remove conditional filter check that relied on leaked state from
previous tests. Each test now unconditionally applies the Type filter,
ensuring tests are independent and order-agnostic.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Use waitForElementToBeRemoved callback form for bulk select removal
  (resolves immediately if gone, longer default timeout)
- Add explicit risonPayload assertions before decoding (clearer failures)
- Replace Record<string, any> with Record<string, unknown>

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Add test coverage for 403 error response on initial dataset fetch,
complementing existing 500 internal server error test.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Address code review feedback: verify toast message contains
"Access Denied" to distinguish 403 from 500 error path.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Add cleanup for antd portal elements (dropdowns, modals, messages)
- Reset browser history state between tests to prevent query param leakage
- Add async cleanup to allow pending React state updates to complete
- Force fresh router state in renderDatasetList with initialEntries

The type filter tests were failing when run in sequence because:
1. antd Select components create portal elements outside React's tree
2. QueryParamProvider reads from window.history which persisted between tests
3. This caused the Type filter's aria-label to include the selected value
   from the previous test ("Type: Virtual" instead of "Type")

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Changes:
- Remove redundant explicit cleanup() (RTL auto-cleanup is enabled)
- Remove brittle manual DOM surgery for antd portals
- Wrap async flush in act() to properly notify React
- Reduce global timeout from 30s to 15s (was 10s but one test needs 11s)
- Remove per-test extended timeouts (15s/30s/60s)
- Remove unnecessary MemoryRouter initialEntries (window.history.replaceState is sufficient)

The core fix remains: window.history.replaceState in afterEach prevents
QueryParamProvider from reading stale URL params between tests.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Add two-phase wait pattern for bulk select tests:
1. First wait for bulk-select-controls container (fast query)
2. Then wait for checkboxes to render

Also add 30s timeout for inherently slow tests:
- sort order persists after deleting (types DELETE char-by-char)
- bulk selection clears when filter changes (multiple async ops)

Fixes 5 tests timing out in CI shard 4.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Re-query header element after delete to avoid stale DOM reference
- Assert specific "2 Selected" count instead of weak /selected/i match
- Rename test to "bulk select enables checkboxes" (removes "for all rows")

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Add window.history.replaceState in afterEach to prevent query param leaks
- Replace url.split('?q=') with URL.searchParams.get for robust parsing
- Fix never-resolving promises in loading tests (use delayed response)
- Add bulk-select-controls anchor before checkbox queries (faster)
- Reduce global timeouts from 30s to 15s
- Rename assertOnlyExpectedCalls test and add explicit call count check
- Add comment explaining /dataset$/i button query pattern

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Use Set comparison for endpoint assertion (allows multiple calls)
- Use fake timers for loading tests (avoids 10s tail wait)
- Use /plus\s*Dataset/i pattern for button query (exact accessible name)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Remove broken URL vs glob comparison in endpoint assertion
- Simplify to just assertOnlyExpectedCalls (checks unmatched + required)
- Add jest.useRealTimers() to afterEach to prevent timer leaks
- Use flexible button pattern /(?:plus\s*)?Dataset$/i for future-proofing

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
…elete modal

- Add error path tests: edit modal fetch failure, bulk export/delete errors
- Add bulk select copy tests: virtual-only, physical-only, mixed selection
- Add delete modal tests: overflow display for >10 related items
- Fix flaky checkbox selection by waiting between clicks

9 new tests covering previously untested error handling and edge cases.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Add comprehensive cleanup to permissions.test.tsx (was missing act flush,
  timer restore, history reset, and restoreAllMocks)
- Add act flush and timer restore to integration.test.tsx afterEach
- Add act flush and timer restore to behavior.test.tsx afterEach
- Add timer restore to listview.test.tsx afterEach
- Increase permissions.test.tsx global timeout from 15s to 30s
- Add 30s timeout to bulk select tests in listview and integration files

These changes fix Jest worker crashes caused by "document global undefined"
errors due to inconsistent cleanup patterns, and prevent test timeouts under
CI parallel load.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Address CI test timeouts by fixing async sequencing issues instead of
increasing timeouts (per Codex analysis):

- permissions.test.tsx: Use findByTestId for table before checking Actions
- listview.test.tsx: Wait for selection state before clicking Delete
- listview.test.tsx: Wait for combobox ready before selectOption
- integration.test.tsx: Wait for sort refetch before applying filter

The root cause was not slow execution but tests waiting for state changes
that never happened due to race conditions in async operations.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@sadpandajoe sadpandajoe force-pushed the feat/dataset-rtl-tests branch from 0f8b6b0 to 4180b80 Compare January 27, 2026 22:18
sadpandajoe and others added 2 commits January 27, 2026 15:28
The bulk select tests were timing out because `waitFor` was causing
an infinite polling loop when using complex regex assertions. The
content was already correct but `waitFor` kept re-checking.

Fix: Use a simple anchor assertion ("1 Selected") in `waitFor` to
stabilize the UI state, then do the specific regex assertion
("1 Selected (Virtual)") outside of `waitFor`.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Bulk select tests were timing out at 15s under CI parallel load.
Added explicit 30s timeouts to:
- bulk select enables checkboxes
- bulk export error shows toast and clears loading state
- bulk select shows "N Selected (Virtual)"
- bulk select shows "N Selected (Physical)"
- ListView provider correctly merges filter + sort + pagination

The tests pass locally but need longer timeouts when running in
parallel with other resource-intensive tests in CI.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
sadpandajoe and others added 3 commits January 27, 2026 16:17
- Add 30s timeout to "bulk select shows mixed count" test
- Increase "bulk selection clears when filter changes" from 30s to 45s
  (still timing out under CI load)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Add async afterEach with act() flush to DatasetList.test.tsx to fix
  "document global undefined" Jest worker crash
- Increase "bulk action orchestration" test timeout from 30s to 45s

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
The 'toggling bulk select mode shows checkboxes' test was timing out
in CI shard 2 with the default 15s timeout. This test involves multiple
async operations (render, find button, click, wait for checkboxes) that
need more time under parallel CI load.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@sadpandajoe sadpandajoe force-pushed the feat/dataset-rtl-tests branch from 149ff70 to 0d3c6b4 Compare January 28, 2026 01:45
@sadpandajoe sadpandajoe changed the title test: add comprehensive React Testing Library and integration tests f… test: add new RTL and integration tests for DatasetList Jan 28, 2026
sadpandajoe and others added 5 commits January 27, 2026 18:38
Medium:
- Added loading state assertion to bulk export error test (verify
  Loading indicator with role="status" is removed after error)
- Replaced waitForNextUpdate() with waitFor on expected final state
  in hook tests (prevents flakiness if hook adds intermediate states)

Low:
- Fixed URL parsing to use new URL().searchParams.get('q') instead
  of split('?q=') in hook tests (robust if params reorder)
- Changed checkbox selection from array index to row-scoped queries
  (find row by dataset name, then checkbox within)
- Replaced 'as any' casts with 'as unknown as JsonResponse'
  in hook tests (follows "no any" guidance)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
…llByRole

- Replace waitFor+getAllByRole patterns with findAllByRole for faster async handling
- Use row-scoped checkbox queries instead of array index access (more robust)
- Scope bulk delete button to toolbar to avoid matching row-level buttons
- Add selection anchors before clicking bulk action buttons
- Fix modal assertions to match actual ConfirmStatusChange description text
- Add explicit timeout to export-only user test

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Use within(table).findByText for row lookup instead of screen.getByText
  to avoid race conditions when table renders before rows
- Replace modal text assertions with stable delete-modal-input testId anchor
- Remove 30s timeout from simple test, add deterministic readiness check instead

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Remove redundant decodeURIComponent() when using searchParams.get()
  since searchParams.get() already URL-decodes the value
- Fix rison decode error for schemas with special characters (e.g. spaces)
- Apply consistently across all test files using URL parser pattern

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
…I tests

- Add 30s timeout to bulk delete error test (default 15s insufficient in CI)
- Add 45s timeout to admin UI elements test (default 30s insufficient in CI)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds comprehensive RTL (React Testing Library) and integration tests for the DatasetList component in Superset. The PR introduces over 4,700 lines of new test code organized into multiple test files, each focusing on different aspects of the DatasetList functionality.

Changes:

  • Adds comprehensive test coverage for DatasetList component with 6 new test files covering rendering, permissions, user interactions, integration scenarios, and error handling
  • Introduces well-organized test helpers with mock data, setup utilities, and assertion functions
  • Modernizes existing hook tests by replacing deprecated waitForNextUpdate with waitFor and improving type safety
  • Adds thorough tests for DuplicateDatasetModal component covering modal lifecycle and user interactions

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated no comments.

Show a summary per file
File Description
DatasetList.testHelpers.tsx Provides comprehensive test utilities including mock data fixtures, user roles, API endpoint constants, and setup/assertion helpers for consistent test configuration
DatasetList.test.tsx Tests basic rendering, loading states, buttons, filters, error handling, and initial API calls - covers fundamental component behavior
DatasetList.permissions.test.tsx Validates permission-based UI visibility and user role restrictions for admin, read-only, write, and export-only users
DatasetList.listview.test.tsx Extensive tests for list view operations including sorting, filtering, bulk actions, CRUD operations, and error paths - the most comprehensive test file
DatasetList.integration.test.tsx Integration tests verifying multi-component orchestration like state merging across filter/sort/pagination and bulk operation workflows
DatasetList.behavior.test.tsx User interaction tests covering search, tooltips, certification badges, warnings, and explore link behavior
useDatasetLists.test.ts Modernizes hook tests by replacing deprecated waitForNextUpdate with waitFor and improving type safety with better type assertions
DuplicateDatasetModal.test.tsx Complete modal component testing including open/close behavior, input validation, keyboard shortcuts, and state clearing

@sadpandajoe sadpandajoe marked this pull request as ready for review January 28, 2026 20:27
@dosubot dosubot Bot added the listview Namespace | Anything related to lists, such as Dashboards, Charts, Datasets, etc. label Jan 28, 2026
@sadpandajoe sadpandajoe removed the review:checkpoint Last PR reviewed during the daily review standup label Jan 29, 2026
@sadpandajoe sadpandajoe merged commit 4b0d497 into master Feb 2, 2026
138 checks passed
@sadpandajoe sadpandajoe deleted the feat/dataset-rtl-tests branch February 2, 2026 20:08
alexandrusoare pushed a commit that referenced this pull request Feb 3, 2026
Co-authored-by: Claude <noreply@anthropic.com>
aminghadersohi pushed a commit to aminghadersohi/superset that referenced this pull request Mar 5, 2026
alex-poor pushed a commit to alex-poor/superset that referenced this pull request Mar 15, 2026
qfcwell pushed a commit to qfcwell/superset that referenced this pull request May 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

listview Namespace | Anything related to lists, such as Dashboards, Charts, Datasets, etc. review:draft size/XXL

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants