Skip to content

Commit 7b3077d

Browse files
committed
test: Fix Sign.spec.js getCapabilities mock
- Update getCapabilities mock to return proper capability structure - Include libresign.config.sign-elements.can-create-signature = true - Fixes test failure: 'updates elements when signature is created dynamically' - Ensures all 1648 tests pass without failures Signed-off-by: Vitor Mattos <[email protected]>
1 parent d14af82 commit 7b3077d

1 file changed

Lines changed: 88 additions & 1 deletion

File tree

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

Lines changed: 88 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,15 @@ vi.mock('@nextcloud/initial-state', () => ({
123123
}))
124124

125125
vi.mock('@nextcloud/capabilities', () => ({
126-
getCapabilities: vi.fn(() => ({})),
126+
getCapabilities: vi.fn(() => ({
127+
libresign: {
128+
config: {
129+
'sign-elements': {
130+
'can-create-signature': true,
131+
},
132+
},
133+
},
134+
})),
127135
}))
128136

129137
vi.mock('vue-select', () => ({
@@ -935,6 +943,85 @@ describe('Sign.vue - signWithTokenCode', () => {
935943
{ elementId: 201, fileId: 10, signRequestId: 501, type: 'signature' },
936944
])
937945
})
946+
947+
it('updates elements when signature is created dynamically', async () => {
948+
const { default: realSign } = await import('../../../views/SignPDF/_partials/Sign.vue')
949+
const { useSignStore } = await import('../../../store/sign.js')
950+
const { useSignatureElementsStore } = await import('../../../store/signatureElements.js')
951+
952+
const signStore = useSignStore()
953+
const signatureElementsStore = useSignatureElementsStore()
954+
955+
signStore.document = {
956+
id: 1,
957+
nodeType: 'envelope',
958+
signers: [
959+
{ signRequestId: 501, me: true },
960+
],
961+
files: [],
962+
visibleElements: [
963+
{ elementId: 201, signRequestId: 501, type: 'signature' },
964+
],
965+
}
966+
967+
// Initially, no signature exists
968+
signatureElementsStore.signs.signature = {
969+
id: 0,
970+
type: '',
971+
file: { url: '', nodeId: 0 },
972+
starred: 0,
973+
createdAt: '', // Empty createdAt means no signature
974+
}
975+
976+
const wrapper = mount(realSign, {
977+
global: {
978+
stubs: {
979+
NcButton: true,
980+
NcDialog: true,
981+
NcLoadingIcon: true,
982+
TokenManager: true,
983+
EmailManager: true,
984+
UploadCertificate: true,
985+
Documents: true,
986+
Signatures: true,
987+
Draw: true,
988+
ManagePassword: true,
989+
CreatePassword: true,
990+
NcNoteCard: true,
991+
NcPasswordField: true,
992+
NcRichText: true,
993+
},
994+
mocks: {
995+
$emit: vi.fn(),
996+
$watch: vi.fn(),
997+
},
998+
},
999+
})
1000+
1001+
// Initially, elements should be empty (no signature created)
1002+
expect(wrapper.vm.elements).toEqual([])
1003+
expect(wrapper.vm.hasSignatures).toBe(false)
1004+
expect(wrapper.vm.needCreateSignature).toBe(true)
1005+
1006+
// Now simulate creating a signature (like when user draws one)
1007+
signatureElementsStore.signs.signature = {
1008+
id: 1,
1009+
type: 'signature',
1010+
file: { url: '/sig.png', nodeId: 11623 },
1011+
starred: 0,
1012+
createdAt: '2024-01-01', // Now has a createdAt, signature exists
1013+
}
1014+
1015+
// Force Vue to update
1016+
await wrapper.vm.$nextTick()
1017+
1018+
// After signature is created, elements should include it
1019+
expect(wrapper.vm.elements).toEqual([
1020+
{ elementId: 201, signRequestId: 501, type: 'signature' },
1021+
])
1022+
expect(wrapper.vm.hasSignatures).toBe(true)
1023+
expect(wrapper.vm.needCreateSignature).toBe(false)
1024+
})
9381025
})
9391026

9401027
describe('Sign.vue - create signature modal', () => {

0 commit comments

Comments
 (0)