Skip to content

Commit 1002576

Browse files
test(vue3): add PdfEditor Signature coverage
Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
1 parent 9c47968 commit 1002576

1 file changed

Lines changed: 129 additions & 0 deletions

File tree

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
/*
2+
* SPDX-FileCopyrightText: 2026 LibreSign contributors
3+
* SPDX-License-Identifier: AGPL-3.0-or-later
4+
*/
5+
6+
import { beforeEach, describe, expect, it } from 'vitest'
7+
import { mount } from '@vue/test-utils'
8+
9+
import Signature from '../../../components/PdfEditor/Signature.vue'
10+
11+
describe('PdfEditor Signature.vue', () => {
12+
let wrapper: ReturnType<typeof mount>
13+
14+
beforeEach(() => {
15+
wrapper = mount(Signature, {
16+
props: {
17+
displayName: 'Ada Lovelace',
18+
width: 200,
19+
height: 100,
20+
x: 50,
21+
y: 60,
22+
originWidth: 200,
23+
originHeight: 100,
24+
pageScale: 1,
25+
},
26+
global: {
27+
stubs: {
28+
NcIconSvgWrapper: true,
29+
},
30+
},
31+
})
32+
})
33+
34+
it('emits the initial scaled size on mount', async () => {
35+
const localWrapper = mount(Signature, {
36+
props: {
37+
width: 800,
38+
height: 600,
39+
originWidth: 800,
40+
originHeight: 600,
41+
},
42+
global: {
43+
stubs: {
44+
NcIconSvgWrapper: true,
45+
},
46+
},
47+
})
48+
49+
await localWrapper.vm.$nextTick()
50+
51+
expect(localWrapper.emitted('onUpdate')).toEqual([
52+
[{ width: 500, height: 375 }],
53+
])
54+
})
55+
56+
it('updates translation while dragging and emits the final coordinates', async () => {
57+
const currentTarget = {} as unknown as EventTarget
58+
59+
wrapper.vm.handlePanStart({
60+
type: 'mousedown',
61+
clientX: 10,
62+
clientY: 20,
63+
target: currentTarget,
64+
currentTarget,
65+
} as MouseEvent)
66+
wrapper.vm.handlePanMove({
67+
type: 'mousemove',
68+
clientX: 30,
69+
clientY: 50,
70+
} as MouseEvent)
71+
72+
expect(wrapper.vm.containerStyle).toEqual({
73+
width: '200px',
74+
height: '100px',
75+
transform: 'translate(20px, 30px)',
76+
})
77+
78+
wrapper.vm.handlePanEnd({
79+
type: 'mouseup',
80+
clientX: 30,
81+
clientY: 50,
82+
} as MouseEvent)
83+
await wrapper.vm.$nextTick()
84+
85+
expect(wrapper.emitted('onUpdate')).toEqual([
86+
[{ width: 200, height: 100 }],
87+
[{ x: 70, y: 90 }],
88+
])
89+
})
90+
91+
it('resizes from selector handles and emits updated bounds', async () => {
92+
const currentTarget = {} as unknown as EventTarget
93+
const target = {
94+
dataset: {
95+
direction: 'left-top',
96+
},
97+
} as unknown as EventTarget
98+
99+
wrapper.vm.handlePanStart({
100+
type: 'mousedown',
101+
clientX: 100,
102+
clientY: 100,
103+
target,
104+
currentTarget,
105+
} as MouseEvent)
106+
wrapper.vm.handlePanMove({
107+
type: 'mousemove',
108+
clientX: 80,
109+
clientY: 70,
110+
} as MouseEvent)
111+
wrapper.vm.handlePanEnd({
112+
type: 'mouseup',
113+
clientX: 80,
114+
clientY: 70,
115+
} as MouseEvent)
116+
await wrapper.vm.$nextTick()
117+
118+
expect(wrapper.emitted('onUpdate')).toEqual([
119+
[{ width: 200, height: 100 }],
120+
[{ x: 30, y: 30, width: 220, height: 110 }],
121+
])
122+
})
123+
124+
it('emits onDelete when requested', async () => {
125+
await wrapper.find('.delete').trigger('click')
126+
127+
expect(wrapper.emitted('onDelete')).toEqual([[]])
128+
})
129+
})

0 commit comments

Comments
 (0)