@@ -66,7 +66,15 @@ vi.mock('@nextcloud/initial-state', () => ({
6666} ) )
6767
6868vi . mock ( '@nextcloud/capabilities' , ( ) => ( {
69- getCapabilities : vi . fn ( ( ) => ( { } ) ) ,
69+ getCapabilities : vi . fn ( ( ) => ( {
70+ libresign : {
71+ config : {
72+ 'sign-elements' : {
73+ 'can-create-signature' : true ,
74+ } ,
75+ } ,
76+ } ,
77+ } ) ) ,
7078} ) )
7179
7280describe ( 'Sign.vue - signWithTokenCode' , ( ) => {
@@ -850,5 +858,84 @@ describe('Sign.vue - signWithTokenCode', () => {
850858 { elementId : 201 , fileId : 10 , signRequestId : 501 , type : 'signature' } ,
851859 ] )
852860 } )
861+
862+ it ( 'updates elements when signature is created dynamically' , async ( ) => {
863+ const { default : realSign } = await import ( '../../../views/SignPDF/_partials/Sign.vue' )
864+ const { useSignStore } = await import ( '../../../store/sign.js' )
865+ const { useSignatureElementsStore } = await import ( '../../../store/signatureElements.js' )
866+
867+ const signStore = useSignStore ( )
868+ const signatureElementsStore = useSignatureElementsStore ( )
869+
870+ signStore . document = {
871+ id : 1 ,
872+ nodeType : 'envelope' ,
873+ signers : [
874+ { signRequestId : 501 , me : true } ,
875+ ] ,
876+ files : [ ] ,
877+ visibleElements : [
878+ { elementId : 201 , signRequestId : 501 , type : 'signature' } ,
879+ ] ,
880+ }
881+
882+ // Initially, no signature exists
883+ signatureElementsStore . signs . signature = {
884+ id : 0 ,
885+ type : '' ,
886+ file : { url : '' , nodeId : 0 } ,
887+ starred : 0 ,
888+ createdAt : '' , // Empty createdAt means no signature
889+ }
890+
891+ const wrapper = mount ( realSign , {
892+ global : {
893+ stubs : {
894+ NcButton : true ,
895+ NcDialog : true ,
896+ NcLoadingIcon : true ,
897+ TokenManager : true ,
898+ EmailManager : true ,
899+ UploadCertificate : true ,
900+ Documents : true ,
901+ Signatures : true ,
902+ Draw : true ,
903+ ManagePassword : true ,
904+ CreatePassword : true ,
905+ NcNoteCard : true ,
906+ NcPasswordField : true ,
907+ NcRichText : true ,
908+ } ,
909+ mocks : {
910+ $emit : vi . fn ( ) ,
911+ $watch : vi . fn ( ) ,
912+ } ,
913+ } ,
914+ } )
915+
916+ // Initially, elements should be empty (no signature created)
917+ expect ( wrapper . vm . elements ) . toEqual ( [ ] )
918+ expect ( wrapper . vm . hasSignatures ) . toBe ( false )
919+ expect ( wrapper . vm . needCreateSignature ) . toBe ( true )
920+
921+ // Now simulate creating a signature (like when user draws one)
922+ signatureElementsStore . signs . signature = {
923+ id : 1 ,
924+ type : 'signature' ,
925+ file : { url : '/sig.png' , nodeId : 11623 } ,
926+ starred : 0 ,
927+ createdAt : '2024-01-01' , // Now has a createdAt, signature exists
928+ }
929+
930+ // Force Vue to update
931+ await wrapper . vm . $nextTick ( )
932+
933+ // After signature is created, elements should include it
934+ expect ( wrapper . vm . elements ) . toEqual ( [
935+ { elementId : 201 , signRequestId : 501 , type : 'signature' } ,
936+ ] )
937+ expect ( wrapper . vm . hasSignatures ) . toBe ( true )
938+ expect ( wrapper . vm . needCreateSignature ) . toBe ( false )
939+ } )
853940 } )
854941} )
0 commit comments