-
Notifications
You must be signed in to change notification settings - Fork 0
test: unify i18next mocks into centralized helpers #56
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: copilot_combined_20260121_qodo_grep_cursor_copilot_1_base_test_unify_i18next_mocks_into_centralized_helpers_pr437
Are you sure you want to change the base?
Changes from all commits
425c3a7
d29dade
80e7d96
87510e6
4235e98
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -52,23 +52,29 @@ Modules are not mocked automatically. Use `vi.mock` in test files, or add global | |||||||||
| ### 1. i18n (Auto-loaded via Global Mock) | ||||||||||
|
|
||||||||||
| A global mock is defined in `web/vitest.setup.ts` and is auto-loaded by Vitest setup. | ||||||||||
| **No explicit mock needed** for most tests - it returns translation keys as-is. | ||||||||||
|
|
||||||||||
| For tests requiring custom translations, override the mock: | ||||||||||
| The global mock provides: | ||||||||||
|
|
||||||||||
| - `useTranslation` - returns translation keys with namespace prefix | ||||||||||
| - `Trans` component - renders i18nKey and components | ||||||||||
| - `useMixedTranslation` (from `@/app/components/plugins/marketplace/hooks`) | ||||||||||
| - `useGetLanguage` (from `@/context/i18n`) - returns `'en-US'` | ||||||||||
|
|
||||||||||
|
Comment on lines
+60
to
+62
|
||||||||||
| - `useMixedTranslation` (from `@/app/components/plugins/marketplace/hooks`) | |
| - `useGetLanguage` (from `@/context/i18n`) - returns `'en-US'` | |
| **Note:** `useMixedTranslation` (from `@/app/components/plugins/marketplace/hooks`) and `useGetLanguage` (from `@/context/i18n`) are **not** mocked globally. Mock them locally in test files that render components depending on these hooks. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,33 +21,6 @@ import Card from './index' | |
| // Mock External Dependencies Only | ||
| // ================================ | ||
|
|
||
|
Comment on lines
21
to
23
|
||
| // Mock react-i18next (translation hook) | ||
| vi.mock('react-i18next', () => ({ | ||
| useTranslation: () => ({ | ||
| t: (key: string) => key, | ||
| }), | ||
| })) | ||
|
|
||
| // Mock useMixedTranslation hook | ||
| vi.mock('../marketplace/hooks', () => ({ | ||
| useMixedTranslation: (_locale?: string) => ({ | ||
| t: (key: string, options?: { ns?: string }) => { | ||
| const fullKey = options?.ns ? `${options.ns}.${key}` : key | ||
| const translations: Record<string, string> = { | ||
| 'plugin.marketplace.partnerTip': 'Partner plugin', | ||
| 'plugin.marketplace.verifiedTip': 'Verified plugin', | ||
| 'plugin.installModal.installWarning': 'Install warning message', | ||
| } | ||
| return translations[fullKey] || key | ||
| }, | ||
| }), | ||
| })) | ||
|
|
||
| // Mock useGetLanguage context | ||
| vi.mock('@/context/i18n', () => ({ | ||
| useGetLanguage: () => 'en-US', | ||
| })) | ||
|
|
||
| // Mock useTheme hook | ||
| vi.mock('@/hooks/use-theme', () => ({ | ||
| default: () => ({ theme: 'light' }), | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comment incorrectly states that the global mock provides
useMixedTranslationanduseGetLanguage. Looking atweb/vitest.setup.ts, the global mock only coversreact-i18nextexports (useTranslation, Trans, etc.). The hooksuseMixedTranslation(from@/app/components/plugins/marketplace/hooks) anduseGetLanguage(from@/context/i18n) are not mocked globally and must be mocked locally in test files that use components which depend on these hooks.