Skip to content

Commit 57aa149

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

1 file changed

Lines changed: 12 additions & 13 deletions

File tree

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

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

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

0 commit comments

Comments
 (0)