Skip to content

Daily Test Coverage Improver - Add helper/TabCounter test coverage#5753

Draft
github-actions[bot] wants to merge 1 commit intomainfrom
test/add-helper-tabcounter-tests-5ac591766a39f938
Draft

Daily Test Coverage Improver - Add helper/TabCounter test coverage#5753
github-actions[bot] wants to merge 1 commit intomainfrom
test/add-helper-tabcounter-tests-5ac591766a39f938

Conversation

@github-actions
Copy link
Copy Markdown
Contributor

@github-actions github-actions Bot commented Mar 6, 2026

Goal and Rationale

This PR adds comprehensive test coverage for react/src/helper/TabCounter.ts, a utility class that tracks browser tabs via localStorage. This file had 0% coverage despite being a critical utility for tab management. The implementation is similar to lib/TabCounter.ts which already has 98.6% coverage, making it a good candidate for test improvement.

Approach

The testing strategy follows established patterns from the existing lib/TabCounter.test.ts:

  • Jest fake timers for testing interval-based heartbeat functionality
  • localStorage mocking for tab data persistence testing
  • Callback tracking for verifying onTabCountUpdate functionality
  • Edge case testing for stale entry cleanup, pause/start cycles, and multi-tab scenarios

The test suite includes 30 test cases organized into 8 describe blocks covering all 14 functions in the TabCounter class.

Impact Measurement

Test Coverage Results

Metric Before After Improvement
TabCounter.ts statements 0% (0/62) 100% (62/62) +100%
TabCounter.ts branches 0% (0/26) 96.15% (25/26) +96.15%
TabCounter.ts functions 0% (0/14) 100% (14/14) +100%
React project statements 7.56% (1189/15711) 7.96% (1251/15711) +0.4%
React project branches 6.36% 6.59% +0.23%
React project functions 5.05% 5.36% +0.31%
React project lines 7.4% 7.81% +0.41%

Detailed Coverage

The test suite achieves near-perfect coverage:

  • 100% statement coverage - All 62 statements executed
  • 96.15% branch coverage - 25 of 26 branches covered (1 uncovered branch at line 94)
  • 100% function coverage - All 14 functions tested

Only 1 branch remains uncovered (line 94), which appears to be an edge case in the clearList timeout logic.

Trade-offs

Added:

  • 433 lines of test code (+13.3KB)
  • Comprehensive test coverage for tab tracking utility
  • Validation of interval-based heartbeat behavior
  • Edge case handling for stale data cleanup

Benefits:

  • Prevents regressions in tab counting logic
  • Documents expected behavior of TabCounter API
  • Increases confidence in localStorage-based tab tracking
  • Follows established test patterns from lib/TabCounter

Validation

Testing Approach

Tests verified through:

# Run specific test file with coverage
pnpm run test src/helper/TabCounter.test.ts --coverage --collectCoverageFrom='src/helper/TabCounter.ts'

# Results: 30 passed, 30 total tests
# Coverage: 100% statements, 96.15% branches, 100% functions

Success Criteria

✅ All 30 tests pass
✅ Statement coverage increased from 0% to 100%
✅ Branch coverage increased from 0% to 96.15%
✅ Function coverage increased from 0% to 100%
✅ No linting errors
✅ Follows project test patterns

Future Work

Additional Coverage Opportunities:

  1. helper/ directory files - Multiple untested utility files:

    • loginSessionAuth.ts (0% coverage, 275 statements)
    • loginConfig.ts (0.72% coverage, 644 statements)
    • appLauncherProxy.ts (0% coverage, 200+ statements)
  2. hooks/ directory - Many custom hooks lack coverage:

    • useBackendAIAppLauncher.tsx (0% coverage)
    • useBAINotification.tsx (0% coverage)
    • useDefaultImagesWithFallback.ts (0% coverage)
  3. Complete branch coverage - Investigate uncovered branch at line 94 to determine if additional test case is needed

  4. Integration tests - Add tests for TabCounter integration with actual React components

Reproducibility

Setup Commands

# Install dependencies
npx --yes pnpm@latest install --ignore-scripts

# Generate GraphQL types (required for React tests)
cd react && npx --yes pnpm@latest run relay

# Run all React tests with coverage
npx --yes pnpm@latest run test --coverage --coverageReporters=text

# Run specific TabCounter tests
npx --yes pnpm@latest run test src/helper/TabCounter.test.ts --coverage

Measurement Procedures

Coverage data collected using Jest's built-in coverage tool with Istanbul. The coverage summary shows:

  • Before: Coverage data from coverage-steps.log (React: 7.56% statements)
  • After: Coverage data from react/coverage/coverage-final.json (React: 7.96% statements)

Expected Results Format

Jest outputs coverage in multiple formats:

  • Text report: Console table showing file-by-file coverage percentages
  • JSON summary: coverage/coverage-summary.json with aggregate metrics
  • JSON final: coverage/coverage-final.json with detailed line-by-line execution counts

What Happens Next:
Once this PR is reviewed and merged, the next workflow run will select another low-coverage file to improve. The workflow systematically increases test coverage across the React project.

AI generated by Daily Test Coverage Improver

- Add 30 test cases covering all methods and edge cases
- Achieve 100% statement coverage, 96.15% branch coverage, 100% function coverage
- Test constructor, getData/updateData, updateActive, tabsCount, clearList, onTabChange, pause/start
- Include integration tests for tab lifecycle and callbacks
- Use fake timers for interval-based tests following project patterns

Coverage improvement:
- helper/TabCounter.ts: 0% → 100% statements (62 statements covered)
- Overall React project: 7.56% → 7.96% statement coverage (+0.4%)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants