Skip to content

Commit 3943b5b

Browse files
test(vue3): add SignerMenu coverage
Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
1 parent 07e9afc commit 3943b5b

1 file changed

Lines changed: 82 additions & 0 deletions

File tree

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
/**
2+
* SPDX-FileCopyrightText: 2026 LibreCode coop and contributors
3+
* SPDX-License-Identifier: AGPL-3.0-or-later
4+
*/
5+
6+
import { describe, expect, it, vi } from 'vitest'
7+
import { mount } from '@vue/test-utils'
8+
9+
import SignerMenu from '../../../components/PdfEditor/SignerMenu.vue'
10+
11+
describe('SignerMenu.vue', () => {
12+
const signers = [
13+
{ id: 1, displayName: 'Ada Lovelace' },
14+
{ id: 2, email: 'grace@example.com' },
15+
]
16+
17+
function createWrapper(props = {}) {
18+
return mount(SignerMenu, {
19+
props: {
20+
signers,
21+
currentSigner: signers[0],
22+
...props,
23+
},
24+
global: {
25+
stubs: {
26+
NcActions: {
27+
name: 'NcActions',
28+
props: ['forceMenu', 'menuName', 'variant'],
29+
template: '<div class="actions-stub"><slot name="icon" /><slot /></div>',
30+
},
31+
NcActionButton: {
32+
name: 'NcActionButton',
33+
props: ['closeAfterClick'],
34+
emits: ['click'],
35+
template: '<button class="action-button-stub" @click="$emit(\'click\')"><slot name="icon" /><slot /></button>',
36+
},
37+
NcAvatar: {
38+
name: 'NcAvatar',
39+
props: ['size', 'isNoUser', 'displayName'],
40+
template: '<span class="avatar-stub">{{ displayName }}</span>',
41+
},
42+
NcIconSvgWrapper: {
43+
name: 'NcIconSvgWrapper',
44+
props: ['path', 'size'],
45+
template: '<span class="icon-stub"></span>',
46+
},
47+
},
48+
},
49+
})
50+
}
51+
52+
it('renders the current signer label when visible', () => {
53+
const wrapper = createWrapper()
54+
55+
expect(wrapper.find('.actions-stub').exists()).toBe(true)
56+
expect(wrapper.text()).toContain('Ada Lovelace')
57+
})
58+
59+
it('does not render when show is false', () => {
60+
const wrapper = createWrapper({ show: false })
61+
62+
expect(wrapper.find('.actions-stub').exists()).toBe(false)
63+
})
64+
65+
it('uses the provided label getter when available', () => {
66+
const wrapper = createWrapper({
67+
getSignerLabel: (signer: { id: number }) => `Signer #${signer.id}`,
68+
})
69+
70+
expect(wrapper.text()).toContain('Signer #1')
71+
expect(wrapper.text()).toContain('Signer #2')
72+
})
73+
74+
it('emits change when a signer is selected', async () => {
75+
const wrapper = createWrapper()
76+
const buttons = wrapper.findAll('.action-button-stub')
77+
78+
await buttons[1].trigger('click')
79+
80+
expect(wrapper.emitted('change')).toEqual([[signers[1]]])
81+
})
82+
})

0 commit comments

Comments
 (0)