-
Notifications
You must be signed in to change notification settings - Fork 16.3k
refactor(datasets): add comprehensive unit tests for dataset API hooks and fix api guards #36175
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
- Add ESLint disable comments for describe blocks (following ChartList pattern) - Fix TypeScript mock typing using jest.mocked() helper - Update supersetGetCache.delete mock to be properly typed - Fix mockDb.owners type to be tuple [number] - Add 'as any' casts for test fixtures to avoid strict type checking - All 30 unit tests passing 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
Improvements to existing unit tests for dataset hooks and API resources. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
- Add break statement in pagination loop error handler to prevent infinite retries on persistent API errors - Add db?.id guard to prevent API calls with undefined database ID - Add 5 new tests covering extension fallback, db undefined, and pagination error scenarios - Update existing error tests to expect single API call (not retry) Test Results: 35/35 passing 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
3fcbe5a to
1699185
Compare
There was a problem hiding this 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 pull request adds comprehensive unit test coverage for dataset API hooks and fixes two critical bugs that could cause browser hangs and unnecessary API calls.
Key Changes:
- Added 35 comprehensive unit tests across two test files (datasets.test.ts and useDatasetLists.test.ts)
- Fixed pagination infinite loop bug by adding
breakstatement in error handler - Fixed missing database guard to prevent API calls with undefined database ID
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| superset-frontend/src/hooks/apiResources/datasets.test.ts | New test file with 21 tests covering getDatasetId, createVerboseMap, useDatasetDrillInfo hook, extension integration, and edge cases |
| superset-frontend/src/features/datasets/hooks/useDatasetLists.test.ts | New test file with 14 tests covering pagination, error handling, guard conditions, and schema encoding |
| superset-frontend/src/features/datasets/hooks/useDatasetLists.ts | Critical bug fixes: added break statement in pagination error handler (line 68) and database ID guard check (line 82) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review Agent Run #7e8d58
Actionable Suggestions - 1
-
superset-frontend/src/features/datasets/hooks/useDatasetLists.test.ts - 1
- Incorrect URL encoding expectation in test · Line 378-380
Review Details
-
Files reviewed - 3 · Commit Range:
7c68474..1699185- superset-frontend/src/features/datasets/hooks/useDatasetLists.test.ts
- superset-frontend/src/features/datasets/hooks/useDatasetLists.ts
- superset-frontend/src/hooks/apiResources/datasets.test.ts
-
Files skipped - 0
-
Tools
- Eslint (Linter) - ✔︎ Successful
- Whispers (Secret Scanner) - ✔︎ Successful
- Detect-secrets (Secret Scanner) - ✔︎ Successful
Bito Usage Guide
Commands
Type the following command in the pull request comment and save the comment.
-
/review- Manually triggers a full AI review. -
/pause- Pauses automatic reviews on this pull request. -
/resume- Resumes automatic reviews. -
/resolve- Marks all Bito-posted review comments as resolved. -
/abort- Cancels all in-progress reviews.
Refer to the documentation for additional commands.
Configuration
This repository uses Default Agent You can customize the agent settings here or contact your Bito workspace admin at [email protected].
Documentation & Help
| // Verify the encoded schema is present in the URL (double-encoded by rison) | ||
| // Schema 'sales analytics' -> encodeURIComponent -> 'sales%20analytics' -> rison.encode_uri -> 'sales%2520analytics' | ||
| expect(callArg).toContain('sales%2520analytics'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The test expects double-encoded schema in the URL, but rison does not encode percent signs, leading to incorrect validation. Update to expect 'sales%20analytics' instead of 'sales%2520analytics' to match actual rison behavior. This affects the useDatasetsList hook's API endpoint construction, where schema encoding is critical for proper URL formation and API calls.
Code suggestion
Check the AI-generated fix before applying
| // Verify the encoded schema is present in the URL (double-encoded by rison) | |
| // Schema 'sales analytics' -> encodeURIComponent -> 'sales%20analytics' -> rison.encode_uri -> 'sales%2520analytics' | |
| expect(callArg).toContain('sales%2520analytics'); | |
| // Verify the encoded schema is present in the URL (encoded by rison) | |
| // Schema 'sales analytics' -> encodeURIComponent -> 'sales%20analytics' -> rison.encode_uri -> 'sales%20analytics' | |
| expect(callArg).toContain('sales%20analytics'); |
Code Review Run #7e8d58
Should Bito avoid suggestions like this for future reviews? (Manage Rules)
- Yes, avoid them
Replace toBeNaN() with Number.isNaN() check since toBeNaN is not a standard Jest matcher. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
Remove all describe() nesting following Kent C. Dodds' "Avoid Nesting When You're Testing" principles: - Remove 3 describe blocks (useDatasetDrillInfo, getDatasetId malformed, extension path) - Move beforeEach/afterEach to module level - Create setupExtensionMock() helper for extension tests - All 21 tests now flat with descriptive names Test structure is cleaner and more maintainable. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
071e9fd to
011624c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.
…s and fix api guards (apache#36175) Co-authored-by: Claude <[email protected]>
…s and fix api guards (apache#36175) Co-authored-by: Claude <[email protected]>
SUMMARY
This PR adds comprehensive unit test coverage for the dataset API hooks used in the filter configuration flow, plus fixes two critical bugs discovered during testing.
New Test Coverage (35 tests)
src/hooks/apiResources/datasets.test.ts (21 tests)
src/features/datasets/hooks/useDatasetLists.test.ts (14 tests)
Bug Fixes
- Problem: Error handler in pagination loop didn't break, causing infinite retries on persistent API errors
- Fix: Added break statement in catch block
- Risk: CRITICAL - could cause browser hangs/crashes
- Problem: API calls fired with database: undefined when db not selected
- Fix: Added db?.id !== undefined check to guard condition
- Risk: MEDIUM - API spam with malformed filters
BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
TESTING INSTRUCTIONS
ADDITIONAL INFORMATION