2023-04-20 06:25:06 +00:00
|
|
|
import { vi, describe, expect, it, beforeAll, afterEach } from 'vitest';
|
2023-10-04 13:46:15 +00:00
|
|
|
import { createWrapper, axios } from 'app/test/vitest/helper';
|
2023-04-18 12:43:18 +00:00
|
|
|
import VnLog from 'src/components/common/VnLog.vue';
|
|
|
|
|
2023-09-29 13:03:02 +00:00
|
|
|
describe('VnLog', () => {
|
|
|
|
let vm;
|
2023-10-04 13:46:15 +00:00
|
|
|
const fakeLogTreeData = [
|
|
|
|
{
|
|
|
|
id: 2,
|
|
|
|
originFk: 1,
|
|
|
|
userFk: 18,
|
|
|
|
action: 'update',
|
|
|
|
changedModel: 'ClaimObservation',
|
|
|
|
oldInstance: {},
|
|
|
|
newInstance: {
|
|
|
|
claimFk: 1,
|
|
|
|
text: 'Waiting for customer',
|
|
|
|
},
|
|
|
|
creationDate: '2023-09-18T12:25:34.000Z',
|
|
|
|
changedModelId: '1',
|
|
|
|
changedModelValue: null,
|
|
|
|
description: null,
|
|
|
|
user: {
|
|
|
|
id: 18,
|
|
|
|
name: 'salesPerson',
|
|
|
|
nickname: 'salesPersonNick',
|
|
|
|
image: '4fa3ada0-3ac4-11eb-9ab8-27f6fc3b85fd',
|
|
|
|
worker: {
|
|
|
|
id: 18,
|
|
|
|
userFk: 18,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
id: 1,
|
|
|
|
originFk: 1,
|
|
|
|
userFk: 18,
|
|
|
|
action: 'update',
|
|
|
|
changedModel: 'Claim',
|
|
|
|
oldInstance: {
|
2024-04-04 12:12:16 +00:00
|
|
|
pickup: null,
|
2023-10-04 13:46:15 +00:00
|
|
|
},
|
|
|
|
newInstance: {
|
2024-04-04 12:12:16 +00:00
|
|
|
pickup: 'agency',
|
2023-10-04 13:46:15 +00:00
|
|
|
},
|
|
|
|
creationDate: '2023-09-18T12:25:34.000Z',
|
|
|
|
changedModelId: '1',
|
|
|
|
changedModelValue: null,
|
|
|
|
description: null,
|
|
|
|
user: {
|
|
|
|
id: 18,
|
|
|
|
name: 'salesPerson',
|
|
|
|
nickname: 'salesPersonNick',
|
|
|
|
image: '4fa3ada0-3ac4-11eb-9ab8-27f6fc3b85fd',
|
|
|
|
worker: {
|
|
|
|
id: 18,
|
|
|
|
userFk: 18,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
];
|
2023-09-29 13:03:02 +00:00
|
|
|
const mockValidations = {
|
|
|
|
Claim: {
|
|
|
|
locale: {
|
|
|
|
name: 'reclamación',
|
|
|
|
},
|
2023-09-26 09:49:57 +00:00
|
|
|
},
|
2023-09-29 13:03:02 +00:00
|
|
|
ClaimObservation: {
|
|
|
|
locale: {
|
|
|
|
name: 'observación',
|
|
|
|
},
|
2023-09-26 09:49:57 +00:00
|
|
|
},
|
2023-09-29 13:03:02 +00:00
|
|
|
ClaimDms: {
|
|
|
|
locale: {
|
|
|
|
name: 'documento',
|
|
|
|
},
|
2023-09-26 09:49:57 +00:00
|
|
|
},
|
2023-09-29 13:03:02 +00:00
|
|
|
ClaimBeginning: {
|
|
|
|
locale: {
|
|
|
|
name: 'comienzo',
|
|
|
|
},
|
2023-09-26 09:49:57 +00:00
|
|
|
},
|
2023-09-29 13:03:02 +00:00
|
|
|
};
|
2023-09-26 09:49:57 +00:00
|
|
|
|
2023-10-04 13:46:15 +00:00
|
|
|
beforeAll(async () => {
|
|
|
|
axios.get.mockImplementation(() => {
|
|
|
|
return { data: fakeLogTreeData };
|
|
|
|
});
|
|
|
|
|
2023-04-18 12:43:18 +00:00
|
|
|
vm = createWrapper(VnLog, {
|
2023-04-20 06:25:06 +00:00
|
|
|
global: {
|
2023-09-26 09:49:57 +00:00
|
|
|
stubs: [],
|
|
|
|
mocks: {},
|
2023-04-20 06:25:06 +00:00
|
|
|
},
|
2023-04-18 12:43:18 +00:00
|
|
|
propsData: {
|
2023-09-26 09:49:57 +00:00
|
|
|
model: 'Claim',
|
2023-04-18 12:43:18 +00:00
|
|
|
},
|
|
|
|
}).vm;
|
2023-09-29 13:03:02 +00:00
|
|
|
vm.validations = mockValidations;
|
2023-04-18 12:43:18 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
vi.clearAllMocks();
|
|
|
|
});
|
|
|
|
|
2023-09-26 09:49:57 +00:00
|
|
|
it('should correctly set logTree', async () => {
|
2023-12-13 13:36:01 +00:00
|
|
|
vm.logTree = vm.getLogTree(fakeLogTreeData);
|
2023-09-26 09:49:57 +00:00
|
|
|
expect(vm.logTree[0].originFk).toEqual(1);
|
|
|
|
expect(vm.logTree[0].logs[0].user.name).toEqual('salesPerson');
|
2023-04-18 12:43:18 +00:00
|
|
|
});
|
|
|
|
|
2023-10-04 13:46:15 +00:00
|
|
|
it('should correctly set the selectedFilters when filtering', () => {
|
2023-09-26 09:49:57 +00:00
|
|
|
vm.searchInput = '1';
|
|
|
|
vm.userSelect = '21';
|
|
|
|
vm.checkboxOptions.insert.selected = true;
|
|
|
|
vm.checkboxOptions.update.selected = true;
|
2023-04-18 12:43:18 +00:00
|
|
|
|
2023-09-26 09:49:57 +00:00
|
|
|
vm.selectFilter('search');
|
|
|
|
vm.selectFilter('userSelect');
|
2023-04-18 12:43:18 +00:00
|
|
|
|
2023-09-26 09:49:57 +00:00
|
|
|
expect(vm.selectedFilters.changedModelId).toEqual('1');
|
|
|
|
expect(vm.selectedFilters.userFk).toEqual('21');
|
|
|
|
expect(vm.selectedFilters.action).toEqual({ inq: ['insert', 'update'] });
|
|
|
|
});
|
2023-04-18 12:43:18 +00:00
|
|
|
|
2023-09-29 13:03:02 +00:00
|
|
|
it('should correctly set the date from', () => {
|
2023-10-04 13:46:15 +00:00
|
|
|
vm.dateFrom = '18-09-2023';
|
2023-09-26 09:49:57 +00:00
|
|
|
vm.selectFilter('date', 'from');
|
2023-10-04 13:46:15 +00:00
|
|
|
expect(vm.selectedFilters.creationDate.between).toEqual([
|
|
|
|
new Date('2023-09-18T00:00:00.000Z'),
|
|
|
|
new Date('2023-09-18T21:59:59.999Z'),
|
|
|
|
]);
|
2023-09-29 13:03:02 +00:00
|
|
|
});
|
2023-04-18 12:43:18 +00:00
|
|
|
});
|