Skip to content

Commit 32dab1e

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

1 file changed

Lines changed: 12 additions & 16 deletions

File tree

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

Lines changed: 12 additions & 16 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 axios from '@nextcloud/axios'
@@ -30,22 +31,17 @@ vi.mock('@nextcloud/router', () => ({
3031
generateOcsUrl: vi.fn((path: string) => path),
3132
}))
3233

33-
vi.mock('@nextcloud/l10n', () => ({
34-
t: vi.fn((_app: string, text: string, params?: Record<string, string>) => {
35-
if (!params) {
36-
return text
37-
}
38-
39-
return Object.entries(params).reduce((message, [key, value]) => {
40-
return message.replace(`{${key}}`, value)
41-
}, text)
42-
}),
43-
translate: vi.fn((_app: string, text: string) => text),
44-
translatePlural: vi.fn((_app: string, singular: string, plural: string, count: number) => (count === 1 ? singular : plural)),
45-
n: vi.fn((_app: string, singular: string, plural: string, count: number) => (count === 1 ? singular : plural)),
46-
getLanguage: vi.fn(() => 'en'),
47-
getLocale: vi.fn(() => 'en'),
48-
isRTL: vi.fn(() => false),
34+
vi.mock('@nextcloud/l10n', () => createL10nMock({
35+
t: (_app: string, text: string, vars?: Record<string, string | number>) => interpolateL10n(text, vars),
36+
n: (_app: string, singular: string, plural: string, count: number, vars?: Record<string, string | number>) => {
37+
const template = count === 1 ? singular : plural
38+
return interpolateL10n(template, { count, ...(vars ?? {}) })
39+
},
40+
translate: (_app: string, text: string, vars?: Record<string, string | number>) => interpolateL10n(text, vars),
41+
translatePlural: (_app: string, singular: string, plural: string, count: number, vars?: Record<string, string | number>) => {
42+
const template = count === 1 ? singular : plural
43+
return interpolateL10n(template, { count, ...(vars ?? {}) })
44+
},
4945
}))
5046

5147
describe('Reminders.vue', () => {

0 commit comments

Comments
 (0)