Skip to content

Commit edb3401

Browse files
committed
test: cover envelope validation local ui state
Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
1 parent 85dcc66 commit edb3401

1 file changed

Lines changed: 61 additions & 62 deletions

File tree

src/tests/components/validation/EnvelopeValidation.spec.ts

Lines changed: 61 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,11 @@ type EnvelopeFile = {
1414
name?: string
1515
nodeId?: number
1616
uuid?: string
17-
opened?: boolean
18-
statusText?: string
1917
signed?: string | null
2018
}
2119

2220
type EnvelopeSigner = {
2321
signed?: string
24-
opened?: boolean
2522
displayName?: string
2623
email?: string
2724
userId?: string
@@ -58,8 +55,11 @@ type EnvelopeValidationVm = {
5855
isTouchDevice: boolean
5956
documentStatus: string
6057
$nextTick: () => Promise<void>
61-
toggleDetail: (signer: EnvelopeSigner) => void
62-
toggleFileDetail: (file: Partial<EnvelopeFile>) => void
58+
toggleDetail: (signerIndex: number) => void
59+
toggleFileDetail: (fileIndex: number) => void
60+
isSignerOpen: (signerIndex: number) => boolean
61+
isFileOpen: (fileIndex: number) => boolean
62+
getFileStatusText: (file: Partial<EnvelopeFile>) => string
6363
getName: (signer: Partial<EnvelopeSigner>) => string
6464
getSignerProgressText: (signer: Partial<EnvelopeSigner>) => string
6565
dateFromSqlAnsi: (date: string) => string
@@ -176,8 +176,8 @@ describe('EnvelopeValidation', () => {
176176
vi.clearAllMocks()
177177
})
178178

179-
describe('RULE: initializeDocument sets opened property for files', () => {
180-
it('initializes all files with opened false', async () => {
179+
describe('RULE: local file UI state is isolated from API payload', () => {
180+
it('starts every file collapsed without mutating file objects', async () => {
181181
const files: EnvelopeFile[] = [
182182
{ id: 1, status: '3' },
183183
{ id: 2, status: '0' },
@@ -186,11 +186,13 @@ describe('EnvelopeValidation', () => {
186186
document: { files },
187187
})
188188

189-
expect(files[0].opened).toBe(false)
190-
expect(files[1].opened).toBe(false)
189+
expect(wrapper.vm.isFileOpen(0)).toBe(false)
190+
expect(wrapper.vm.isFileOpen(1)).toBe(false)
191+
expect('opened' in files[0]).toBe(false)
192+
expect('opened' in files[1]).toBe(false)
191193
})
192194

193-
it('sets statusText for each file', async () => {
195+
it('derives file status text without mutating file objects', async () => {
194196
const files: EnvelopeFile[] = [
195197
{ id: 1, status: '3' },
196198
{ id: 2, status: '1' },
@@ -199,14 +201,18 @@ describe('EnvelopeValidation', () => {
199201
document: { files },
200202
})
201203

202-
expect(files[0].statusText).toBe('Signed')
203-
expect(files[1].statusText).toBe('Pending')
204+
expect(wrapper.vm.getFileStatusText(files[0])).toBe('Signed')
205+
expect(wrapper.vm.getFileStatusText(files[1])).toBe('Pending')
206+
expect('statusText' in files[0]).toBe(false)
207+
expect('statusText' in files[1]).toBe(false)
204208
})
205209

206-
it('reinitializes on watched document change', async () => {
210+
it('resets local file state when document prop changes', async () => {
207211
wrapper = createWrapper({
208212
document: { files: [{ id: 1, status: '3' }] },
209213
})
214+
wrapper.vm.toggleFileDetail(0)
215+
expect(wrapper.vm.isFileOpen(0)).toBe(true)
210216

211217
await wrapper.setProps({
212218
document: {
@@ -217,48 +223,37 @@ describe('EnvelopeValidation', () => {
217223
},
218224
})
219225

220-
const document = wrapper.props('document') as EnvelopeDocument
221-
expect(document.files[0]!.opened).toBe(false)
226+
expect(wrapper.vm.isFileOpen(0)).toBe(false)
222227
})
223228
})
224229

225230
describe('RULE: toggleDetail toggles signer details', () => {
226-
it('toggles opened state from false to true', () => {
227-
wrapper = createWrapper()
228-
const signer: EnvelopeSigner = { signed: '2024-06-01', opened: false }
229-
230-
wrapper.vm.toggleDetail(signer)
231-
232-
expect(signer.opened).toBe(true)
233-
})
234-
235-
it('toggles opened state from true to false', () => {
236-
wrapper = createWrapper()
237-
const signer: EnvelopeSigner = { signed: '2024-06-01', opened: true }
231+
it('tracks signer open state locally', () => {
232+
const signer: EnvelopeSigner = { signed: '2024-06-01' }
233+
wrapper = createWrapper({
234+
document: { signers: [signer] },
235+
})
238236

239-
wrapper.vm.toggleDetail(signer)
237+
expect(wrapper.vm.isSignerOpen(0)).toBe(false)
238+
wrapper.vm.toggleDetail(0)
240239

241-
expect(signer.opened).toBe(false)
240+
expect(wrapper.vm.isSignerOpen(0)).toBe(true)
241+
expect('opened' in signer).toBe(false)
242242
})
243243
})
244244

245245
describe('RULE: toggleFileDetail toggles file details', () => {
246-
it('toggles file opened from false to true', () => {
247-
wrapper = createWrapper()
248-
const file = { opened: false }
249-
250-
wrapper.vm.toggleFileDetail(file)
251-
252-
expect(file.opened).toBe(true)
253-
})
254-
255-
it('toggles file opened from true to false', () => {
256-
wrapper = createWrapper()
257-
const file = { opened: true }
246+
it('tracks file open state locally', () => {
247+
const file: EnvelopeFile = { id: 1, status: '3' }
248+
wrapper = createWrapper({
249+
document: { files: [file] },
250+
})
258251

259-
wrapper.vm.toggleFileDetail(file)
252+
expect(wrapper.vm.isFileOpen(0)).toBe(false)
253+
wrapper.vm.toggleFileDetail(0)
260254

261-
expect(file.opened).toBe(false)
255+
expect(wrapper.vm.isFileOpen(0)).toBe(true)
256+
expect('opened' in file).toBe(false)
262257
})
263258
})
264259

@@ -394,36 +389,38 @@ describe('EnvelopeValidation', () => {
394389
})
395390
})
396391

397-
describe('RULE: created lifecycle initializes document', () => {
398-
it('calls initializeDocument on created', () => {
392+
describe('RULE: created lifecycle initializes local UI state', () => {
393+
it('starts file details collapsed on created', () => {
399394
const files: EnvelopeFile[] = [{ id: 1, status: '3' }]
400395
wrapper = createWrapper({
401396
document: { files },
402397
})
403398

404-
expect(files[0].opened).toBe(false)
399+
expect(wrapper.vm.isFileOpen(0)).toBe(false)
405400
})
406401
})
407402

408-
describe('RULE: documentStatus and initializeDocument together manage file state', () => {
403+
describe('RULE: documentStatus and local UI state together manage file state', () => {
409404
it('maintains file state across multiple toggles', () => {
410-
const file: EnvelopeFile = { id: 1, status: '3', opened: false }
405+
const file: EnvelopeFile = { id: 1, status: '3' }
411406
wrapper = createWrapper({
412407
document: { files: [file] },
413408
})
414409

415-
wrapper.vm.toggleFileDetail(file)
416-
expect(file.opened).toBe(true)
410+
wrapper.vm.toggleFileDetail(0)
411+
expect(wrapper.vm.isFileOpen(0)).toBe(true)
417412

418-
wrapper.vm.toggleFileDetail(file)
419-
expect(file.opened).toBe(false)
413+
wrapper.vm.toggleFileDetail(0)
414+
expect(wrapper.vm.isFileOpen(0)).toBe(false)
420415
})
421416

422417
it('reinitializes files when document prop changes', async () => {
423-
const oldFile: EnvelopeFile = { id: 1, status: '3', opened: true }
418+
const oldFile: EnvelopeFile = { id: 1, status: '3' }
424419
wrapper = createWrapper({
425420
document: { files: [oldFile] },
426421
})
422+
wrapper.vm.toggleFileDetail(0)
423+
expect(wrapper.vm.isFileOpen(0)).toBe(true)
427424

428425
const newFile: EnvelopeFile = { id: 2, status: '1' }
429426
await wrapper.setProps({
@@ -435,31 +432,33 @@ describe('EnvelopeValidation', () => {
435432
},
436433
})
437434

438-
expect(newFile.opened).toBe(false)
435+
expect(wrapper.vm.isFileOpen(0)).toBe(false)
436+
expect('opened' in newFile).toBe(false)
439437
})
440438
})
441439

442-
describe('RULE: signer details show only when opened', () => {
443-
it('shows signer details when opened true', async () => {
444-
const signer: EnvelopeSigner = { opened: true, signed: '2024-06-01' }
440+
describe('RULE: signer details show only when local state is open', () => {
441+
it('shows signer details when toggled open', async () => {
442+
const signer: EnvelopeSigner = { signed: '2024-06-01' }
445443
wrapper = createWrapper({
446444
document: { signers: [signer] },
447445
})
446+
wrapper.vm.toggleDetail(0)
448447

449448
await wrapper.vm.$nextTick()
450449

451-
expect(signer.opened).toBe(true)
450+
expect(wrapper.vm.isSignerOpen(0)).toBe(true)
452451
})
453452

454-
it('hides signer details when opened false', async () => {
455-
const signer: EnvelopeSigner = { opened: false }
453+
it('starts with signer details closed', async () => {
454+
const signer: EnvelopeSigner = {}
456455
wrapper = createWrapper({
457456
document: { signers: [signer] },
458457
})
459458

460459
await wrapper.vm.$nextTick()
461460

462-
expect(signer.opened).toBe(false)
461+
expect(wrapper.vm.isSignerOpen(0)).toBe(false)
463462
})
464463
})
465464

@@ -471,7 +470,7 @@ describe('EnvelopeValidation', () => {
471470
})
472471

473472
it('renders actions slot when not touch device and file has nodeId', async () => {
474-
const file: EnvelopeFile = { id: 1, nodeId: 123, opened: false, status: '3', name: 'test.pdf', statusText: 'Signed' }
473+
const file: EnvelopeFile = { id: 1, nodeId: 123, status: '3', name: 'test.pdf' }
475474
wrapper = createWrapper({
476475
document: { files: [file] },
477476
})

0 commit comments

Comments
 (0)