-
Notifications
You must be signed in to change notification settings - Fork 78
[Coverage Improvement] Add comprehensive unit tests for BAIStatistic component #4804
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
[Coverage Improvement] Add comprehensive unit tests for BAIStatistic component #4804
Conversation
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 PR adds comprehensive unit tests for the BAIStatistic component, improving test coverage from 0% to 100% statement coverage. The component displays statistical information with formatted numbers, infinity handling, progress bars, and internationalized text.
Key Changes
- Added 40 test cases covering rendering, formatting, infinity handling, progress bars, and edge cases
- Implemented i18n mock for translation testing
- Achieved 100% statement coverage and 95.83% branch coverage
ac4d3c9 to
1f01c66
Compare
How to use the Graphite Merge QueueAdd either label to this PR to merge it via the merge queue:
You must have a Graphite account in order to use the merge queue. Sign up using this link. An organization admin has required the Graphite Merge Queue in this repository. Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue. This stack of pull requests is managed by Graphite. Learn more about stacking. |
Coverage report for
|
St.❔ |
Category | Percentage | Covered / Total |
|---|---|---|---|
| 🟡 | Statements | 63.5% | 254/400 |
| 🔴 | Branches | 42.3% | 151/357 |
| 🔴 | Functions | 50% | 46/92 |
| 🟡 | Lines | 65.16% | 230/353 |
Test suite run success
186 tests passing in 9 suites.
Report generated by 🧪jest coverage report action from 7d7dbf1
nowgnuesLee
left a comment
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.
LGTM
yomybaby
left a comment
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.
LGTM
Merge activity
|
…component (#4804) ## Goal and Rationale This PR adds comprehensive unit tests for the `BAIStatistic` component in the `backend.ai-ui` package, significantly improving test coverage from **0% to 100% (statements)**. **Why this matters:** - BAIStatistic is a reusable statistics display component used across the application for showing resource usage metrics - Ensures proper number formatting, infinity handling, and progress bar rendering - Prevents regressions in critical data display features - Part of systematic test coverage improvement plan for backend.ai-ui components ## Approach ### Testing Strategy - **Comprehensive unit testing** using Jest and React Testing Library - **40 test cases** covering all component behaviors and edge cases - **Test categories**: Basic rendering, number formatting, infinity handling, progress bars, percentage calculation, edge cases, integration tests ### Test Implementation Details **Test Categories:** 1. **Basic Rendering** (4 tests) - Title, current value, units, combined display 2. **Number Formatting** (6 tests) - Decimal precision, trailing zeros, large/small numbers 3. **Infinity Handling** (4 tests) - Infinity values, custom display strings, negative infinity 4. **Progress Bar Rendering** (5 tests) - Hidden/normal/ghost modes, undefined total, custom steps 5. **Percentage Calculation** (8 tests) - 0%, 50%, 100%, edge cases with infinity/zero 6. **Edge Cases** (7 tests) - Undefined/zero/negative values, precision, styling 7. **ReactNode Title Support** (2 tests) - JSX elements and complex nodes as titles 8. **Integration Tests** (3 tests) - Complete component with all props, decimal combinations ## Impact Measurement ### Coverage Results **Target file**: `packages/backend.ai-ui/src/components/BAIStatistic.tsx` (141 lines) | Metric | Before | After | Improvement | |--------|--------|-------|-------------| | **Statements** | 0% | **100%** | **+100%** | | **Branches** | 0% | **95.83%** | **+95.83%** | | **Functions** | 0% | **100%** | **+100%** | | **Lines** | 0% | **100%** | **+100%** | **Uncovered lines**: 50, 88 (minor conditional branches not affecting core functionality) ### Test Suite Results - ✅ All 40 new tests passing - ✅ No regressions (102 total tests, up from 62) - ✅ ESLint and Prettier validation passed - ✅ Edge cases covered: infinity values, zero division, precision handling ### Overall Project Impact **backend.ai-ui Package:** | Metric | Before | After | Change | |--------|--------|-------|--------| | Test files | 4 | **5** | +1 | | Total tests | 62 | **102** | **+40 tests** | | Overall coverage | 54.78% | **58.71%** | **+3.93%** | ## Trade-offs ### Pros ✅ **100% statement coverage** - All code paths tested ✅ **95.83% branch coverage** - Nearly complete branch coverage ✅ **Zero regressions** - All existing tests continue to pass ✅ **Production-ready** - Tests follow best practices and repository patterns ✅ **Maintainable** - Clear test names and well-organized structure ✅ **Comprehensive edge case coverage** - Handles infinity, zero division, precision ### Cons⚠️ **Test file size** - 432 lines for 141-line source (~3:1 ratio) - *Justified by comprehensive coverage of all rendering paths and calculations*⚠️ **Progress bar testing** - Uses presence checks rather than exact percentage values - *Ant Design component internals tested separately; we verify integration*⚠️ **Two uncovered lines** - Lines 50, 88 are minor conditional branches - *Would require complex test setup for minimal additional value* ## Validation ### Testing Approach All tests use Jest with React Testing Library: - Component rendering validation using `render()` and `screen` queries - Number formatting validation with various precision levels - Infinity handling verification with translation mocks - Progress bar presence and configuration testing - Edge case validation including zero, negative, and undefined values ### Success Criteria Met ✅ All 40 tests pass consistently ✅ 100% statement coverage achieved ✅ 95.83% branch coverage achieved ✅ No lint errors or warnings ✅ No impact on existing tests (62 → 102 tests, all passing) ✅ Pre-commit hooks pass (ESLint + Prettier) ## Reproducibility ### Setup Commands ```bash # From repository root cd /home/runner/work/backend.ai-webui/backend.ai-webui # Install dependencies pnpm install # Navigate to backend.ai-ui package cd packages/backend.ai-ui ``` ### Running Tests ```bash # Run tests for this specific file NODE_OPTIONS='--no-deprecation' npx jest src/components/BAIStatistic.test.tsx # Run with coverage NODE_OPTIONS='--no-deprecation' npx jest src/components/BAIStatistic.test.tsx --coverage --collectCoverageFrom='src/components/BAIStatistic.tsx' # Run all backend.ai-ui tests with coverage NODE_OPTIONS='--no-deprecation' npx jest --coverage ``` ### Expected Results ``` PASS src/components/BAIStatistic.test.tsx BAIStatistic Basic Rendering ✓ should render title correctly ✓ should render current value without total ✓ should render unit when provided ✓ should render with both current and total values Number Formatting ✓ should format decimal numbers with default precision (2) ✓ should format decimal numbers with custom precision ... (34 more tests) Test Suites: 5 passed, 5 total Tests: 102 passed, 102 total (40 new) Snapshots: 3 passed, 3 total Time: ~3.6s Coverage Summary: File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s ------------------|---------|----------|---------|---------|------------------- BAIStatistic.tsx | 100 | 95.83 | 100 | 100 | 50,88 All files | 58.71 | 42.16 | 44.73 | 60.70 | ``` ## Future Work Based on the research plan in discussion #4760, the next high-priority areas for test coverage improvement are: 1. **Other backend.ai-ui components** with 0% coverage: - `BAIButton.tsx` - Button component with async action support - `BAIBackButton.tsx` - Navigation back button component - `BAIFetchKeyButton.tsx` - Fetch key control component - `BAITag.tsx` - Tag display component - `BAISelect.tsx` - Enhanced select component 2. **React project helpers** in `/react/src/helper/`: - `customThemeConfig.ts` - Theme loading and configuration logic - `react-to-webcomponent.tsx` - React component wrapper logic - `bui-language.ts` - i18n language mappings (simple constants) 3. **React project hooks** in `/react/src/hooks/`: - `useThemeMode.tsx` - Theme management hook - `useValidateServiceName.tsx` - Service name validation logic - `useValidateSessionName.tsx` - Session name validation logic --- **Related Discussion**: #4760 (Daily Test Coverage Improver - Research and Plan) **Branch**: `test/bai-statistic-coverage` **Files Changed**: 1 file, +432 lines > AI generated by [Daily Test Coverage Improver](https://github.com/lablup/backend.ai-webui/actions/runs/20117309295) > AI generated by [Daily Test Coverage Improver](https://github.com/lablup/backend.ai-webui/actions/runs/20117309295)
1f01c66 to
7d7dbf1
Compare

Goal and Rationale
This PR adds comprehensive unit tests for the
BAIStatisticcomponent in thebackend.ai-uipackage, significantly improving test coverage from 0% to 100% (statements).Why this matters:
Approach
Testing Strategy
Test Implementation Details
Test Categories:
Impact Measurement
Coverage Results
Target file:
packages/backend.ai-ui/src/components/BAIStatistic.tsx(141 lines)Uncovered lines: 50, 88 (minor conditional branches not affecting core functionality)
Test Suite Results
Overall Project Impact
backend.ai-ui Package:
Trade-offs
Pros
✅ 100% statement coverage - All code paths tested
✅ 95.83% branch coverage - Nearly complete branch coverage
✅ Zero regressions - All existing tests continue to pass
✅ Production-ready - Tests follow best practices and repository patterns
✅ Maintainable - Clear test names and well-organized structure
✅ Comprehensive edge case coverage - Handles infinity, zero division, precision
Cons
Validation
Testing Approach
All tests use Jest with React Testing Library:
render()andscreenqueriesSuccess Criteria Met
✅ All 40 tests pass consistently
✅ 100% statement coverage achieved
✅ 95.83% branch coverage achieved
✅ No lint errors or warnings
✅ No impact on existing tests (62 → 102 tests, all passing)
✅ Pre-commit hooks pass (ESLint + Prettier)
Reproducibility
Setup Commands
Running Tests
Expected Results
Future Work
Based on the research plan in discussion #4760, the next high-priority areas for test coverage improvement are:
Other backend.ai-ui components with 0% coverage:
BAIButton.tsx- Button component with async action supportBAIBackButton.tsx- Navigation back button componentBAIFetchKeyButton.tsx- Fetch key control componentBAITag.tsx- Tag display componentBAISelect.tsx- Enhanced select componentReact project helpers in
/react/src/helper/:customThemeConfig.ts- Theme loading and configuration logicreact-to-webcomponent.tsx- React component wrapper logicbui-language.ts- i18n language mappings (simple constants)React project hooks in
/react/src/hooks/:useThemeMode.tsx- Theme management hookuseValidateServiceName.tsx- Service name validation logicuseValidateSessionName.tsx- Session name validation logicRelated Discussion: #4760 (Daily Test Coverage Improver - Research and Plan)
Branch:
test/bai-statistic-coverageFiles Changed: 1 file, +432 lines