test: unify i18next mocks into centralized helpers#7
Open
Conversation
Consolidate scattered i18next mock implementations across test files into a single source of truth. This reduces duplication and ensures consistent mock behavior. - Create test/i18n-mock.ts with reusable factory functions - Update vitest.setup.ts to use the centralized helpers - Remove redundant mock definitions from 8 test files - Update testing.md documentation 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
…eateReactI18nextMock` and detail global mock provisions.
Greptile OverviewGreptile SummaryThis PR successfully consolidates i18next mocking across the test suite by introducing centralized helper functions in Key changes:
Benefits:
Confidence Score: 5/5
Important Files Changed
Sequence DiagramsequenceDiagram
participant Dev as Developer
participant Test as Test File
participant Helper as i18n-mock.ts
participant Global as vitest.setup.ts
participant Component as React Component
Note over Dev,Component: Initial Setup (One-time)
Dev->>Helper: Create centralized mock helpers
Helper-->>Helper: Define createTFunction()
Helper-->>Helper: Define createUseTranslationMock()
Helper-->>Helper: Define createTransMock()
Helper-->>Helper: Define createReactI18nextMock()
Dev->>Global: Configure global mock
Global->>Helper: Import createReactI18nextMock()
Global->>Global: vi.mock('react-i18next')
Note over Dev,Component: Test Execution Flow
alt Test needs custom translations
Test->>Helper: Import createReactI18nextMock()
Test->>Test: vi.mock('react-i18next', () => createReactI18nextMock({...}))
Test->>Test: Provide custom translation map
else Test uses global mock
Test->>Global: Use default global mock
Note over Test: No explicit mock needed
end
Test->>Component: Render component
Component->>Component: Call useTranslation()
alt Custom mock exists
Component->>Helper: t(key, options)
Helper->>Helper: Check translations[ns.key]
Helper->>Helper: Check translations[key]
Helper-->>Component: Return custom translation or ns.key
else Using global mock
Component->>Helper: t(key, options)
Helper->>Helper: Return ns.key format
Helper-->>Component: Return formatted key
end
Component-->>Test: Rendered output
Test->>Test: Assert on translated strings
Note over Dev,Component: Benefits Achieved
Note over Helper: ✓ Single source of truth
Note over Test: ✓ Consistent mock behavior
Note over Global: ✓ Reduced duplication
Note over Test: ✓ Easy custom translations
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Benchmark PR from agentic-review-benchmarks#7