Skip to content

Commit 303d970

Browse files
authored
Merge pull request #7272 from LibreSign/backport/7270/stable33
[stable33] test: l10n mock standardization
2 parents 608fe6a + ddbbc26 commit 303d970

97 files changed

Lines changed: 421 additions & 835 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/tests/App.spec.ts

Lines changed: 2 additions & 9 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 } from './testHelpers/l10n.js'
78
import { mount } from '@vue/test-utils'
89

910
import { initialActionCode, ACTION_CODES } from '../helpers/ActionMapping'
@@ -30,15 +31,7 @@ vi.mock('vue-router', async () => {
3031
}
3132
})
3233

33-
vi.mock('@nextcloud/l10n', () => ({
34-
t: vi.fn((_app: string, text: string) => text),
35-
translate: vi.fn((_app: string, text: string) => text),
36-
translatePlural: vi.fn((_app: string, singular: string, plural: string, count: number) => (count === 1 ? singular : plural)),
37-
n: vi.fn((_app: string, singular: string, plural: string, count: number) => (count === 1 ? singular : plural)),
38-
isRTL: vi.fn(() => false),
39-
getLanguage: vi.fn(() => 'en'),
40-
getLocale: vi.fn(() => 'en'),
41-
}))
34+
vi.mock('@nextcloud/l10n', () => createL10nMock())
4235

