feat: updates

This commit is contained in:
Javier Segarra 2025-01-23 11:33:19 +01:00
parent ff63a8fd11
commit 5f2b71dc70
13 changed files with 212 additions and 566 deletions

View File

@ -54,12 +54,17 @@
"postcss": "^8.4.23", "postcss": "^8.4.23",
"prettier": "^3.4.2", "prettier": "^3.4.2",
"sass": "^1.83.4", "sass": "^1.83.4",
"vitest": "^2.0.0" "vitest": "^3.0.3"
}, },
"engines": { "engines": {
"node": "^20 || ^18 || ^16", "node": "^20 || ^18 || ^16",
"npm": ">= 8.1.2", "npm": ">= 8.1.2",
"yarn": ">= 1.21.1", "yarn": ">= 1.21.1",
"bun": ">= 1.0.25" "bun": ">= 1.0.25"
},
"overrides": {
"@vitejs/plugin-vue": "^5.2.1",
"vite": "^6.0.11",
"vitest": "^0.31.1"
} }
} }

File diff suppressed because it is too large Load Diff

View File

@ -1,8 +1,7 @@
import { describe, expect, it, beforeEach, afterEach, vi } from 'vitest'; import { describe, expect, it, beforeEach, afterEach, vi } from 'vitest';
import { createWrapper } from 'app/test/vitest/helper'; import { createWrapper } from 'app/test/vitest/helper';
import VnVisibleColumn from '../VnVisibleColumn.vue'; import VnVisibleColumn from '../VnVisibleColumn.vue';
import { axios } from 'app/test/vitest/helper'; import { default as axios } from 'axios';
describe('VnVisibleColumns', () => { describe('VnVisibleColumns', () => {
let wrapper; let wrapper;
let vm; let vm;

View File

@ -1,4 +1,6 @@
import { createWrapper, axios } from 'app/test/vitest/helper'; import { createWrapper } from 'app/test/vitest/helper';
import { default as axios } from 'axios';
import CrudModel from 'components/CrudModel.vue'; import CrudModel from 'components/CrudModel.vue';
import { vi, afterEach, beforeEach, beforeAll, describe, expect, it } from 'vitest'; import { vi, afterEach, beforeEach, beforeAll, describe, expect, it } from 'vitest';
@ -168,16 +170,18 @@ describe('CrudModel', () => {
result = vm.isEmpty(dummyArray); result = vm.isEmpty(dummyArray);
expect(result).toBe(false); expect(result).toBe(false);
}) });
}); });
describe('resetData()', () => { describe('resetData()', () => {
it('should add $index to elements in data[] and sets originalData and formData with data', async () => { it('should add $index to elements in data[] and sets originalData and formData with data', async () => {
data = [{ data = [
{
name: 'Tony', name: 'Tony',
lastName: 'Stark', lastName: 'Stark',
age: 42, age: 42,
}]; },
];
vm.resetData(data); vm.resetData(data);
@ -210,11 +214,13 @@ describe('CrudModel', () => {
}); });
describe('saveChanges()', () => { describe('saveChanges()', () => {
data = [{ data = [
{
name: 'Tony', name: 'Tony',
lastName: 'Stark', lastName: 'Stark',
age: 42, age: 42,
}]; },
];
it('should call saveFn if exists', async () => { it('should call saveFn if exists', async () => {
await wrapper.setProps({ saveFn: vi.fn() }); await wrapper.setProps({ saveFn: vi.fn() });
@ -231,11 +237,13 @@ describe('CrudModel', () => {
it("should use default url if there's not saveFn", async () => { it("should use default url if there's not saveFn", async () => {
const postMock = vi.spyOn(axios, 'post'); const postMock = vi.spyOn(axios, 'post');
vm.formData = [{ vm.formData = [
{
name: 'Bruce', name: 'Bruce',
lastName: 'Wayne', lastName: 'Wayne',
age: 45, age: 45,
}] },
];
await vm.saveChanges(data); await vm.saveChanges(data);

View File

@ -1,4 +1,5 @@
import { createWrapper, axios } from 'app/test/vitest/helper'; import { createWrapper } from 'app/test/vitest/helper';
import { default as axios } from 'axios';
import EditForm from 'components/EditTableCellValueForm.vue'; import EditForm from 'components/EditTableCellValueForm.vue';
import { vi, afterEach, beforeAll, describe, expect, it } from 'vitest'; import { vi, afterEach, beforeAll, describe, expect, it } from 'vitest';

View File

@ -1,4 +1,6 @@
import { createWrapper, axios } from 'app/test/vitest/helper'; import { createWrapper } from 'app/test/vitest/helper';
import { default as axios } from 'axios';
import FilterItemForm from 'src/components/FilterItemForm.vue'; import FilterItemForm from 'src/components/FilterItemForm.vue';
import { vi, beforeAll, describe, expect, it } from 'vitest'; import { vi, beforeAll, describe, expect, it } from 'vitest';
@ -38,7 +40,7 @@ describe('FilterItemForm', () => {
{ relation: 'producer', scope: { fields: ['name'] } }, { relation: 'producer', scope: { fields: ['name'] } },
{ relation: 'ink', scope: { fields: ['name'] } }, { relation: 'ink', scope: { fields: ['name'] } },
], ],
where: {"name":{"like":"%bolas de madera%"}}, where: { name: { like: '%bolas de madera%' } },
}; };
expect(axios.get).toHaveBeenCalledWith('Items/withName', { expect(axios.get).toHaveBeenCalledWith('Items/withName', {

View File

@ -1,5 +1,7 @@
import { describe, expect, it, beforeAll, vi, afterAll } from 'vitest'; import { describe, expect, it, beforeAll, vi, afterAll } from 'vitest';
import { createWrapper, axios } from 'app/test/vitest/helper'; import { createWrapper } from 'app/test/vitest/helper';
import { default as axios } from 'axios';
import FormModel from 'src/components/FormModel.vue'; import FormModel from 'src/components/FormModel.vue';
describe('FormModel', () => { describe('FormModel', () => {

View File

@ -1,4 +1,6 @@
import { createWrapper, axios } from 'app/test/vitest/helper'; import { createWrapper } from 'app/test/vitest/helper';
import { default as axios } from 'axios';
import VnDmsList from 'src/components/common/VnDmsList.vue'; import VnDmsList from 'src/components/common/VnDmsList.vue';
import { vi, afterEach, beforeAll, describe, expect, it } from 'vitest'; import { vi, afterEach, beforeAll, describe, expect, it } from 'vitest';
@ -6,7 +8,7 @@ describe('VnDmsList', () => {
let vm; let vm;
const dms = { const dms = {
userFk: 1, userFk: 1,
name: 'DMS 1' name: 'DMS 1',
}; };
beforeAll(() => { beforeAll(() => {
@ -18,8 +20,8 @@ describe('VnDmsList', () => {
filter: 'wd.workerFk', filter: 'wd.workerFk',
updateModel: 'Workers', updateModel: 'Workers',
deleteModel: 'WorkerDms', deleteModel: 'WorkerDms',
downloadModel: 'WorkerDms' downloadModel: 'WorkerDms',
} },
}).vm; }).vm;
}); });
@ -34,7 +36,7 @@ describe('VnDmsList', () => {
name: 'Jessica', name: 'Jessica',
lastName: 'Jones', lastName: 'Jones',
file: '4.jpg', file: '4.jpg',
created: '2021-07-28 21:00:00' created: '2021-07-28 21:00:00',
}, },
{ {
userFk: 2, userFk: 2,
@ -47,22 +49,21 @@ describe('VnDmsList', () => {
lastName: 'BannerDMS', lastName: 'BannerDMS',
created: '2022-07-28 21:00:00', created: '2022-07-28 21:00:00',
file: '4.jpg', file: '4.jpg',
} },
}, },
{ {
userFk: 3, userFk: 3,
name: 'Natasha', name: 'Natasha',
lastName: 'Romanoff', lastName: 'Romanoff',
file: '4.jpg', 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', () => { it('Should replace objects that contain the "dms" property with the value of the same and sort by creation date', () => {
vm.setData(data); vm.setData(data);
expect([vm.rows][0][0].lastName).toEqual('BannerDMS'); expect([vm.rows][0][0].lastName).toEqual('BannerDMS');
expect([vm.rows][0][1].lastName).toEqual('Romanoff'); expect([vm.rows][0][1].lastName).toEqual('Romanoff');
}); });
}); });

View File

@ -1,5 +1,7 @@
import { describe, it, expect, vi, beforeAll, afterEach, beforeEach } from 'vitest'; import { describe, it, expect, vi, beforeAll, afterEach, beforeEach } from 'vitest';
import { createWrapper, axios } from 'app/test/vitest/helper'; import { createWrapper } from 'app/test/vitest/helper';
import { default as axios } from 'axios';
import VnNotes from 'src/components/ui/VnNotes.vue'; import VnNotes from 'src/components/ui/VnNotes.vue';
describe('VnNotes', () => { describe('VnNotes', () => {
@ -8,10 +10,18 @@ describe('VnNotes', () => {
let spyFetch; let spyFetch;
let postMock; let postMock;
let expectedBody; let expectedBody;
const mockData= {name: 'Tony', lastName: 'Stark', text: 'Test Note', observationTypeFk: 1}; const mockData = {
name: 'Tony',
lastName: 'Stark',
text: 'Test Note',
observationTypeFk: 1,
};
function generateExpectedBody() { function generateExpectedBody() {
expectedBody = {...vm.$props.body, ...{ text: vm.newNote.text, observationTypeFk: vm.newNote.observationTypeFk }}; expectedBody = {
...vm.$props.body,
...{ text: vm.newNote.text, observationTypeFk: vm.newNote.observationTypeFk },
};
} }
async function setTestParams(text, observationType, type) { async function setTestParams(text, observationType, type) {
@ -27,7 +37,7 @@ describe('VnNotes', () => {
propsData: { propsData: {
url: '/test', url: '/test',
body: { name: 'Tony', lastName: 'Stark' }, body: { name: 'Tony', lastName: 'Stark' },
} },
}); });
wrapper = wrapper.wrapper; wrapper = wrapper.wrapper;
vm = wrapper.vm; vm = wrapper.vm;
@ -54,7 +64,7 @@ describe('VnNotes', () => {
}); });
it('should not call axios.post and vnPaginateRef.fetch if newNote.text is empty', async () => { it('should not call axios.post and vnPaginateRef.fetch if newNote.text is empty', async () => {
await setTestParams( "", null, false ); await setTestParams('', null, false);
await vm.insert(); await vm.insert();
@ -63,7 +73,7 @@ describe('VnNotes', () => {
}); });
it('should not call axios.post and vnPaginateRef.fetch if observationTypeFk is missing and selectType is true', async () => { it('should not call axios.post and vnPaginateRef.fetch if observationTypeFk is missing and selectType is true', async () => {
await setTestParams( "Test Note", null, true ); await setTestParams('Test Note', null, true);
await vm.insert(); await vm.insert();
@ -72,7 +82,7 @@ describe('VnNotes', () => {
}); });
it('should call axios.post and vnPaginateRef.fetch if observationTypeFk is missing and selectType is false', async () => { it('should call axios.post and vnPaginateRef.fetch if observationTypeFk is missing and selectType is false', async () => {
await setTestParams( "Test Note", null, false ); await setTestParams('Test Note', null, false);
generateExpectedBody(); generateExpectedBody();
@ -83,7 +93,7 @@ describe('VnNotes', () => {
}); });
it('should call axios.post and vnPaginateRef.fetch if observationTypeFk is setted and selectType is false', async () => { it('should call axios.post and vnPaginateRef.fetch if observationTypeFk is setted and selectType is false', async () => {
await setTestParams( "Test Note", 1, false ); await setTestParams('Test Note', 1, false);
generateExpectedBody(); generateExpectedBody();
@ -94,7 +104,7 @@ describe('VnNotes', () => {
}); });
it('should call axios.post and vnPaginateRef.fetch when newNote is valid', async () => { it('should call axios.post and vnPaginateRef.fetch when newNote is valid', async () => {
await setTestParams( "Test Note", 1, true ); await setTestParams('Test Note', 1, true);
generateExpectedBody(); generateExpectedBody();

View File

@ -1,5 +1,7 @@
import { vi, describe, expect, it, beforeAll, afterEach, beforeEach } from 'vitest'; import { vi, describe, expect, it, beforeAll, afterEach, beforeEach } from 'vitest';
import { createWrapper, axios } from 'app/test/vitest/helper'; import { createWrapper } from 'app/test/vitest/helper';
import { default as axios } from 'axios';
import CardSummary from 'src/components/ui/CardSummary.vue'; import CardSummary from 'src/components/ui/CardSummary.vue';
import * as vueRouter from 'vue-router'; import * as vueRouter from 'vue-router';

View File

@ -60,7 +60,7 @@ export function useSession() {
const { data: isValidToken } = await axios.get('VnUsers/validateToken'); const { data: isValidToken } = await axios.get('VnUsers/validateToken');
if (isValidToken) if (isValidToken)
destroyTokenPromises = Object.entries(tokens).map(([key, url]) => destroyTokenPromises = Object.entries(tokens).map(([key, url]) =>
destroyToken(url, storage, key) destroyToken(url, storage, key),
); );
} }
} finally { } finally {

View File

@ -61,7 +61,7 @@ watch(
() => { () => {
claimDmsFilter.value.where.id = router.currentRoute.value.params.id; claimDmsFilter.value.where.id = router.currentRoute.value.params.id;
claimDmsRef.value.fetch(); claimDmsRef.value.fetch();
} },
); );
function openDialog(dmsId) { function openDialog(dmsId) {

View File

@ -40,8 +40,6 @@ vi.mock('vue-router', () => ({
onBeforeRouteLeave: () => {}, onBeforeRouteLeave: () => {},
})); }));
vi.mock('axios');
vi.spyOn(useValidator, 'useValidator').mockImplementation(() => { vi.spyOn(useValidator, 'useValidator').mockImplementation(() => {
return { return {
validate: vi.fn(), validate: vi.fn(),