From 0ee939d5683cca7fdaa9296d49611d01441e52e3 Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Fri, 28 Feb 2025 19:27:09 +0100 Subject: [PATCH] feat: refs #8647 updates --- src/components/__tests__/CrudModel.spec.js | 16 +------ .../common/__tests__/VnDmsList.spec.js | 43 +++++++++---------- .../ui/__tests__/CardSummary.spec.js | 1 - .../ui/__tests__/VnSearchbar.spec.js | 2 - src/composables/showResultsTable.js | 30 ------------- .../Claim/Card/__tests__/ClaimLines.spec.js | 4 -- .../Claim/Card/__tests__/ClaimPhoto.spec.js | 4 -- .../__tests__/CustomerPayments.spec.js | 4 -- src/pages/Login/__tests__/Login.spec.js | 2 +- test/vitest/helper.js | 15 +++---- 10 files changed, 29 insertions(+), 92 deletions(-) delete mode 100644 src/composables/showResultsTable.js diff --git a/src/components/__tests__/CrudModel.spec.js b/src/components/__tests__/CrudModel.spec.js index f1ffcb200..b0eafbc02 100644 --- a/src/components/__tests__/CrudModel.spec.js +++ b/src/components/__tests__/CrudModel.spec.js @@ -1,6 +1,5 @@ import { createWrapper, axios } from 'app/test/vitest/helper'; import CrudModel from 'components/CrudModel.vue'; -import keyShortcut from 'src/boot/keyShortcut'; import { vi, afterEach, beforeEach, beforeAll, describe, expect, it } from 'vitest'; describe('CrudModel', () => { @@ -10,20 +9,10 @@ describe('CrudModel', () => { beforeAll(() => { wrapper = createWrapper(CrudModel, { global: { - stubs: [ - 'vnPaginate', - 'useState', - 'arrayData', - 'useStateStore', - 'vue-i18n', - 'RouterLink', - ], + stubs: ['vnPaginate', 'vue-i18n'], mocks: { validate: vi.fn(), }, - directives: { - shortcut: keyShortcut, - }, }, propsData: { dataRequired: { @@ -34,9 +23,6 @@ describe('CrudModel', () => { url: 'crudModelUrl', saveFn: '', }, - directives: { - shortcut: keyShortcut, // Registrar la directiva en los tests - }, }); wrapper = wrapper.wrapper; vm = wrapper.vm; diff --git a/src/components/common/__tests__/VnDmsList.spec.js b/src/components/common/__tests__/VnDmsList.spec.js index 9649943a2..deb78d62c 100644 --- a/src/components/common/__tests__/VnDmsList.spec.js +++ b/src/components/common/__tests__/VnDmsList.spec.js @@ -4,11 +4,11 @@ import { vi, afterEach, beforeAll, describe, expect, it } from 'vitest'; describe('VnDmsList', () => { let vm; - const dms = { - userFk: 1, - name: 'DMS 1' + const dms = { + userFk: 1, + name: 'DMS 1', }; - + beforeAll(() => { vi.spyOn(axios, 'get').mockResolvedValue({ data: [] }); vm = createWrapper(VnDmsList, { @@ -18,8 +18,8 @@ describe('VnDmsList', () => { filter: 'wd.workerFk', updateModel: 'Workers', deleteModel: 'WorkerDms', - downloadModel: 'WorkerDms' - } + downloadModel: 'WorkerDms', + }, }).vm; }); @@ -29,46 +29,45 @@ describe('VnDmsList', () => { describe('setData()', () => { const data = [ - { - userFk: 1, + { + userFk: 1, name: 'Jessica', lastName: 'Jones', file: '4.jpg', - created: '2021-07-28 21:00:00' + created: '2021-07-28 21:00:00', }, - { - userFk: 2, + { + userFk: 2, name: 'Bruce', lastName: 'Banner', created: '2022-07-28 21:00:00', dms: { - userFk: 2, + userFk: 2, name: 'Bruce', lastName: 'BannerDMS', created: '2022-07-28 21:00:00', file: '4.jpg', - } + }, }, { userFk: 3, name: 'Natasha', lastName: 'Romanoff', file: '4.jpg', - created: '2021-10-28 21:00:00' - } - ] + created: '2021-10-28 21:00:00', + }, + ]; it('Should replace objects that contain the "dms" property with the value of the same and sort by creation date', () => { vm.setData(data); expect([vm.rows][0][0].lastName).toEqual('BannerDMS'); expect([vm.rows][0][1].lastName).toEqual('Romanoff'); - }); }); describe('parseDms()', () => { - const resultDms = { ...dms, userId:1}; - + const resultDms = { ...dms, userId: 1 }; + it('Should add properties that end with "Fk" by changing the suffix to "Id"', () => { const parsedDms = vm.parseDms(dms); expect(parsedDms).toEqual(resultDms); @@ -76,12 +75,12 @@ describe('VnDmsList', () => { }); describe('showFormDialog()', () => { - const resultDms = { ...dms, userId:1}; - + const resultDms = { ...dms, userId: 1 }; + it('should call fn parseDms() and set show true if dms is defined', () => { vm.showFormDialog(dms); expect(vm.formDialog.show).toEqual(true); expect(vm.formDialog.dms).toEqual(resultDms); }); }); -}); \ No newline at end of file +}); diff --git a/src/components/ui/__tests__/CardSummary.spec.js b/src/components/ui/__tests__/CardSummary.spec.js index 567a14310..6bd742310 100644 --- a/src/components/ui/__tests__/CardSummary.spec.js +++ b/src/components/ui/__tests__/CardSummary.spec.js @@ -22,7 +22,6 @@ describe('CardSummary', () => { beforeEach(() => { wrapper = createWrapper(CardSummary, { global: { - stubs: ['RouterLink'], mocks: { validate: vi.fn(), }, diff --git a/src/components/ui/__tests__/VnSearchbar.spec.js b/src/components/ui/__tests__/VnSearchbar.spec.js index b1820e37d..64014e8d8 100644 --- a/src/components/ui/__tests__/VnSearchbar.spec.js +++ b/src/components/ui/__tests__/VnSearchbar.spec.js @@ -11,8 +11,6 @@ describe('VnSearchbar', () => { beforeEach(async () => { wrapper = createWrapper(VnSearchbar, { - global: { stubs: ['RouterLink'] }, - propsData: { dataKey: 'testKey', filter: null, diff --git a/src/composables/showResultsTable.js b/src/composables/showResultsTable.js deleted file mode 100644 index c7e43ef7c..000000000 --- a/src/composables/showResultsTable.js +++ /dev/null @@ -1,30 +0,0 @@ -import { useI18n } from 'vue-i18n'; - -import { useQuasar } from 'quasar'; - -export function showResultsAsTable(dialog, results, key) { - const quasar = useQuasar(); - const { t } = useI18n(); - function openTable() { - quasar.notify({ - message: t('negative.detail.modal.changeItem.success'), - color: 'positive', - actions: [ - { - label: t('globals.ok'), - color: 'white', - handler: () => { - quasar.dialog({ - component: dialog, - componentProps: { - results, - key, - }, - }); - }, - }, - ], - }); - } - return { openTable }; -} diff --git a/src/pages/Claim/Card/__tests__/ClaimLines.spec.js b/src/pages/Claim/Card/__tests__/ClaimLines.spec.js index b8bc6f9b4..ffbd6bf06 100644 --- a/src/pages/Claim/Card/__tests__/ClaimLines.spec.js +++ b/src/pages/Claim/Card/__tests__/ClaimLines.spec.js @@ -1,7 +1,6 @@ import { vi, describe, expect, it, beforeAll, beforeEach, afterEach } from 'vitest'; import { createWrapper, axios } from 'app/test/vitest/helper'; import ClaimLines from '/src/pages/Claim/Card/ClaimLines.vue'; -import keyShortcut from 'src/boot/keyShortcut'; describe('ClaimLines', () => { let vm; @@ -13,9 +12,6 @@ describe('ClaimLines', () => { mocks: { fetch: vi.fn(), }, - directives: { - shortcut: keyShortcut, - }, }, }).vm; }); diff --git a/src/pages/Claim/Card/__tests__/ClaimPhoto.spec.js b/src/pages/Claim/Card/__tests__/ClaimPhoto.spec.js index 7139fa9e3..8949e18a9 100644 --- a/src/pages/Claim/Card/__tests__/ClaimPhoto.spec.js +++ b/src/pages/Claim/Card/__tests__/ClaimPhoto.spec.js @@ -1,7 +1,6 @@ import { vi, describe, expect, it, beforeAll, afterEach } from 'vitest'; import { createWrapper, axios } from 'app/test/vitest/helper'; import ClaimPhoto from 'pages/Claim/Card/ClaimPhoto.vue'; -import keyShortcut from 'src/boot/keyShortcut'; describe('ClaimPhoto', () => { let vm; @@ -26,9 +25,6 @@ describe('ClaimPhoto', () => { mocks: { fetch: vi.fn(), }, - directives: { - shortcut: keyShortcut, - }, }, }).vm; }); diff --git a/src/pages/Customer/Payments/__tests__/CustomerPayments.spec.js b/src/pages/Customer/Payments/__tests__/CustomerPayments.spec.js index bb4423ddd..0b1457ece 100644 --- a/src/pages/Customer/Payments/__tests__/CustomerPayments.spec.js +++ b/src/pages/Customer/Payments/__tests__/CustomerPayments.spec.js @@ -1,7 +1,6 @@ import { vi, describe, expect, it, beforeAll, afterEach } from 'vitest'; import { createWrapper, axios } from 'app/test/vitest/helper'; import CustomerPayments from 'src/pages/Customer/Payments/CustomerPayments.vue'; -import keyShortcut from 'src/boot/keyShortcut'; describe('CustomerPayments', () => { let vm; @@ -13,9 +12,6 @@ describe('CustomerPayments', () => { mocks: { fetch: vi.fn(), }, - directives: { - shortcut: keyShortcut, - }, }, }).vm; }); diff --git a/src/pages/Login/__tests__/Login.spec.js b/src/pages/Login/__tests__/Login.spec.js index acddec61f..e90a8ee53 100644 --- a/src/pages/Login/__tests__/Login.spec.js +++ b/src/pages/Login/__tests__/Login.spec.js @@ -5,7 +5,7 @@ import Login from 'pages/Login/LoginMain.vue'; describe('Login', () => { let vm; beforeAll(() => { - vm = createWrapper(Login, { global: { stubs: ['RouterLink'] } }).vm; + vm = createWrapper(Login).vm; }); afterEach(() => { diff --git a/test/vitest/helper.js b/test/vitest/helper.js index 05753f820..5e283c1d4 100644 --- a/test/vitest/helper.js +++ b/test/vitest/helper.js @@ -106,6 +106,7 @@ export function createWrapper(component, options) { directives: { shortcut: keyShortcut, }, + stubs: ['useState', 'arrayData', 'useStateStore', 'vue-i18n', 'RouterLink'], }, mocks: { t: (tKey) => tKey, @@ -113,15 +114,11 @@ export function createWrapper(component, options) { }, }; - const mountOptions = Object.assign({}, defaultOptions); - - if (options instanceof Object) { - Object.assign(mountOptions, options); - - if (options.global) { - mountOptions.global.plugins = defaultOptions.global.plugins; - } - } + const mountOptions = { + ...defaultOptions, + ...options, + global: { ...defaultOptions.global, ...options?.global }, + }; const wrapper = mount(component, mountOptions); const vm = wrapper.vm;