Skip to content

Commit 4b88d17

Browse files
test: cover internal sign route hydration
Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
1 parent 1fa94bd commit 4b88d17

1 file changed

Lines changed: 60 additions & 7 deletions

File tree

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

Lines changed: 60 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ vi.mock('../../../components/PdfEditor/PdfEditor.vue', () => ({
3333
},
3434
}))
3535

36-
vi.mock('../../store/files.js', () => {
36+
vi.mock('../../../store/files.js', () => {
3737
const filesInstance = {
38-
getAllFiles: vi.fn(),
38+
fetchFileDetail: vi.fn(),
3939
addFile: vi.fn(),
4040
selectFile: vi.fn(),
4141
getFile: vi.fn(),
@@ -45,7 +45,7 @@ vi.mock('../../store/files.js', () => {
4545
}
4646
})
4747

48-
vi.mock('../../store/sidebar.js', () => {
48+
vi.mock('../../../store/sidebar.js', () => {
4949
const sidebarInstance = {
5050
toggleSidebar: vi.fn(),
5151
hideSidebar: vi.fn(),
@@ -56,8 +56,8 @@ vi.mock('../../store/sidebar.js', () => {
5656
}
5757
})
5858

59-
vi.mock('../../store/sign.js', async () => {
60-
const actual = await vi.importActual('../../store/sign.js')
59+
vi.mock('../../../store/sign.js', async () => {
60+
const actual = await vi.importActual('../../../store/sign.js')
6161
return actual
6262
})
6363

@@ -66,7 +66,7 @@ describe('SignPDF.vue', () => {
6666
id: 1,
6767
name: 'Envelope',
6868
description: '',
69-
status: '',
69+
status: 0,
7070
statusText: '',
7171
url: '/apps/libresign/p/pdf/uuid-123',
7272
nodeId: 1,
@@ -196,13 +196,13 @@ describe('SignPDF.vue', () => {
196196
id: 10,
197197
name: 'file1',
198198
file: '/file1.pdf',
199+
files: undefined,
199200
metadata: { extension: 'pdf' },
200201
signers: [
201202
{
202203
signRequestId: 501,
203204
displayName: 'Ada',
204205
email: 'ada@example.com',
205-
localKey: 'signer:501',
206206
me: true,
207207
},
208208
],
@@ -296,4 +296,57 @@ describe('SignPDF.vue', () => {
296296
{ message: 'Document not found', scope: 'pdfLoad' },
297297
])
298298
})
299+
300+
it('loads the signing document from file validation when entering the internal sign route', async () => {
301+
const SignPDF = (await import('../../../views/SignPDF/SignPDF.vue')).default
302+
const { useFilesStore } = await import('../../../store/files.js')
303+
const { useSidebarStore } = await import('../../../store/sidebar.js')
304+
const { useSignStore } = await import('../../../store/sign.js')
305+
const filesStore = useFilesStore()
306+
const sidebarStore = useSidebarStore()
307+
const signStore = useSignStore()
308+
const file = createSignDocument({
309+
id: 12,
310+
status: 1,
311+
statusText: 'Ready to sign',
312+
signers: [{ me: true, signRequestId: 44, displayName: 'Admin', email: 'admin@email.tld' }],
313+
})
314+
315+
vi.mocked(filesStore.fetchFileDetail).mockResolvedValue(file)
316+
vi.stubGlobal('fetch', vi.fn().mockResolvedValue({
317+
headers: {
318+
get: vi.fn(() => 'application/pdf'),
319+
},
320+
blob: vi.fn(async () => new Blob(['pdf'], { type: 'application/pdf' })),
321+
}))
322+
323+
mount(SignPDF, {
324+
global: {
325+
stubs: {
326+
TopBar: true,
327+
PdfEditor: true,
328+
NcNoteCard: true,
329+
NcButton: true,
330+
},
331+
mocks: {
332+
$route: { name: 'SignPDF', params: { uuid: 'sign-uuid-123' }, query: {} },
333+
},
334+
},
335+
})
336+
337+
await vi.waitFor(() => {
338+
expect(filesStore.fetchFileDetail).toHaveBeenCalledWith({
339+
uuid: 'sign-uuid-123',
340+
force: true,
341+
})
342+
})
343+
344+
expect(signStore.document).toEqual(expect.objectContaining({
345+
id: 12,
346+
status: 1,
347+
statusText: 'Ready to sign',
348+
}))
349+
expect(filesStore.selectFile).toHaveBeenCalledWith(12)
350+
expect(sidebarStore.activeSignTab).toHaveBeenCalled()
351+
})
299352
})

0 commit comments

Comments
 (0)