Skip to content

test: unify i18next mocks into centralized helpers#7

Open
tomerqodo wants to merge 5 commits intoaugment_full_base_test_unify_i18next_mocks_into_centralized_helpers_pr7from
augment_full_head_test_unify_i18next_mocks_into_centralized_helpers_pr7
Open

test: unify i18next mocks into centralized helpers#7
tomerqodo wants to merge 5 commits intoaugment_full_base_test_unify_i18next_mocks_into_centralized_helpers_pr7from
augment_full_head_test_unify_i18next_mocks_into_centralized_helpers_pr7

Conversation

@tomerqodo
Copy link
Copy Markdown

Benchmark PR from agentic-review-benchmarks#7

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.
@augmentcode
Copy link
Copy Markdown

augmentcode bot commented Jan 26, 2026

🤖 Augment PR Summary

Summary: This PR centralizes and standardizes frontend i18n mocking for Vitest by introducing a shared react-i18next mock helper.

Changes:

  • Added web/test/i18n-mock.ts with reusable factories for useTranslation/Trans mocks
  • Updated the global Vitest setup to use the new helper for the react-i18next mock
  • Removed duplicated per-test react-i18next mocks from multiple component specs, relying on the shared/global behavior
  • Adjusted marketplace tests/assertions to match the standardized namespace-prefixed key formatting
  • Updated testing/mocking documentation and templates to describe the recommended mock approach

Technical Notes: Custom translation strings for assertions can now be supplied via createReactI18nextMock({ ... }), reducing boilerplate and improving consistency across test files.

🤖 Was this summary useful? React with 👍 or 👎

Copy link
Copy Markdown

@augmentcode augmentcode bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review completed. 3 suggestions posted.

Fix All in Augment

Comment augment review to trigger a new review at any time.

Comment thread web/test/i18n-mock.ts
*/
export function createUseTranslationMock(translations: TranslationMap = {}) {
return {
useTranslation: () => ({
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

createUseTranslationMock’s useTranslation mock ignores the namespace argument (e.g. useTranslation('datasetSettings')), so t('key') won’t get the default namespace prefix unless callers pass options.ns. This diverges from real react-i18next usage patterns and the previous global mock behavior, so some tests may silently assert on the wrong strings.

Fix This in Augment

🤖 Was this useful? React with 👍 or 👎

Comment thread web/test/i18n-mock.ts
*/
export function createTransMock(translations: TranslationMap = {}) {
return {
Trans: ({ i18nKey, children }: {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Trans mock only uses { i18nKey, children } and ignores common props like components/values; many app components use <Trans ... components={{...}} /> to inject links/nodes. With this mock, tests may miss verifying that those injected elements actually render.

Fix This in Augment

🤖 Was this useful? React with 👍 or 👎

Comment thread web/test/i18n-mock.ts

/**
* Create a t function with optional custom translations
* Checks translations[key] first, then translations[ns.key], then returns ns.key as fallback
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The docstring for createTFunction says it checks translations[key] before translations[ns.key], but the implementation checks translations[fullKey] first. This mismatch could confuse future test authors who rely on the documented precedence.

Fix This in Augment

🤖 Was this useful? React with 👍 or 👎

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.

3 participants