From 0d2e7b2611447d4bbf58f76a3dce02d4d62d3ed2 Mon Sep 17 00:00:00 2001 From: alexandre Date: Tue, 18 Apr 2023 13:16:52 +0200 Subject: [PATCH 1/8] refs #5357 refactor vnLog and vnLogFilter --- src/components/common/VnLog.vue | 208 ++++++++++++++++++ .../common/VnLogFilter.vue} | 0 src/pages/Claim/Card/ClaimLog.vue | 199 +---------------- 3 files changed, 210 insertions(+), 197 deletions(-) create mode 100644 src/components/common/VnLog.vue rename src/{pages/Claim/Card/ClaimLogFilter.vue => components/common/VnLogFilter.vue} (100%) diff --git a/src/components/common/VnLog.vue b/src/components/common/VnLog.vue new file mode 100644 index 000000000..1213c8bbc --- /dev/null +++ b/src/components/common/VnLog.vue @@ -0,0 +1,208 @@ + + + + + +en: + actions: + insert: Creates + update: Updates + delete: Deletes + models: + Claim: Claim + ClaimDms: Document + ClaimBeginning: Claimed Sales + ClaimObservation: Observation + properties: + id: ID + claimFk: Claim ID + saleFk: Sale ID + quantity: Quantity + observation: Observation + ticketCreated: Created + created: Created + isChargedToMana: Charged to mana + hasToPickUp: Has to pick Up + dmsFk: Document ID + text: Description + claimStateFk: Claim State + workerFk: Worker + clientFk: Customer + rma: RMA + responsibility: Responsibility + packages: Packages +es: + Audit logs: Registros de auditoría + Property: Propiedad + Before: Antes + After: Después + Yes: Si + Nothing: Nada + actions: + insert: Crea + update: Actualiza + delete: Elimina + models: + Claim: Reclamación + ClaimDms: Documento + ClaimBeginning: Línea reclamada + ClaimObservation: Observación + properties: + id: ID + claimFk: ID reclamación + saleFk: ID linea de venta + quantity: Cantidad + observation: Observación + ticketCreated: Creado + created: Creado + isChargedToMana: Cargado a maná + hasToPickUp: Se debe recoger + dmsFk: ID documento + text: Descripción + claimStateFk: Estado de la reclamación + workerFk: Trabajador + clientFk: Cliente + rma: RMA + responsibility: Responsabilidad + packages: Bultos + diff --git a/src/pages/Claim/Card/ClaimLogFilter.vue b/src/components/common/VnLogFilter.vue similarity index 100% rename from src/pages/Claim/Card/ClaimLogFilter.vue rename to src/components/common/VnLogFilter.vue diff --git a/src/pages/Claim/Card/ClaimLog.vue b/src/pages/Claim/Card/ClaimLog.vue index a5af8c72a..6cf941688 100644 --- a/src/pages/Claim/Card/ClaimLog.vue +++ b/src/pages/Claim/Card/ClaimLog.vue @@ -1,201 +1,6 @@ - - - -en: - actions: - insert: Creates - update: Updates - delete: Deletes - models: - Claim: Claim - ClaimDms: Document - ClaimBeginning: Claimed Sales - ClaimObservation: Observation - properties: - id: ID - claimFk: Claim ID - saleFk: Sale ID - quantity: Quantity - observation: Observation - ticketCreated: Created - created: Created - isChargedToMana: Charged to mana - hasToPickUp: Has to pick Up - dmsFk: Document ID - text: Description - claimStateFk: Claim State - workerFk: Worker - clientFk: Customer - rma: RMA - responsibility: Responsibility - packages: Packages -es: - Audit logs: Registros de auditoría - Property: Propiedad - Before: Antes - After: Después - Yes: Si - Nothing: Nada - actions: - insert: Crea - update: Actualiza - delete: Elimina - models: - Claim: Reclamación - ClaimDms: Documento - ClaimBeginning: Línea reclamada - ClaimObservation: Observación - properties: - id: ID - claimFk: ID reclamación - saleFk: ID linea de venta - quantity: Cantidad - observation: Observación - ticketCreated: Creado - created: Creado - isChargedToMana: Cargado a maná - hasToPickUp: Se debe recoger - dmsFk: ID documento - text: Descripción - claimStateFk: Estado de la reclamación - workerFk: Trabajador - clientFk: Cliente - rma: RMA - responsibility: Responsabilidad - packages: Bultos - -- 2.40.1 From 583314106507641767df9536024c6f8fbb83d4aa Mon Sep 17 00:00:00 2001 From: alexandre Date: Tue, 18 Apr 2023 14:43:18 +0200 Subject: [PATCH 2/8] refs #5357 unit test added --- src/components/FetchData.vue | 20 +++--- .../__tests__/components/common/VnLog.spec.js | 69 +++++++++++++++++++ 2 files changed, 81 insertions(+), 8 deletions(-) create mode 100644 test/vitest/__tests__/components/common/VnLog.spec.js diff --git a/src/components/FetchData.vue b/src/components/FetchData.vue index 4aaa0f64c..4324b6984 100644 --- a/src/components/FetchData.vue +++ b/src/components/FetchData.vue @@ -39,16 +39,20 @@ onMounted(async () => { }); async function fetch() { - const filter = Object.assign({}, $props.filter); - if ($props.where) filter.where = $props.where; - if ($props.sortBy) filter.order = $props.sortBy; - if ($props.limit) filter.limit = $props.limit; + try { + const filter = Object.assign({}, $props.filter); + if ($props.where) filter.where = $props.where; + if ($props.sortBy) filter.order = $props.sortBy; + if ($props.limit) filter.limit = $props.limit; - const { data } = await axios.get($props.url, { - params: { filter }, - }); + const { data } = await axios.get($props.url, { + params: { filter }, + }); - emit('onFetch', data); + emit('onFetch', data); + } catch (e) { + // + } } const render = () => { diff --git a/test/vitest/__tests__/components/common/VnLog.spec.js b/test/vitest/__tests__/components/common/VnLog.spec.js new file mode 100644 index 000000000..8dc511e3f --- /dev/null +++ b/test/vitest/__tests__/components/common/VnLog.spec.js @@ -0,0 +1,69 @@ +import { vi, describe, expect, it, beforeAll, afterEach } from 'vitest'; +import { createWrapper } from 'app/test/vitest/helper'; +import VnLog from 'src/components/common/VnLog.vue'; + +describe('VnLog', () => { + let vm; + beforeAll(() => { + vm = createWrapper(VnLog, { + propsData: { + model: "Claim", + }, + }).vm; + }); + + afterEach(() => { + vi.clearAllMocks(); + }); + + describe('formatValue()', () => { + it('should return Yes if has a true boolean', async () => { + const result = vm.formatValue(true); + + expect(result).toEqual('Yes'); + }); + it('should return No if has a true boolean', async () => { + const result = vm.formatValue(false); + + expect(result).toEqual('No'); + }); + it('should return Nothing if has no params', async () => { + const result = vm.formatValue(); + + expect(result).toEqual('Nothing'); + }); + it('should return a string from a string value', async () => { + const result = vm.formatValue('Something'); + + expect(result).toEqual(`"Something"`); + }); + it('should call to format a date', async () => { + vi.mock('src/filters', () => ({ + toDate: ()=>{ + return "Date formatted" + }, + })); + + const result = vm.formatValue('01-01-1970'); + expect(result).toEqual("Date formatted"); + }); + }); + + describe('actionColor()', () => { + it('should return positive if insert', async () => { + const result = vm.actionColor('insert'); + + expect(result).toEqual('positive'); + }); + it('should return positive if update', async () => { + const result = vm.actionColor('update'); + + expect(result).toEqual('positive'); + }); + it('should return negative if delete', async () => { + const result = vm.actionColor('delete'); + + expect(result).toEqual('negative'); + }); + }); +}); -- 2.40.1 From 27352eaf153eac4411324b58e9ded0e664ca81f5 Mon Sep 17 00:00:00 2001 From: alexandre Date: Tue, 18 Apr 2023 14:46:57 +0200 Subject: [PATCH 3/8] refs #5357 mocked route.params.id --- test/vitest/__tests__/components/common/VnLog.spec.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/test/vitest/__tests__/components/common/VnLog.spec.js b/test/vitest/__tests__/components/common/VnLog.spec.js index 8dc511e3f..5d793e0ac 100644 --- a/test/vitest/__tests__/components/common/VnLog.spec.js +++ b/test/vitest/__tests__/components/common/VnLog.spec.js @@ -10,6 +10,11 @@ describe('VnLog', () => { model: "Claim", }, }).vm; + vm.route = { + params: { + id: 1 + } + } }); afterEach(() => { -- 2.40.1 From 8dfc8d5c73ea462e89b47c8cf9de3cb0114a453d Mon Sep 17 00:00:00 2001 From: alexandre Date: Tue, 18 Apr 2023 14:50:25 +0200 Subject: [PATCH 4/8] refs #5357 mocked useRoute function --- test/vitest/__tests__/components/common/VnLog.spec.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/test/vitest/__tests__/components/common/VnLog.spec.js b/test/vitest/__tests__/components/common/VnLog.spec.js index 5d793e0ac..48785a800 100644 --- a/test/vitest/__tests__/components/common/VnLog.spec.js +++ b/test/vitest/__tests__/components/common/VnLog.spec.js @@ -10,11 +10,11 @@ describe('VnLog', () => { model: "Claim", }, }).vm; - vm.route = { - params: { - id: 1 - } - } + vi.mock('vue-router', () => ({ + useRoute: ()=>{ + return {params: {id: 1}} + }, + })); }); afterEach(() => { -- 2.40.1 From 6fcefc8df18cf2d13984098a31b7f7b1a09f9af7 Mon Sep 17 00:00:00 2001 From: alexandre Date: Tue, 18 Apr 2023 14:55:24 +0200 Subject: [PATCH 5/8] refs #5357 faking route --- test/vitest/__tests__/components/common/VnLog.spec.js | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/test/vitest/__tests__/components/common/VnLog.spec.js b/test/vitest/__tests__/components/common/VnLog.spec.js index 48785a800..5d3af55f4 100644 --- a/test/vitest/__tests__/components/common/VnLog.spec.js +++ b/test/vitest/__tests__/components/common/VnLog.spec.js @@ -10,11 +10,7 @@ describe('VnLog', () => { model: "Claim", }, }).vm; - vi.mock('vue-router', () => ({ - useRoute: ()=>{ - return {params: {id: 1}} - }, - })); + vm.route = {params: {id: 1}} }); afterEach(() => { -- 2.40.1 From a969fb44f8ffa819fd452aad4897b8ddbedb5abc Mon Sep 17 00:00:00 2001 From: alexandre Date: Tue, 18 Apr 2023 14:57:26 +0200 Subject: [PATCH 6/8] refs #5357 faking get request --- test/vitest/__tests__/components/common/VnLog.spec.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/vitest/__tests__/components/common/VnLog.spec.js b/test/vitest/__tests__/components/common/VnLog.spec.js index 5d3af55f4..2dab02c34 100644 --- a/test/vitest/__tests__/components/common/VnLog.spec.js +++ b/test/vitest/__tests__/components/common/VnLog.spec.js @@ -1,5 +1,5 @@ import { vi, describe, expect, it, beforeAll, afterEach } from 'vitest'; -import { createWrapper } from 'app/test/vitest/helper'; +import { createWrapper, axios } from 'app/test/vitest/helper'; import VnLog from 'src/components/common/VnLog.vue'; describe('VnLog', () => { @@ -10,7 +10,7 @@ describe('VnLog', () => { model: "Claim", }, }).vm; - vm.route = {params: {id: 1}} + vi.spyOn(axios, 'get').mockResolvedValue({ data: true }); }); afterEach(() => { -- 2.40.1 From 28d844ab3d46c36416789d9ce0b63af773755ccc Mon Sep 17 00:00:00 2001 From: alexandre Date: Tue, 18 Apr 2023 15:03:50 +0200 Subject: [PATCH 7/8] refs #5357 beforeEach --- test/vitest/__tests__/components/common/VnLog.spec.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/test/vitest/__tests__/components/common/VnLog.spec.js b/test/vitest/__tests__/components/common/VnLog.spec.js index 2dab02c34..6ecf57505 100644 --- a/test/vitest/__tests__/components/common/VnLog.spec.js +++ b/test/vitest/__tests__/components/common/VnLog.spec.js @@ -1,4 +1,4 @@ -import { vi, describe, expect, it, beforeAll, afterEach } from 'vitest'; +import { vi, describe, expect, it, beforeAll, afterEach, beforeEach } from 'vitest'; import { createWrapper, axios } from 'app/test/vitest/helper'; import VnLog from 'src/components/common/VnLog.vue'; @@ -10,9 +10,12 @@ describe('VnLog', () => { model: "Claim", }, }).vm; - vi.spyOn(axios, 'get').mockResolvedValue({ data: true }); }); + beforeEach(()=>{ + vi.spyOn(axios, 'get').mockResolvedValue({ data: true }); + }) + afterEach(() => { vi.clearAllMocks(); }); -- 2.40.1 From 6c9ca97274b04685e47719ea7320b8f726d779ae Mon Sep 17 00:00:00 2001 From: alexandre Date: Thu, 20 Apr 2023 08:25:06 +0200 Subject: [PATCH 8/8] refs #5357 mocking fetch --- .../__tests__/components/common/VnLog.spec.js | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/test/vitest/__tests__/components/common/VnLog.spec.js b/test/vitest/__tests__/components/common/VnLog.spec.js index 6ecf57505..6787b6d51 100644 --- a/test/vitest/__tests__/components/common/VnLog.spec.js +++ b/test/vitest/__tests__/components/common/VnLog.spec.js @@ -1,21 +1,23 @@ -import { vi, describe, expect, it, beforeAll, afterEach, beforeEach } from 'vitest'; -import { createWrapper, axios } from 'app/test/vitest/helper'; +import { vi, describe, expect, it, beforeAll, afterEach } from 'vitest'; +import { createWrapper } from 'app/test/vitest/helper'; import VnLog from 'src/components/common/VnLog.vue'; describe('VnLog', () => { let vm; beforeAll(() => { vm = createWrapper(VnLog, { + global: { + stubs: ['FetchData', 'VnPaginate'], + mocks: { + fetch: vi.fn(), + }, + }, propsData: { model: "Claim", }, }).vm; }); - beforeEach(()=>{ - vi.spyOn(axios, 'get').mockResolvedValue({ data: true }); - }) - afterEach(() => { vi.clearAllMocks(); }); -- 2.40.1