From 0bd48d476b5c517201efdae94b5257eb449f8114 Mon Sep 17 00:00:00 2001 From: jtubau Date: Fri, 20 Dec 2024 10:35:31 +0100 Subject: [PATCH 1/7] test: refs #7100 added test to vnNotes component --- .../components/common/VnNotes.spec.js | 66 +++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 test/vitest/__tests__/components/common/VnNotes.spec.js diff --git a/test/vitest/__tests__/components/common/VnNotes.spec.js b/test/vitest/__tests__/components/common/VnNotes.spec.js new file mode 100644 index 000000000..cdd97a924 --- /dev/null +++ b/test/vitest/__tests__/components/common/VnNotes.spec.js @@ -0,0 +1,66 @@ +import { describe, it, expect, vi, beforeAll, afterEach, beforeEach } from 'vitest'; +import { createWrapper, axios } from 'app/test/vitest/helper'; +import VnNotes from 'src/components/ui/VnNotes.vue'; + +describe('VnNotes', () => { + let vm; + let spyFetch; + let postMock; + + beforeAll(async () => { + vi.spyOn(axios, 'get').mockReturnValue({ data: [] }); + + vm = createWrapper(VnNotes, { + propsData: { + url: '/test', + filter: { order: 'created DESC' }, + body: { name: 'Tony', lastName: 'Stark' }, + addNote: false, + selectType: true, + } + }).vm; + }); + + beforeEach(() => { + postMock = vi.spyOn(axios, 'post').mockResolvedValue({ data: {name: 'Tony', lastName: 'Stark', text: 'Test Note', observationTypeFk: 1} }); + spyFetch = vi.spyOn(vm.vnPaginateRef, 'fetch').mockImplementation(() => vi.fn()); + }); + + afterEach(() => { + vi.clearAllMocks(); + }); + + describe('insert', () => { + it('should not call axios.post if newNote.text is empty', async () => { + vm.newNote.text = ''; + vm.newNote.observationTypeFk = 1; + + await vm.insert(); + + expect(postMock).not.toHaveBeenCalled(); + expect(spyFetch).not.toHaveBeenCalled(); + }); + + it('should not call axios.post if observationTypeFk is missing and selectType is set', async () => { + vm.newNote.text = 'Test Note'; + vm.newNote.observationTypeFk = null; + + await vm.insert(); + + expect(postMock).not.toHaveBeenCalled(); + expect(spyFetch).not.toHaveBeenCalled(); + }); + + it('should call axios.post and vnPaginateRef.fetch when newNote is valid', async () => { + vm.newNote.text = 'Test Note'; + vm.newNote.observationTypeFk = 1; + + const expectedBody = {...vm.$props.body, ...{ text: vm.newNote.text, observationTypeFk: vm.newNote.observationTypeFk }}; + + await vm.insert(); + + expect(postMock).toHaveBeenCalledWith(vm.$props.url, expectedBody); + expect(spyFetch).toHaveBeenCalled(); + }); + }); +}); \ No newline at end of file From 69451862bf79616f5ebe40408f6b7b387dc98c14 Mon Sep 17 00:00:00 2001 From: jtubau Date: Fri, 20 Dec 2024 13:20:11 +0100 Subject: [PATCH 2/7] test: refs #7100 modified test and added more cases --- .../components/common/VnNotes.spec.js | 64 +++++++++++++++---- 1 file changed, 53 insertions(+), 11 deletions(-) diff --git a/test/vitest/__tests__/components/common/VnNotes.spec.js b/test/vitest/__tests__/components/common/VnNotes.spec.js index cdd97a924..598ea4526 100644 --- a/test/vitest/__tests__/components/common/VnNotes.spec.js +++ b/test/vitest/__tests__/components/common/VnNotes.spec.js @@ -4,21 +4,23 @@ import VnNotes from 'src/components/ui/VnNotes.vue'; describe('VnNotes', () => { let vm; + let wrapper; let spyFetch; let postMock; + let expectedBody; beforeAll(async () => { vi.spyOn(axios, 'get').mockReturnValue({ data: [] }); - vm = createWrapper(VnNotes, { + wrapper = createWrapper(VnNotes, { propsData: { url: '/test', - filter: { order: 'created DESC' }, body: { name: 'Tony', lastName: 'Stark' }, - addNote: false, - selectType: true, + selectType: false, } - }).vm; + }); + wrapper = wrapper.wrapper; + vm = wrapper.vm; }); beforeEach(() => { @@ -31,9 +33,10 @@ describe('VnNotes', () => { }); describe('insert', () => { - it('should not call axios.post if newNote.text is empty', async () => { - vm.newNote.text = ''; - vm.newNote.observationTypeFk = 1; + it('should not call axios.post and vnPaginateRef.fetch if newNote.text is null', async () => { + vm.newNote.text = null; + vm.newNote.observationTypeFk = null; + await wrapper.setProps({ selectType: true }); await vm.insert(); @@ -41,9 +44,10 @@ describe('VnNotes', () => { expect(spyFetch).not.toHaveBeenCalled(); }); - it('should not call axios.post if observationTypeFk is missing and selectType is set', async () => { - vm.newNote.text = 'Test Note'; + it('should not call axios.post and vnPaginateRef.fetch if newNote.text is empty', async () => { + vm.newNote.text = ""; vm.newNote.observationTypeFk = null; + await wrapper.setProps({ selectType: false }); await vm.insert(); @@ -51,11 +55,49 @@ describe('VnNotes', () => { expect(spyFetch).not.toHaveBeenCalled(); }); + it('should not call axios.post and vnPaginateRef.fetch if observationTypeFk is missing and selectType is true', async () => { + vm.newNote.text = 'Test Note'; + vm.newNote.observationTypeFk = null; + await wrapper.setProps({ selectType: true }); + + await vm.insert(); + + expect(postMock).not.toHaveBeenCalled(); + expect(spyFetch).not.toHaveBeenCalled(); + }); + + it('should call axios.post and vnPaginateRef.fetch if observationTypeFk is missing and selectType is false', async () => { + vm.newNote.text = "Test Note"; + vm.newNote.observationTypeFk = null; + await wrapper.setProps({ selectType: false }); + + expectedBody = {...vm.$props.body, ...{ text: vm.newNote.text, observationTypeFk: vm.newNote.observationTypeFk }}; + + await vm.insert(); + + expect(postMock).toHaveBeenCalledWith(vm.$props.url, expectedBody); + expect(spyFetch).toHaveBeenCalled(); + }); + + it('should call axios.post and vnPaginateRef.fetch if observationTypeFk is setted and selectType is false', async () => { + vm.newNote.text = "Test Note"; + vm.newNote.observationTypeFk = 1; + await wrapper.setProps({ selectType: false }); + + expectedBody = {...vm.$props.body, ...{ text: vm.newNote.text, observationTypeFk: vm.newNote.observationTypeFk }}; + + await vm.insert(); + + expect(postMock).toHaveBeenCalledWith(vm.$props.url, expectedBody); + expect(spyFetch).toHaveBeenCalled(); + }); + it('should call axios.post and vnPaginateRef.fetch when newNote is valid', async () => { vm.newNote.text = 'Test Note'; vm.newNote.observationTypeFk = 1; + wrapper.setProps({ selectType: false }); - const expectedBody = {...vm.$props.body, ...{ text: vm.newNote.text, observationTypeFk: vm.newNote.observationTypeFk }}; + expectedBody = {...vm.$props.body, ...{ text: vm.newNote.text, observationTypeFk: vm.newNote.observationTypeFk }}; await vm.insert(); From 07afbc82efe2038278545a90311fe52c08f404e3 Mon Sep 17 00:00:00 2001 From: jtubau Date: Mon, 23 Dec 2024 09:29:50 +0100 Subject: [PATCH 3/7] refactor: refs #7100 delete unnecesary set prop --- test/vitest/__tests__/components/common/VnNotes.spec.js | 1 - 1 file changed, 1 deletion(-) diff --git a/test/vitest/__tests__/components/common/VnNotes.spec.js b/test/vitest/__tests__/components/common/VnNotes.spec.js index 598ea4526..c9b40007b 100644 --- a/test/vitest/__tests__/components/common/VnNotes.spec.js +++ b/test/vitest/__tests__/components/common/VnNotes.spec.js @@ -16,7 +16,6 @@ describe('VnNotes', () => { propsData: { url: '/test', body: { name: 'Tony', lastName: 'Stark' }, - selectType: false, } }); wrapper = wrapper.wrapper; From 7a2de50d7d01d3ce9785165fa6baf2e13a368ef1 Mon Sep 17 00:00:00 2001 From: jtubau Date: Thu, 26 Dec 2024 08:29:29 +0100 Subject: [PATCH 4/7] feat: refs #8117 filters and values added as needed --- src/components/common/VnSelect.vue | 4 ++-- src/components/common/VnSelectWorker.vue | 3 ++- src/pages/Claim/ClaimFilter.vue | 11 +-------- src/pages/Entry/EntryFilter.vue | 10 +++++--- src/pages/Entry/EntryLatestBuysFilter.vue | 10 ++++---- src/pages/InvoiceIn/InvoiceInFilter.vue | 17 ++++++++++++-- src/pages/InvoiceIn/InvoiceInList.vue | 6 ++--- src/pages/InvoiceOut/InvoiceOutGlobalForm.vue | 12 +--------- src/pages/Item/ItemList.vue | 11 +++++++++ src/pages/Item/ItemListFilter.vue | 23 ++++++++----------- src/pages/Item/ItemRequestFilter.vue | 1 - src/pages/Order/Card/OrderFilter.vue | 1 + src/pages/Ticket/TicketFilter.vue | 10 ++++---- src/pages/Travel/ExtraCommunityFilter.vue | 16 ++++++++++++- src/pages/Travel/TravelFilter.vue | 6 ++--- 15 files changed, 81 insertions(+), 60 deletions(-) diff --git a/src/components/common/VnSelect.vue b/src/components/common/VnSelect.vue index 8aa725b4a..795291f1e 100644 --- a/src/components/common/VnSelect.vue +++ b/src/components/common/VnSelect.vue @@ -194,10 +194,10 @@ function filter(val, options) { } if (!row) return; - const id = row[$props.optionValue]; + const id = String(row[$props.optionValue]); const optionLabel = String(row[$props.optionLabel]).toLowerCase(); - return id == search || optionLabel.includes(search); + return id.includes(search) || optionLabel.includes(search); }); } diff --git a/src/components/common/VnSelectWorker.vue b/src/components/common/VnSelectWorker.vue index b0fef4443..9a8151a3d 100644 --- a/src/components/common/VnSelectWorker.vue +++ b/src/components/common/VnSelectWorker.vue @@ -51,6 +51,7 @@ const url = computed(() => { option-value="id" option-label="nickname" :fields="['id', 'name', 'nickname', 'code']" + :filter-options="['id', 'name', 'nickname', 'code']" sort-by="nickname ASC" > diff --git a/src/pages/Entry/EntryLatestBuysFilter.vue b/src/pages/Entry/EntryLatestBuysFilter.vue index 83124c1bf..7ceaa1325 100644 --- a/src/pages/Entry/EntryLatestBuysFilter.vue +++ b/src/pages/Entry/EntryLatestBuysFilter.vue @@ -69,12 +69,14 @@ const tagValues = ref([]); use-input @update:model-value="searchFn()" > -