|
6 | 6 | import { describe, expect, it, beforeEach } from 'vitest' |
7 | 7 | import { setActivePinia, createPinia } from 'pinia' |
8 | 8 | import { useSignStore } from './sign.js' |
| 9 | +import { FILE_STATUS } from '../constants.js' |
9 | 10 |
|
10 | 11 | describe('useSignStore', () => { |
11 | 12 | beforeEach(() => { |
@@ -44,4 +45,66 @@ describe('useSignStore', () => { |
44 | 45 | expect(store.pendingAction).toBe('createPassword') |
45 | 46 | }) |
46 | 47 | }) |
| 48 | + |
| 49 | + describe('ableToSign getter', () => { |
| 50 | + it('returns false when document status is not ABLE_TO_SIGN or PARTIAL_SIGNED', () => { |
| 51 | + const store = useSignStore() |
| 52 | + store.document = { |
| 53 | + status: FILE_STATUS.DRAFT, |
| 54 | + signers: [{ me: true, status: 1 }], |
| 55 | + } |
| 56 | + expect(store.ableToSign).toBe(false) |
| 57 | + }) |
| 58 | + |
| 59 | + it('returns false when there is no signer with me: true', () => { |
| 60 | + const store = useSignStore() |
| 61 | + store.document = { |
| 62 | + status: FILE_STATUS.ABLE_TO_SIGN, |
| 63 | + signers: [{ me: false, status: 1 }], |
| 64 | + } |
| 65 | + expect(store.ableToSign).toBe(false) |
| 66 | + }) |
| 67 | + |
| 68 | + it('returns false when signer status is not ABLE_TO_SIGN (status 1)', () => { |
| 69 | + const store = useSignStore() |
| 70 | + store.document = { |
| 71 | + status: FILE_STATUS.ABLE_TO_SIGN, |
| 72 | + signers: [{ me: true, status: 0 }], |
| 73 | + } |
| 74 | + expect(store.ableToSign).toBe(false) |
| 75 | + }) |
| 76 | + |
| 77 | + it('returns true when document status is ABLE_TO_SIGN and signer can sign', () => { |
| 78 | + const store = useSignStore() |
| 79 | + store.document = { |
| 80 | + status: FILE_STATUS.ABLE_TO_SIGN, |
| 81 | + signers: [{ me: true, status: 1 }], |
| 82 | + } |
| 83 | + expect(store.ableToSign).toBe(true) |
| 84 | + }) |
| 85 | + |
| 86 | + it('returns true when document status is PARTIAL_SIGNED and signer can sign', () => { |
| 87 | + const store = useSignStore() |
| 88 | + store.document = { |
| 89 | + status: FILE_STATUS.PARTIAL_SIGNED, |
| 90 | + signers: [{ me: true, status: 1 }], |
| 91 | + } |
| 92 | + expect(store.ableToSign).toBe(true) |
| 93 | + }) |
| 94 | + |
| 95 | + it('returns false when document is undefined', () => { |
| 96 | + const store = useSignStore() |
| 97 | + store.document = undefined |
| 98 | + expect(store.ableToSign).toBe(false) |
| 99 | + }) |
| 100 | + |
| 101 | + it('returns false when signers array is empty', () => { |
| 102 | + const store = useSignStore() |
| 103 | + store.document = { |
| 104 | + status: FILE_STATUS.ABLE_TO_SIGN, |
| 105 | + signers: [], |
| 106 | + } |
| 107 | + expect(store.ableToSign).toBe(false) |
| 108 | + }) |
| 109 | + }) |
47 | 110 | }) |
0 commit comments