Skip to content

Commit dc23281

Browse files
test(vue3): add RenewEmail coverage
Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
1 parent 0cad0d3 commit dc23281

1 file changed

Lines changed: 130 additions & 0 deletions

File tree

src/tests/views/RenewEmail.spec.ts

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
/*
2+
* SPDX-FileCopyrightText: 2026 LibreSign contributors
3+
* SPDX-License-Identifier: AGPL-3.0-or-later
4+
*/
5+
6+
import { beforeEach, describe, expect, it, vi } from 'vitest'
7+
import { mount } from '@vue/test-utils'
8+
import axios from '@nextcloud/axios'
9+
10+
import RenewEmail from '../../views/RenewEmail.vue'
11+
12+
const loadStateMock = vi.fn((_: string, key: string) => {
13+
const values: Record<string, string> = {
14+
title: 'Renew access',
15+
body: 'Please confirm the email renewal.',
16+
renewButton: 'Renew email',
17+
uuid: 'request-uuid',
18+
}
19+
20+
return values[key]
21+
})
22+
23+
vi.mock('@nextcloud/l10n', () => ({
24+
t: vi.fn((_app: string, text: string) => text),
25+
translate: vi.fn((_app: string, text: string) => text),
26+
translatePlural: vi.fn((_app: string, singular: string, plural: string, count: number) => (count === 1 ? singular : plural)),
27+
n: vi.fn((_app: string, singular: string, plural: string, count: number) => (count === 1 ? singular : plural)),
28+
getLanguage: vi.fn(() => 'en'),
29+
getLocale: vi.fn(() => 'en'),
30+
isRTL: vi.fn(() => false),
31+
}))
32+
33+
vi.mock('@nextcloud/axios', () => ({
34+
default: {
35+
post: vi.fn(),
36+
},
37+
}))
38+
39+
vi.mock('@nextcloud/initial-state', () => ({
40+
loadState: vi.fn((app: string, key: string) => loadStateMock(app, key)),
41+
}))
42+
43+
vi.mock('@nextcloud/router', () => ({
44+
generateOcsUrl: vi.fn((path: string, params?: Record<string, string>) => path.replace('{uuid}', params?.uuid ?? '')),
45+
}))
46+
47+
describe('RenewEmail.vue', () => {
48+
beforeEach(() => {
49+
vi.mocked(axios.post).mockReset()
50+
loadStateMock.mockClear()
51+
})
52+
53+
function createWrapper() {
54+
return mount(RenewEmail, {
55+
global: {
56+
stubs: {
57+
NcButton: {
58+
name: 'NcButton',
59+
props: ['variant', 'wide', 'disabled'],
60+
emits: ['click'],
61+
template: '<button class="renew-button" :disabled="disabled" @click="$emit(\'click\')"><slot /><slot name="icon" /></button>',
62+
},
63+
NcIconSvgWrapper: {
64+
name: 'NcIconSvgWrapper',
65+
props: ['path'],
66+
template: '<span class="icon-stub"></span>',
67+
},
68+
NcLoadingIcon: {
69+
name: 'NcLoadingIcon',
70+
props: ['size'],
71+
template: '<span class="loading-stub"></span>',
72+
},
73+
NcNoteCard: {
74+
name: 'NcNoteCard',
75+
props: ['type'],
76+
template: '<div class="note-card"><slot /></div>',
77+
},
78+
},
79+
},
80+
})
81+
}
82+
83+
it('renders the initial state from the server-side payload', () => {
84+
const wrapper = createWrapper()
85+
86+
expect(wrapper.text()).toContain('Renew access')
87+
expect(wrapper.text()).toContain('Please confirm the email renewal.')
88+
expect(wrapper.text()).toContain('Renew email')
89+
})
90+
91+
it('stores the success message after renewing the email', async () => {
92+
vi.mocked(axios.post).mockResolvedValue({
93+
data: {
94+
ocs: {
95+
data: {
96+
message: 'Email renewed successfully',
97+
},
98+
},
99+
},
100+
})
101+
const wrapper = createWrapper()
102+
103+
await wrapper.vm.renew()
104+
105+
expect(wrapper.vm.response).toBe('Email renewed successfully')
106+
expect(wrapper.vm.error).toBe('')
107+
expect(wrapper.vm.hasLoading).toBe(false)
108+
})
109+
110+
it('stores the error message when the renewal request fails', async () => {
111+
vi.mocked(axios.post).mockRejectedValue({
112+
response: {
113+
data: {
114+
ocs: {
115+
data: {
116+
message: 'Renewal failed',
117+
},
118+
},
119+
},
120+
},
121+
})
122+
const wrapper = createWrapper()
123+
124+
await wrapper.vm.renew()
125+
126+
expect(wrapper.vm.error).toBe('Renewal failed')
127+
expect(wrapper.vm.response).toBe('')
128+
expect(wrapper.vm.hasLoading).toBe(false)
129+
})
130+
})

0 commit comments

Comments
 (0)