Skip to content

Code Review Bench PR #30376 - test: unify i18next mocks into centralized helpers#7

Open
ketkarameya wants to merge 5 commits intobase_pr_30376_20260125_7333from
corrupted_pr_30376_20260125_7333
Open

Code Review Bench PR #30376 - test: unify i18next mocks into centralized helpers#7
ketkarameya wants to merge 5 commits intobase_pr_30376_20260125_7333from
corrupted_pr_30376_20260125_7333

Conversation

@ketkarameya
Copy link

@ketkarameya ketkarameya commented Feb 10, 2026

Code Review Bench PR langgenius#30376 - test: unify i18next mocks into centralized helpers

Benchmark PR for Gitar evaluation

Original PR: agentic-review-benchmarks#7

test: unify i18next mocks into centralized helpers


Summary by Gitar

  • Test infrastructure refactor:
    • Consolidated duplicated i18next mocks from 8 test files into centralized web/test/i18n-mock.ts factory functions
  • New factories:
    • createTFunction, createUseTranslationMock, createTransMock, and createReactI18nextMock with namespace-aware translation resolution
  • Code reduction:
    • Removed 133 lines of duplicate mock implementations, added 47 lines in centralized helper
  • Documentation updates:
    • Updated web/testing/testing.md and test templates to recommend centralized mock usage

This will update automatically on new commits.


hyoban and others added 5 commits January 25, 2026 12:05
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.
@gitar-bot-staging
Copy link

gitar-bot-staging bot commented Feb 10, 2026

Code Review 👍 Approved with suggestions 0 resolved / 2 findings

Clean test infrastructure refactoring that correctly consolidates duplicated i18next mocks into reusable factories. Two minor documentation/fidelity improvements suggested.

💡 Bug: JSDoc describes lookup order opposite to actual code

📄 web/test/i18n-mock.ts:8

The JSDoc on line 8 says "Checks translations[key] first, then translations[ns.key]" but the implementation on lines 16-21 checks translations[fullKey] (i.e., the namespaced ns.key) first, then translations[key] second. This inverted documentation will mislead contributors who want to understand or customize the lookup precedence.

Impact: Low — just a documentation mismatch, but could confuse developers when they provide translations with both bare keys and namespaced keys.

Suggested fix
 * Create a t function with optional custom translations
 * Checks translations[ns.key] first, then translations[key], then returns ns.key as fallback
💡 Edge Case: useTranslation mock ignores defaultNs parameter

📄 web/test/i18n-mock.ts:41

The real useTranslation from react-i18next accepts an optional defaultNs parameter: useTranslation('myNamespace'). The old global mock in vitest.setup.ts forwarded this to the t function:

useTranslation: (defaultNs?: string) => ({
  t: (key, options?) => {
    const ns = options?.ns ?? defaultNs
    ...
  }
})

The new createUseTranslationMock ignores it:

useTranslation: () => ({ t: createTFunction(translations) })

Note that createTFunction already supports defaultNs as its second parameter, so the fix is straightforward.

Impact: Currently no production code in the affected test paths calls useTranslation with arguments, so this is not breaking. However, it's a regression in mock fidelity that could cause silent test failures if a component starts using useTranslation('ns').

Suggested fix
export function createUseTranslationMock(translations: TranslationMap = {}) {
  return {
    useTranslation: (defaultNs?: string) => ({
      t: createTFunction(translations, defaultNs),
      i18n: {
        language: 'en',
        changeLanguage: vi.fn(),
      },
    }),
  }
}
Rules 🎸 1 action taken

Gitar Rules

🎸 Summary Enhancement: Appended technical summary with 4 categories (63 words) covering test infrastructure refactor, new factories, code reduction, and documentation updates

5 rules not applicable. Show all rules by commenting gitar display:verbose.

Options

Auto-apply is off → Gitar will not commit updates to this branch.
Display: compact → Showing less information.

Comment with these commands to change:

Auto-apply Compact
gitar auto-apply:on         
gitar display:verbose         

Was this helpful? React with 👍 / 👎 | Gitar

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants