Daily Test Coverage Improver - Add tests for useKeyboardShortcut hook #5171
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Goal and Rationale
This PR adds comprehensive unit tests for the
useKeyboardShortcut.tshook, which was previously untested (0% coverage).Coverage area chosen: Simple utility hook in
/react/src/hooks/useKeyboardShortcut.tsWhy it matters: This hook manages keyboard shortcuts throughout the application, preventing shortcuts from triggering when input fields are focused or modals are open. Testing it ensures:
Approach
Testing strategy:
renderHookahooks'useEventListenerto intercept event registrationImplementation steps:
ahooks.useEventListenerto capture event handlersskipShortcutOnMetaKeyoption with all modifier keysImpact Measurement
Test Coverage Results
Test Suite Results
Note: The 2 failed test suites are pre-existing issues related to ES Module imports (
nuqspackage) and are unrelated to this PR.Trade-offs
What changed:
react/src/hooks/useKeyboardShortcut.test.ts(324 lines)Complexity:
ahooks.useEventListenerand DOM manipulation)Validation
Testing approach:
Success criteria met:
✅ All 22 new tests pass
✅ 96%+ coverage achieved for useKeyboardShortcut.ts
✅ 100% function and line coverage
✅ No existing tests broken
✅ Hooks coverage improved by 1.44-1.53%
✅ Overall React coverage improved by 0.19%
Test Cases Covered
Basic Functionality (2 tests)
Input Element Detection (4 tests)
Modal Detection (2 tests)
skipShortcutOnMetaKey Option (6 tests)
Shadow DOM Handling (2 tests)
Combined Conditions (3 tests)
Edge Cases (3 tests)
Future Work
Additional coverage opportunities identified:
Based on the baseline coverage analysis and previous PR #5147 recommendations, the next priority areas are:
More Simple Utility Hooks (0% coverage, high ROI):
useHighlight.ts- Code syntax highlighting with shiki (already reviewed, good candidate)useScrollBreackPoint.tsx- Scroll position tracking (already reviewed, good candidate)Validation Hooks (important business logic):
useValidateServiceName.tsx- Service name validationuseValidateSessionName.tsx- Session name validationState Management Hooks:
useLocalStorageGlobalState.tsx- Browser storage hookuseHiddenColumnKeysSetting.tsx- UI settings persistenceBackend.AI UI Package (
packages/backend.ai-ui/src/helper/index.ts):Reproducibility
Setup Commands
Run Tests
Measurement Procedures
Expected Results Format
Related: Discussion #4760 - Daily Test Coverage Improver Research and Plan