@@ -8,6 +8,7 @@ import { shallowMount } from '@vue/test-utils'
88import type { VueWrapper } from '@vue/test-utils'
99import { createPinia , setActivePinia } from 'pinia'
1010import axios from '@nextcloud/axios'
11+ import { loadState } from '@nextcloud/initial-state'
1112import type { useFilesStore as useFilesStoreType } from '../../../store/files.js'
1213import RequestSignatureTab from '../../../components/RightSidebar/RequestSignatureTab.vue'
1314import { useFilesStore } from '../../../store/files.js'
@@ -104,6 +105,16 @@ describe('RequestSignatureTab - Critical Business Rules', () => {
104105 beforeEach ( async ( ) => {
105106 setActivePinia ( createPinia ( ) )
106107 generateUrlMock . mockClear ( )
108+ vi . mocked ( loadState ) . mockImplementation ( ( app , key , defaultValue ) => {
109+ if ( key === 'config' ) {
110+ return {
111+ 'sign-elements' : { 'is-available' : true } ,
112+ 'identification_documents' : { enabled : false } ,
113+ }
114+ }
115+ if ( key === 'can_request_sign' ) return true
116+ return defaultValue
117+ } )
107118 vi . mocked ( axios . get ) . mockResolvedValue ( { data : { ocs : { data : null } } } as Awaited < ReturnType < typeof axios . get > > )
108119 filesStore = useFilesStore ( )
109120
@@ -435,6 +446,35 @@ describe('RequestSignatureTab - Critical Business Rules', () => {
435446 expect ( generateUrlMock ) . toHaveBeenCalledWith ( '/apps/libresign/p/sign/{uuid}/pdf' , { uuid : 'signer-uuid-123' } )
436447 expect ( wrapper . vm . modalSrc ) . toBe ( '/apps/libresign/p/sign/signer-uuid-123/pdf' )
437448 } )
449+
450+ it ( 'does not use stale sign_request_uuid from initial state when file has no signing UUIDs' , async ( ) => {
451+ vi . mocked ( loadState ) . mockImplementation ( ( app , key , defaultValue ) => {
452+ if ( key === 'sign_request_uuid' ) {
453+ return 'stale-sign-request-uuid'
454+ }
455+ if ( key === 'config' ) {
456+ return {
457+ 'sign-elements' : { 'is-available' : true } ,
458+ 'identification_documents' : { enabled : false } ,
459+ }
460+ }
461+ if ( key === 'can_request_sign' ) return true
462+ return defaultValue
463+ } )
464+
465+ await wrapper . setProps ( { useModal : true } )
466+ await updateFile ( {
467+ signUuid : null ,
468+ signers : [ ] ,
469+ settings : { signerFileUuid : '' } ,
470+ } )
471+ generateUrlMock . mockClear ( )
472+
473+ await wrapper . vm . sign ( )
474+
475+ expect ( generateUrlMock ) . not . toHaveBeenCalledWith ( '/apps/libresign/p/sign/{uuid}/pdf' , { uuid : 'stale-sign-request-uuid' } )
476+ expect ( wrapper . vm . modalSrc ) . toBe ( '' )
477+ } )
438478 } )
439479
440480 describe ( 'RULE: canEditSigningOrder when using ordered flow' , ( ) => {
0 commit comments