Skip to content

Commit a85bc45

Browse files
test(signpdf): cover pdfLoad-scoped visibility behavior
Add unit tests proving PdfEditor is hidden only for pdfLoad-scoped errors and remains visible for non-pdfLoad errors. Update PdfEditor mock to expose a stable DOM marker for assertions. Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
1 parent ecfe60b commit a85bc45

1 file changed

Lines changed: 57 additions & 3 deletions

File tree

src/tests/views/SignPDF/SignPDF.spec.ts

Lines changed: 57 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,7 @@ vi.mock('@nextcloud/capabilities', () => ({
2929
vi.mock('../../../components/PdfEditor/PdfEditor.vue', () => ({
3030
default: {
3131
name: 'PdfEditor',
32-
render() {
33-
return null
34-
},
32+
template: '<div data-test="pdf-editor" />',
3533
},
3634
}))
3735

@@ -214,4 +212,60 @@ describe('SignPDF.vue', () => {
214212
},
215213
])
216214
})
215+
216+
it('hides PDF only when error scope is pdfLoad', async () => {
217+
const SignPDF = (await import('../../../views/SignPDF/SignPDF.vue')).default
218+
const { useSignStore } = await import('../../../store/sign.js')
219+
const signStore = useSignStore()
220+
221+
signStore.document = createSignDocument()
222+
signStore.errors = [{ message: 'Document not found', scope: 'pdfLoad' }]
223+
224+
const wrapper = mount(SignPDF, {
225+
global: {
226+
stubs: {
227+
TopBar: true,
228+
NcNoteCard: true,
229+
NcButton: true,
230+
},
231+
mocks: {
232+
$route: { name: 'TestRoute', params: { uuid: 'uuid-123' }, query: {} },
233+
},
234+
},
235+
})
236+
237+
wrapper.vm.mounted = true
238+
wrapper.vm.pdfBlobs = [new File([new Blob(['pdf'], { type: 'application/pdf' })], 'sample.pdf', { type: 'application/pdf' })]
239+
await wrapper.vm.$nextTick()
240+
241+
expect(wrapper.find('[data-test="pdf-editor"]').exists()).toBe(false)
242+
})
243+
244+
it('keeps PDF visible for non-pdfLoad errors', async () => {
245+
const SignPDF = (await import('../../../views/SignPDF/SignPDF.vue')).default
246+
const { useSignStore } = await import('../../../store/sign.js')
247+
const signStore = useSignStore()
248+
249+
signStore.document = createSignDocument()
250+
signStore.errors = [{ message: 'Certificate validation failed', code: 422 }]
251+
252+
const wrapper = mount(SignPDF, {
253+
global: {
254+
stubs: {
255+
TopBar: true,
256+
NcNoteCard: true,
257+
NcButton: true,
258+
},
259+
mocks: {
260+
$route: { name: 'TestRoute', params: { uuid: 'uuid-123' }, query: {} },
261+
},
262+
},
263+
})
264+
265+
wrapper.vm.mounted = true
266+
wrapper.vm.pdfBlobs = [new File([new Blob(['pdf'], { type: 'application/pdf' })], 'sample.pdf', { type: 'application/pdf' })]
267+
await wrapper.vm.$nextTick()
268+
269+
expect(wrapper.find('[data-test="pdf-editor"]').exists()).toBe(true)
270+
})
217271
})

0 commit comments

Comments
 (0)