Skip to content

test: unify i18next mocks into centralized helpers#7

Open
tomerqodo wants to merge 5 commits intogreptile_full_base_test_unify_i18next_mocks_into_centralized_helpers_pr7from
greptile_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 intogreptile_full_base_test_unify_i18next_mocks_into_centralized_helpers_pr7from
greptile_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.
@greptile-apps
Copy link
Copy Markdown

greptile-apps Bot commented Jan 26, 2026

Greptile Overview

Greptile Summary

This PR successfully consolidates i18next mocking across the test suite by introducing centralized helper functions in web/test/i18n-mock.ts. The refactoring removes 293 lines of duplicated mock code while adding 79 lines of reusable utilities.

Key changes:

  • Created createTFunction, createUseTranslationMock, createTransMock, and createReactI18nextMock factory functions with proper namespace handling
  • Updated global mock in vitest.setup.ts to use the centralized helper
  • Migrated 18 test files to use the new helpers or rely on the global mock
  • Updated all documentation (testing.md, mocking.md, template) to recommend the new approach
  • Fixed test assertions in marketplace tests to match namespace-prefixed behavior (plugin.category.all instead of category.all)

Benefits:

  • Single source of truth for i18n mock behavior
  • Consistent namespace handling across all tests
  • Easy customization through translation maps
  • Reduced maintenance burden and code duplication

Confidence Score: 5/5

  • This PR is safe to merge with minimal risk - it's a pure refactoring that improves test maintainability
  • The changes are low-risk refactoring with no production code impact. All modifications are test-only, the new helper functions are well-designed with proper TypeScript types, and the migration is systematic and consistent across all 18 test files. The PR reduces code duplication and improves maintainability without changing test behavior.
  • No files require special attention

Important Files Changed

Filename Overview
web/test/i18n-mock.ts Added centralized i18n mock helpers with createTFunction, createUseTranslationMock, createTransMock, and createReactI18nextMock factory functions
web/vitest.setup.ts Integrated global i18n mock using createReactI18nextMock helper, replacing inline mock implementation
web/testing/testing.md Updated documentation to recommend createReactI18nextMock helper and explain global mock behavior with namespace handling
.claude/skills/frontend-testing/references/mocking.md Updated i18n mocking guide to recommend createReactI18nextMock helper and explain global mock provisions
web/app/components/base/inline-delete-confirm/index.spec.tsx Migrated from inline i18n mock to createReactI18nextMock helper with custom translations
web/app/components/plugins/marketplace/index.spec.tsx Removed redundant i18n mock, updated assertions to match global mock's namespace-prefixed behavior

Sequence Diagram

sequenceDiagram
    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
Loading

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