Skip to content

Commit 265964e

Browse files
committed
test: standardize l10n mock in views/Settings/RootCertificateCfssl
Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com> (cherry picked from commit 4c4ed4a) Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
1 parent 32dab1e commit 265964e

1 file changed

Lines changed: 12 additions & 13 deletions

File tree

src/tests/views/Settings/RootCertificateCfssl.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 RootCertificateCfssl from '../../../views/Settings/RootCertificateCfssl.vue'
@@ -41,19 +42,17 @@ vi.mock('@nextcloud/router', () => ({
4142
generateOcsUrl: vi.fn((path: string) => path),
4243
}))
4344

44-
vi.mock('@nextcloud/l10n', () => ({
45-
t: vi.fn((_app: string, text: string, vars?: Record<string, string>) => {
46-
if (!vars) {
47-
return text
48-
}
49-
return text.replace(/{(\w+)}/g, (_match, key) => String(vars[key]))
50-
}),
51-
translate: vi.fn((_app: string, text: string) => text),
52-
translatePlural: vi.fn((_app: string, singular: string, plural: string, count: number) => (count === 1 ? singular : plural)),
53-
n: vi.fn((_app: string, singular: string, plural: string, count: number) => (count === 1 ? singular : plural)),
54-
getLanguage: vi.fn(() => 'en'),
55-
getLocale: vi.fn(() => 'en'),
56-
isRTL: vi.fn(() => false),
45+
vi.mock('@nextcloud/l10n', () => createL10nMock({
46+
t: (_app: string, text: string, vars?: Record<string, string | number>) => interpolateL10n(text, vars),
47+
n: (_app: string, singular: string, plural: string, count: number, vars?: Record<string, string | number>) => {
48+
const template = count === 1 ? singular : plural
49+
return interpolateL10n(template, { count, ...(vars ?? {}) })
50+
},
51+
translate: (_app: string, text: string, vars?: Record<string, string | number>) => interpolateL10n(text, vars),
52+
translatePlural: (_app: string, singular: string, plural: string, count: number, vars?: Record<string, string | number>) => {
53+
const template = count === 1 ? singular : plural
54+
return interpolateL10n(template, { count, ...(vars ?? {}) })
55+
},
5756
}))
5857

5958
vi.mock('../../../helpers/certification', () => ({

0 commit comments

Comments
 (0)