Skip to content

Commit 290478a

Browse files
committed
test: cover modal urls in request signature tab
Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
1 parent c13d15c commit 290478a

File tree

1 file changed

+36
-1
lines changed

1 file changed

+36
-1
lines changed

src/tests/components/RightSidebar/RequestSignatureTab.spec.ts

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,18 @@ import type { useFilesStore as useFilesStoreType } from '../../../store/files.js
1010
let RequestSignatureTab: unknown
1111
import { FILE_STATUS } from '../../../constants.js'
1212

13+
const { generateUrlMock } = vi.hoisted(() => ({
14+
generateUrlMock: vi.fn((path: string, params?: Record<string, string | number>) => {
15+
if (!params) {
16+
return path
17+
}
18+
19+
return Object.entries(params).reduce((url, [key, value]) => {
20+
return url.replace(`{${key}}`, String(value))
21+
}, path)
22+
}),
23+
}))
24+
1325
// Mock translation function
1426
;(globalThis as typeof globalThis & { t: (app: string, msg: string) => string }).t = vi.fn((app: string, msg: string) => msg)
1527

@@ -46,7 +58,7 @@ vi.mock('@nextcloud/dialogs')
4658
vi.mock('@nextcloud/axios')
4759
vi.mock('@nextcloud/router', () => ({
4860
generateOcsUrl: vi.fn((path) => `/ocs${path}`),
49-
generateUrl: vi.fn((path) => path),
61+
generateUrl: (...args: Parameters<typeof generateUrlMock>) => generateUrlMock(...args),
5062
getRootUrl: vi.fn(() => ''),
5163
}))
5264

@@ -68,6 +80,7 @@ describe('RequestSignatureTab - Critical Business Rules', () => {
6880

6981
beforeEach(async () => {
7082
setActivePinia(createPinia())
83+
generateUrlMock.mockClear()
7184
RequestSignatureTab = (await import('../../../components/RightSidebar/RequestSignatureTab.vue')).default
7285
const { useFilesStore } = await import('../../../store/files.js')
7386
filesStore = useFilesStore()
@@ -351,6 +364,28 @@ describe('RequestSignatureTab - Critical Business Rules', () => {
351364
})
352365
})
353366

367+
describe('RULE: modal navigation uses absolute generated URLs', () => {
368+
it('uses generateUrl for validation modal links', async () => {
369+
await wrapper.setProps({ useModal: true })
370+
await updateFile({ uuid: 'validation-uuid' })
371+
372+
wrapper.vm.validationFile()
373+
374+
expect(generateUrlMock).toHaveBeenCalledWith('/apps/libresign/p/validation/{uuid}', { uuid: 'validation-uuid' })
375+
expect(wrapper.vm.modalSrc).toBe('/apps/libresign/p/validation/validation-uuid')
376+
})
377+
378+
it('uses generateUrl for signing modal links', async () => {
379+
await wrapper.setProps({ useModal: true })
380+
await updateFile({ signUuid: 'sign-uuid' })
381+
382+
await wrapper.vm.sign()
383+
384+
expect(generateUrlMock).toHaveBeenCalledWith('/apps/libresign/p/sign/{uuid}/pdf', { uuid: 'sign-uuid' })
385+
expect(wrapper.vm.modalSrc).toBe('/apps/libresign/p/sign/sign-uuid/pdf')
386+
})
387+
})
388+
354389
describe('RULE: canEditSigningOrder when using ordered flow', () => {
355390
beforeEach(async () => {
356391
await updateFile({

0 commit comments

Comments
 (0)