test: update install plugin component tests to utilize enhanced translation function with namespace support

This commit is contained in:
CodingOnStar 2025-12-29 17:29:46 +08:00
parent 3cf07334d1
commit 23a8bebb62
2 changed files with 16 additions and 8 deletions

View File

@ -66,11 +66,15 @@ vi.mock('@/context/app-context', () => ({
vi.mock('react-i18next', () => ({
useTranslation: () => ({
t: (key: string, params?: Record<string, unknown>) => {
if (params) {
return `${key}:${JSON.stringify(params)}`
t: (key: string, options?: { ns?: string } & Record<string, unknown>) => {
// Build full key with namespace prefix if provided
const fullKey = options?.ns ? `${options.ns}.${key}` : key
// Handle interpolation params (excluding ns)
const { ns: _ns, ...params } = options || {}
if (Object.keys(params).length > 0) {
return `${fullKey}:${JSON.stringify(params)}`
}
return key
return fullKey
},
}),
Trans: ({ i18nKey, components }: { i18nKey: string, components?: Record<string, React.ReactNode> }) => (

View File

@ -50,11 +50,15 @@ vi.mock('@/service/plugins', () => ({
vi.mock('react-i18next', () => ({
useTranslation: () => ({
t: (key: string, params?: Record<string, unknown>) => {
if (params) {
return `${key}:${JSON.stringify(params)}`
t: (key: string, options?: { ns?: string } & Record<string, unknown>) => {
// Build full key with namespace prefix if provided
const fullKey = options?.ns ? `${options.ns}.${key}` : key
// Handle interpolation params (excluding ns)
const { ns: _ns, ...params } = options || {}
if (Object.keys(params).length > 0) {
return `${fullKey}:${JSON.stringify(params)}`
}
return key
return fullKey
},
}),
}))