-
-
Notifications
You must be signed in to change notification settings - Fork 111
Expand file tree
/
Copy pathConfetti.spec.ts
More file actions
111 lines (90 loc) · 3.31 KB
/
Confetti.spec.ts
File metadata and controls
111 lines (90 loc) · 3.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
/*
* SPDX-FileCopyrightText: 2026 LibreSign contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
import { beforeAll, beforeEach, describe, expect, it, vi } from 'vitest'
import { mount } from '@vue/test-utils'
const loadStateMock = vi.fn()
vi.mock('@nextcloud/initial-state', () => ({
loadState: (...args: unknown[]) => loadStateMock(...args),
}))
vi.mock('@nextcloud/l10n', () => ({
t: vi.fn((_app: string, text: string) => text),
translate: vi.fn((_app: string, text: string) => text),
translatePlural: vi.fn((_app: string, singular: string, plural: string, count: number) => (count === 1 ? singular : plural)),
n: vi.fn((_app: string, singular: string, plural: string, count: number) => (count === 1 ? singular : plural)),
isRTL: vi.fn(() => false),
getLanguage: vi.fn(() => 'en'),
getLocale: vi.fn(() => 'en'),
}))
let Confetti: unknown
beforeAll(async () => {
;({ default: Confetti } = await import('../../../views/Settings/Confetti.vue'))
})
describe('Confetti', () => {
beforeEach(() => {
loadStateMock.mockReset()
})
it('defaults to true when state is not set', async () => {
loadStateMock.mockImplementation((_app: string, key: string, fallback: unknown) => fallback)
const wrapper = mount(Confetti as never, {
global: {
stubs: {
NcSettingsSection: { template: '<div><slot /></div>' },
NcCheckboxRadioSwitch: { template: '<div><slot /></div>' },
},
},
})
expect(wrapper.vm.showConfetti).toBe(true)
})
it('reads show_confetti_after_signing from initial state', async () => {
loadStateMock.mockImplementation((_app: string, key: string, fallback: unknown) => {
if (key === 'show_confetti_after_signing') return true
return fallback
})
const wrapper = mount(Confetti as never, {
global: {
stubs: {
NcSettingsSection: { template: '<div><slot /></div>' },
NcCheckboxRadioSwitch: { template: '<div><slot /></div>' },
},
},
})
expect(wrapper.vm.showConfetti).toBe(true)
})
it('calls OCP.AppConfig.setValue with "1" when enabled', async () => {
loadStateMock.mockImplementation((_app: string, key: string, fallback: unknown) => fallback)
const setValueMock = vi.fn()
vi.stubGlobal('OCP', { AppConfig: { setValue: setValueMock } })
const wrapper = mount(Confetti as never, {
global: {
stubs: {
NcSettingsSection: { template: '<div><slot /></div>' },
NcCheckboxRadioSwitch: { template: '<div><slot /></div>' },
},
},
})
await wrapper.setData({ showConfetti: true })
wrapper.vm.saveShowConfetti()
expect(setValueMock).toHaveBeenCalledWith('libresign', 'show_confetti_after_signing', '1')
})
it('calls OCP.AppConfig.setValue with "0" when disabled', async () => {
loadStateMock.mockImplementation((_app: string, key: string, fallback: unknown) => {
if (key === 'show_confetti_after_signing') return true
return fallback
})
const setValueMock = vi.fn()
vi.stubGlobal('OCP', { AppConfig: { setValue: setValueMock } })
const wrapper = mount(Confetti as never, {
global: {
stubs: {
NcSettingsSection: { template: '<div><slot /></div>' },
NcCheckboxRadioSwitch: { template: '<div><slot /></div>' },
},
},
})
await wrapper.setData({ showConfetti: false })
wrapper.vm.saveShowConfetti()
expect(setValueMock).toHaveBeenCalledWith('libresign', 'show_confetti_after_signing', '0')
})
})