Skip to content

Commit 9794ec7

Browse files
committed
test: standardize l10n mock in views/Settings/TSA
Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com> (cherry picked from commit 057741a) Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
1 parent 98bf8fd commit 9794ec7

1 file changed

Lines changed: 12 additions & 13 deletions

File tree

src/tests/views/Settings/TSA.spec.ts

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
*/
55

66
import { beforeEach, describe, expect, it, vi } from 'vitest'
7+
import { createL10nMock, interpolateL10n } from '../../testHelpers/l10n.js'
78
import { flushPromises, mount } from '@vue/test-utils'
89

910
import TSA from '../../../views/Settings/TSA.vue'
@@ -32,19 +33,17 @@ vi.mock('@nextcloud/axios', () => ({
3233
},
3334
}))
3435

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+
},
4847
}))
4948

5049
describe('TSA.vue', () => {

0 commit comments

Comments
 (0)