-
Notifications
You must be signed in to change notification settings - Fork 0
test: unify i18next mocks into centralized helpers #2
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_bench-100-20260108-copilot_base_test_unify_i18next_mocks_into_centralized_helpers_pr129
Are you sure you want to change the base?
Changes from all commits
344da1f
6834145
33272bd
1a45b88
ebf6662
f78fd25
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'` | |
| Hooks from other modules such as: | |
| - `useMixedTranslation` (from `@/app/components/plugins/marketplace/hooks`) | |
| - `useGetLanguage` (from `@/context/i18n`) | |
| are **not** provided by this global mock. When your tests depend on them, mock those modules explicitly in the test file (using `vi.mock`) or via shared mocks under `web/__mocks__/`, following the testing guidelines. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,33 +21,6 @@ import Card from './index' | |
| // Mock External Dependencies Only | ||
| // ================================ | ||
|
|
||
|
||
| // 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.
Same documentation issue - the comment states that the global mock provides
useMixedTranslationanduseGetLanguage, but these are from separate modules that are not mocked globally. OnlyuseTranslationandTransfromreact-i18nextare provided by the global mock inweb/vitest.setup.ts.