Skip to content

Commit b4adab4

Browse files
committed
feat: refactor tests to cover new rule
Signed-off-by: Vitor Mattos <[email protected]>
1 parent d7522d8 commit b4adab4

1 file changed

Lines changed: 97 additions & 0 deletions

File tree

src/tests/components/Request/VisibleElements.spec.js

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -602,4 +602,101 @@ describe('VisibleElements Component - Business Rules', () => {
602602
expect(showError).toHaveBeenCalledWith('save failed')
603603
})
604604
})
605+
606+
describe('RULE: aggregateVisibleElementsByFiles', () => {
607+
it.each([
608+
{
609+
label: 'undefined input',
610+
input: undefined,
611+
expected: [],
612+
},
613+
{
614+
label: 'null input',
615+
input: null,
616+
expected: [],
617+
},
618+
{
619+
label: 'empty array',
620+
input: [],
621+
expected: [],
622+
},
623+
{
624+
label: 'mixed files with invalid entries',
625+
input: [
626+
{ id: 545, visibleElements: [{ elementId: 185, fileId: 545 }] },
627+
{ id: 999, visibleElements: null },
628+
{ id: 546, visibleElements: [{ elementId: 186, fileId: 546 }] },
629+
],
630+
expected: [
631+
{ elementId: 185, fileId: 545 },
632+
{ elementId: 186, fileId: 546 },
633+
],
634+
},
635+
{
636+
label: 'preserves order when a file has multiple elements',
637+
input: [
638+
{
639+
id: 100,
640+
visibleElements: [
641+
{ elementId: 1, fileId: 100 },
642+
{ elementId: 2, fileId: 100 },
643+
],
644+
},
645+
{ id: 200, visibleElements: [{ elementId: 3, fileId: 200 }] },
646+
],
647+
expected: [
648+
{ elementId: 1, fileId: 100 },
649+
{ elementId: 2, fileId: 100 },
650+
{ elementId: 3, fileId: 200 },
651+
],
652+
},
653+
])('handles $label', ({ input, expected }) => {
654+
expect(wrapper.vm.aggregateVisibleElementsByFiles(input)).toEqual(expected)
655+
})
656+
})
657+
658+
describe('RULE: fetchFiles updates document files and visible elements', () => {
659+
it.each([
660+
{
661+
label: 'applies aggregated visible elements when available',
662+
childFiles: [
663+
{ id: 545, name: 'file1.pdf', visibleElements: [{ elementId: 185, fileId: 545 }] },
664+
{ id: 546, name: 'file2.pdf', visibleElements: [{ elementId: 186, fileId: 546 }] },
665+
],
666+
initialVisibleElements: [{ elementId: 999, fileId: 1 }],
667+
expectedVisibleElements: [
668+
{ elementId: 185, fileId: 545 },
669+
{ elementId: 186, fileId: 546 },
670+
],
671+
},
672+
{
673+
label: 'keeps existing visibleElements when aggregated result is empty',
674+
childFiles: [
675+
{ id: 545, name: 'file1.pdf', visibleElements: [] },
676+
{ id: 546, name: 'file2.pdf' },
677+
],
678+
initialVisibleElements: [{ elementId: 999, fileId: 1 }],
679+
expectedVisibleElements: [{ elementId: 999, fileId: 1 }],
680+
},
681+
])('$label', async ({ childFiles, initialVisibleElements, expectedVisibleElements }) => {
682+
filesStore.files[1].id = 544
683+
filesStore.files[1].files = []
684+
filesStore.files[1].visibleElements = initialVisibleElements
685+
686+
axios.get.mockResolvedValue({
687+
data: {
688+
ocs: {
689+
data: {
690+
data: childFiles,
691+
},
692+
},
693+
},
694+
})
695+
696+
await wrapper.vm.fetchFiles()
697+
698+
expect(wrapper.vm.document.files).toEqual(childFiles)
699+
expect(wrapper.vm.document.visibleElements).toEqual(expectedVisibleElements)
700+
})
701+
})
605702
})

0 commit comments

Comments
 (0)