|
4 | 4 | */ |
5 | 5 |
|
6 | 6 | import { beforeEach, describe, expect, it, vi } from 'vitest' |
| 7 | +import { createL10nMock, interpolateL10n } from '../../testHelpers/l10n.js' |
7 | 8 | import { flushPromises, mount } from '@vue/test-utils' |
8 | 9 |
|
9 | 10 | import TSA from '../../../views/Settings/TSA.vue' |
@@ -32,19 +33,17 @@ vi.mock('@nextcloud/axios', () => ({ |
32 | 33 | }, |
33 | 34 | })) |
34 | 35 |
|
35 | | -vi.mock('@nextcloud/l10n', () => ({ |
36 | | - t: vi.fn((_app: string, text: string, vars?: Record<string, string>) => { |
37 | | - if (!vars) { |
38 | | - return text |
39 | | - } |
40 | | - return text.replace(/{(\w+)}/g, (_match, key) => String(vars[key])) |
41 | | - }), |
42 | | - translate: vi.fn((_app: string, text: string) => text), |
43 | | - translatePlural: vi.fn((_app: string, singular: string, plural: string, count: number) => (count === 1 ? singular : plural)), |
44 | | - n: vi.fn((_app: string, singular: string, plural: string, count: number) => (count === 1 ? singular : plural)), |
45 | | - getLanguage: vi.fn(() => 'en'), |
46 | | - getLocale: vi.fn(() => 'en'), |
47 | | - isRTL: vi.fn(() => false), |
| 36 | +vi.mock('@nextcloud/l10n', () => createL10nMock({ |
| 37 | + t: (_app: string, text: string, vars?: Record<string, string | number>) => interpolateL10n(text, vars), |
| 38 | + n: (_app: string, singular: string, plural: string, count: number, vars?: Record<string, string | number>) => { |
| 39 | + const template = count === 1 ? singular : plural |
| 40 | + return interpolateL10n(template, { count, ...(vars ?? {}) }) |
| 41 | + }, |
| 42 | + translate: (_app: string, text: string, vars?: Record<string, string | number>) => interpolateL10n(text, vars), |
| 43 | + translatePlural: (_app: string, singular: string, plural: string, count: number, vars?: Record<string, string | number>) => { |
| 44 | + const template = count === 1 ? singular : plural |
| 45 | + return interpolateL10n(template, { count, ...(vars ?? {}) }) |
| 46 | + }, |
48 | 47 | })) |
49 | 48 |
|
50 | 49 | describe('TSA.vue', () => { |
|
0 commit comments