Skip to content

Commit f81ca5a

Browse files
committed
test: standardize l10n mock in views/Validation
Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com> (cherry picked from commit dd33df1) Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
1 parent 31f45dd commit f81ca5a

1 file changed

Lines changed: 12 additions & 28 deletions

File tree

src/tests/views/Validation.spec.ts

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

66
import { afterEach, describe, expect, it, beforeEach, vi } from 'vitest'
7+
import { createL10nMock, interpolateL10n } from '../testHelpers/l10n.js'
78
import { shallowMount } from '@vue/test-utils'
89
import axios from '@nextcloud/axios'
910
import { getCapabilities } from '@nextcloud/capabilities'
@@ -97,36 +98,19 @@ vi.mock('@nextcloud/logger', () => ({
9798
})),
9899
}))
99100

100-
vi.mock('@nextcloud/l10n', () => ({
101-
translate: vi.fn((app: string, text: string, vars?: Record<string, string>) => {
102-
if (vars) {
103-
return text.replace(/{(\w+)}/g, (_m: string, key: string) => vars[key as keyof typeof vars] || key)
104-
}
105-
return text
106-
}),
107-
translatePlural: vi.fn((app: string, singular: string, plural: string, count: number, vars?: Record<string, string>) => {
101+
vi.mock('@nextcloud/l10n', () => createL10nMock({
102+
t: (app: string, text: string, vars?: Record<string, string>) => {
103+
return interpolateL10n(text, vars)
104+
},
105+
n: (_app: string, singular: string, plural: string, count: number, vars?: Record<string, string>) => {
108106
const template = count === 1 ? singular : plural
109-
if (vars) {
110-
return template.replace(/{(\w+)}/g, (_m: string, key: string) => vars[key as keyof typeof vars] || key)
111-
}
112-
return template
113-
}),
114-
t: vi.fn((app: string, text: string, vars?: Record<string, string>) => {
115-
if (vars) {
116-
return text.replace(/{(\w+)}/g, (_m: string, key: string) => vars[key as keyof typeof vars] || key)
117-
}
118-
return text
119-
}),
120-
n: vi.fn((app: string, singular: string, plural: string, count: number, vars?: Record<string, string>) => {
107+
return interpolateL10n(template, { count, ...(vars ?? {}) })
108+
},
109+
translate: (app: string, text: string, vars?: Record<string, string>) => interpolateL10n(text, vars),
110+
translatePlural: (_app: string, singular: string, plural: string, count: number, vars?: Record<string, string>) => {
121111
const template = count === 1 ? singular : plural
122-
if (vars) {
123-
return template.replace(/{(\w+)}/g, (_m: string, key: string) => vars[key as keyof typeof vars] || key)
124-
}
125-
return template
126-
}),
127-
getLanguage: vi.fn(() => 'en'),
128-
getLocale: vi.fn(() => 'en'),
129-
isRTL: vi.fn(() => false),
112+
return interpolateL10n(template, { count, ...(vars ?? {}) })
113+
},
130114
}))
131115

132116
// Mock router

0 commit comments

Comments
 (0)