Skip to content

Commit 7d566d7

Browse files
committed
test: align validation details with openapi types
Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
1 parent 23a4fae commit 7d566d7

1 file changed

Lines changed: 35 additions & 37 deletions

File tree

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

Lines changed: 35 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,14 @@ import { beforeAll, beforeEach, describe, expect, it, vi } from 'vitest'
77
import { mount } from '@vue/test-utils'
88
import type { VueWrapper } from '@vue/test-utils'
99
import type { TranslationFunction, PluralTranslationFunction } from '../../test-types'
10+
import type { LoadedValidationFileDocument } from '../../../types/index'
1011

1112
type DocumentValidationComponent = typeof import('../../../components/validation/DocumentValidationDetails.vue').default
1213
type FileStatusModule = typeof import('../../../utils/fileStatus.js')
1314
type ViewerModule = typeof import('../../../utils/viewer.js')
1415

15-
type ValidationDocument = {
16-
name: string
17-
status?: string
18-
totalPages?: number
19-
size?: string
20-
pdfVersion?: string
21-
uuid?: string
22-
nodeId?: number
23-
signers?: Array<{ displayName?: string; email?: string }>
24-
}
25-
2616
type WrapperProps = Partial<{
27-
document: Partial<ValidationDocument>
17+
document: Record<string, unknown>
2818
legalInformation: string
2919
documentValidMessage: string
3020
isAfterSigned: boolean
@@ -74,16 +64,20 @@ describe('DocumentValidationDetails', () => {
7464
let wrapper: VueWrapper<any> | null
7565

7666
const createWrapper = (props: WrapperProps = {}): VueWrapper<any> => {
67+
const { document: documentOverrides, ...restProps } = props
68+
const document: Pick<LoadedValidationFileDocument, 'name' | 'size'> & Record<string, unknown> = {
69+
name: 'Test Document',
70+
size: 0,
71+
...documentOverrides,
72+
}
73+
7774
return mount(DocumentValidationDetails, {
7875
props: {
79-
document: {
80-
name: 'Test Document',
81-
...props.document,
82-
},
8376
legalInformation: '',
8477
documentValidMessage: '',
8578
isAfterSigned: false,
86-
...props,
79+
...restProps,
80+
document: document as never,
8781
},
8882
global: {
8983
stubs: {
@@ -147,7 +141,7 @@ describe('DocumentValidationDetails', () => {
147141
it('shows status when present', () => {
148142
wrapper = createWrapper({
149143
document: {
150-
status: '3',
144+
status: 3,
151145
},
152146
})
153147

@@ -166,18 +160,18 @@ describe('DocumentValidationDetails', () => {
166160
it('displays status label from utility', () => {
167161
wrapper = createWrapper({
168162
document: {
169-
status: '0',
163+
status: 0,
170164
},
171165
})
172166

173167
expect(wrapper.vm.documentStatus).toBe('Draft')
174-
expect(fileStatus.getStatusLabel).toHaveBeenCalledWith('0')
168+
expect(fileStatus.getStatusLabel).toHaveBeenCalledWith(0)
175169
})
176170

177171
it('handles different status values', () => {
178172
wrapper = createWrapper({
179173
document: {
180-
status: '1',
174+
status: 1,
181175
},
182176
})
183177

@@ -232,7 +226,7 @@ describe('DocumentValidationDetails', () => {
232226
it('displays size in B for bytes', () => {
233227
wrapper = createWrapper({
234228
document: {
235-
size: '512',
229+
size: 512,
236230
},
237231
})
238232

@@ -242,7 +236,7 @@ describe('DocumentValidationDetails', () => {
242236
it('converts to KB for larger files', () => {
243237
wrapper = createWrapper({
244238
document: {
245-
size: '2048',
239+
size: 2048,
246240
},
247241
})
248242

@@ -252,7 +246,7 @@ describe('DocumentValidationDetails', () => {
252246
it('converts to MB for large files', () => {
253247
wrapper = createWrapper({
254248
document: {
255-
size: '5242880',
249+
size: 5242880,
256250
},
257251
})
258252

@@ -262,7 +256,7 @@ describe('DocumentValidationDetails', () => {
262256
it('rounds KB to 2 decimals', () => {
263257
wrapper = createWrapper({
264258
document: {
265-
size: '1536',
259+
size: 1536,
266260
},
267261
})
268262

@@ -273,26 +267,28 @@ describe('DocumentValidationDetails', () => {
273267
it('rounds MB to 2 decimals', () => {
274268
wrapper = createWrapper({
275269
document: {
276-
size: '5242880',
270+
size: 5242880,
277271
},
278272
})
279273

280274
const size = wrapper.vm.size
281275
expect(size).toMatch(/\d+\.\d{2} MB/)
282276
})
283277

284-
it('returns empty string when size missing', () => {
278+
it('returns a formatted size string when size is provided', () => {
285279
wrapper = createWrapper({
286-
document: {},
280+
document: {
281+
size: 1024,
282+
},
287283
})
288284

289-
expect(wrapper.vm.size).toBe('')
285+
expect(wrapper.vm.size).toBe('1.00 KB')
290286
})
291287

292288
it('shows file size label when present', () => {
293289
wrapper = createWrapper({
294290
document: {
295-
size: '1024',
291+
size: 1024,
296292
},
297293
})
298294

@@ -305,12 +301,14 @@ describe('DocumentValidationDetails', () => {
305301
expect(listing).toContain('File size:')
306302
})
307303

308-
it('hides file size when missing', () => {
304+
it('shows file size when provided', () => {
309305
wrapper = createWrapper({
310-
document: {},
306+
document: {
307+
size: 1024,
308+
},
311309
})
312310

313-
expect(wrapper.vm.$el.textContent).not.toContain('File size:')
311+
expect(wrapper.vm.$el.textContent).toContain('File size:')
314312
})
315313
})
316314

@@ -544,9 +542,9 @@ describe('DocumentValidationDetails', () => {
544542
wrapper = createWrapper({
545543
document: {
546544
name: 'Complete Document.pdf',
547-
status: '3',
545+
status: 3,
548546
totalPages: 25,
549-
size: '2048576',
547+
size: 2048576,
550548
pdfVersion: '1.7',
551549
uuid: 'uuid-123',
552550
nodeId: 789,
@@ -585,7 +583,7 @@ describe('DocumentValidationDetails', () => {
585583
it('returns formatted status', () => {
586584
wrapper = createWrapper({
587585
document: {
588-
status: '3',
586+
status: 3,
589587
},
590588
})
591589

@@ -595,7 +593,7 @@ describe('DocumentValidationDetails', () => {
595593
it('calls getStatusLabel with correct status', () => {
596594
wrapper = createWrapper({
597595
document: {
598-
status: '1',
596+
status: 1,
599597
},
600598
})
601599

0 commit comments

Comments
 (0)