4336
vi.mock('@nextcloud/vue/components/NcContent', () => ({
4437
default: { name: 'NcContent', template: '<div class="nc-content"><slot /></div>', props: ['appName'] },

src/tests/ExternalApp.spec.ts

Lines changed: 2 additions & 9 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 } from './testHelpers/l10n.js'
78
import { mount } from '@vue/test-utils'
89

910
import { initialActionCode, ACTION_CODES } from '../helpers/ActionMapping'
@@ -12,15 +13,7 @@ vi.mock('@nextcloud/initial-state', () => ({
1213
loadState: vi.fn((app, key, defaultValue) => defaultValue),
1314
}))
1415

15-
vi.mock('@nextcloud/l10n', () => ({
16-
t: vi.fn((_app: string, text: string) => text),
17-
translate: vi.fn((_app: string, text: string) => text),
18-
translatePlural: vi.fn((_app: string, singular: string, plural: string, count: number) => (count === 1 ? singular : plural)),
19-
n: vi.fn((_app: string, singular: string, plural: string, count: number) => (count === 1 ? singular : plural)),
20-
isRTL: vi.fn(() => false),
21-
getLanguage: vi.fn(() => 'en'),
22-
getLocale: vi.fn(() => 'en'),
23-
}))
16+
vi.mock('@nextcloud/l10n', () => createL10nMock())
2417

2518
import ExternalApp from '../ExternalApp.vue'
2619

src/tests/actions/openInLibreSignAction.spec.ts

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

66
import { describe, expect, it, beforeEach, vi, afterEach } from 'vitest'
7+
import { createL10nMock } from '../testHelpers/l10n.js'
78

89
// Mock @nextcloud/logger to avoid import-time errors with @nextcloud/vue
910
vi.mock('@nextcloud/logger', () => ({
@@ -83,15 +84,7 @@ vi.mock('@nextcloud/initial-state', () => ({
8384
}),
8485
}))
8586

86-
vi.mock('@nextcloud/l10n', () => ({
87-
translate: vi.fn((_app: string, text: string) => text),
88-
translatePlural: vi.fn((_app: string, singular: string, plural: string, count: number) => (count === 1 ? singular : plural)),
89-
t: vi.fn((_app: string, text: string) => text),
90-
n: vi.fn((_app: string, singular: string, plural: string, count: number) => (count === 1 ? singular : plural)),
91-
getLanguage: vi.fn(() => 'en'),
92-
getLocale: vi.fn(() => 'en'),
93-
isRTL: vi.fn(() => false),
94-
}))
87+
vi.mock('@nextcloud/l10n', () => createL10nMock())
9588

9689
vi.mock('@nextcloud/vue/functions/dialog', () => ({
9790
spawnDialog: vi.fn(() => Promise.resolve('Test Envelope')),

src/tests/components/CodeEditor.spec.ts

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,12 @@
44
*/
55

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

910
import CodeEditor from '../../components/CodeEditor.vue'
1011

11-
vi.mock('@nextcloud/l10n', () => ({
12-
translate: vi.fn((_app: string, text: string) => text),
13-
translatePlural: vi.fn((_app: string, singular: string, plural: string, count: number) => (count === 1 ? singular : plural)),
14-
t: vi.fn((_app: string, text: string) => text),
15-
n: vi.fn((_app: string, singular: string, plural: string, count: number) => (count === 1 ? singular : plural)),
16-
getLanguage: vi.fn(() => 'en'),
17-
getLocale: vi.fn(() => 'en'),
18-
isRTL: vi.fn(() => false),
19-
}))
12+
vi.mock('@nextcloud/l10n', () => createL10nMock())
2013

2114
vi.mock('@ssddanbrown/codemirror-lang-twig', () => ({
2215
twig: vi.fn(() => ({ name: 'twig-extension' })),

src/tests/components/Draw/FileUpload.spec.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,6 @@ import { beforeEach, describe, expect, it, vi } from 'vitest'
77
import { mount } from '@vue/test-utils'
88
import FileUpload from '../../../components/Draw/FileUpload.vue'
99

10-
vi.mock('@nextcloud/l10n', () => ({
11-
t: vi.fn((_app: string, text: string) => text),
12-
}))
13-
1410
vi.mock('@nextcloud/capabilities', () => ({
1511
getCapabilities: vi.fn(() => ({
1612
libresign: {

src/tests/components/File/File.spec.ts

Lines changed: 2 additions & 6 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 } from '../../testHelpers/l10n.js'
78
import { mount } from '@vue/test-utils'
89

910
import File from '../../../components/File/File.vue'
@@ -36,12 +37,7 @@ const sidebarStoreMock = {
3637
activeRequestSignatureTab: vi.fn(),
3738
}
3839

39-
vi.mock('@nextcloud/l10n', () => ({
40-
t: vi.fn((_app: string, text: string) => text),
41-
getLanguage: vi.fn(() => 'en'),
42-
getLocale: vi.fn(() => 'en'),
43-
isRTL: vi.fn(() => false),
44-
}))
40+
vi.mock('@nextcloud/l10n', () => createL10nMock())
4541

4642
vi.mock('@nextcloud/router', () => ({
4743
generateOcsUrl: vi.fn((path: string, params?: Record<string, string | number>) => {

src/tests/components/FileEntry/FileEntrySigners.spec.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,6 @@ type FileEntrySignersWrapper = VueWrapper<any> & {
2727

2828
let FileEntrySigners: any
2929

30-
vi.mock('@nextcloud/l10n', () => ({
31-
translate: vi.fn((_app: string, text: string) => text),
32-
isRTL: vi.fn(() => false),
33-
}))
34-
3530
beforeAll(async () => {
3631
;({ default: FileEntrySigners } = await import('../../../views/FilesList/FileEntry/FileEntrySigners.vue'))
3732
})

src/tests/components/FileEntry/FileEntryStatus.spec.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,6 @@ type FileEntryStatusWrapper = VueWrapper<any> & {
3131

3232
let FileEntryStatus: any
3333

34-
vi.mock('@nextcloud/l10n', () => ({
35-
translate: vi.fn((_app: string, text: string) => text),
36-
isRTL: vi.fn(() => false),
37-
}))
38-
3934
vi.mock('vue-select', () => ({
4035
default: {
4136
name: 'VSelect',

src/tests/components/FileStatusList.spec.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,14 @@
44
*/
55

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

910
import FileStatusList from '../../components/FileStatusList.vue'
1011

1112
const axiosGetMock = vi.fn()
1213

13-
vi.mock('@nextcloud/l10n', () => ({
14-
t: vi.fn((_app: string, text: string) => text),
15-
n: vi.fn((_app: string, singular: string, plural: string, count: number) => (count === 1 ? singular : plural)),
16-
}))
14+
vi.mock('@nextcloud/l10n', () => createL10nMock())
1715

1816
vi.mock('@nextcloud/files', () => ({
1917
formatFileSize: vi.fn((size: number) => `${size}B`),

src/tests/components/FooterTemplateEditor.spec.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,6 @@ vi.mock('debounce', () => ({
2323
default: vi.fn((fn: (...args: unknown[]) => unknown) => fn),
2424
}))
2525

26-
vi.mock('@nextcloud/l10n', () => ({
27-
t: vi.fn((_app: string, text: string) => text),
28-
}))
29-
3026
vi.mock('@nextcloud/axios', () => ({
3127
default: {
3228
get: vi.fn((...args: unknown[]) => axiosGetMock(...args)),

0 commit comments

Comments
 (0)