0
0
Fork 0

resf #5673 test(claimDevelopment): front test

This commit is contained in:
Alex Moreno 2023-08-25 10:56:03 +02:00
parent a09b4ff548
commit 6260b7ed5e
6 changed files with 27 additions and 33 deletions

View File

@ -16,7 +16,7 @@ import ClaimLinesImport from './ClaimLinesImport.vue';
const quasar = useQuasar();
const route = useRoute();
const { t } = useI18n();
console.log(t);
const stateStore = useStateStore();
const arrayData = useArrayData('ClaimLines');
const store = arrayData.store;

View File

@ -20,7 +20,7 @@ const $props = defineProps({
});
const entityId = computed(() => $props.id || route.params.id);
let wagonTypes;
let wagonTypes = [];
let originalData = {};
const wagon = ref({});
const filteredWagonTypes = ref(wagonTypes);

View File

@ -1,7 +1,6 @@
import { createWrapper, axios } from 'app/test/vitest/helper';
import CrudModel from 'components/CrudModel.vue';
import { vi, afterEach, beforeAll, beforeEach, describe, expect, it } from 'vitest';
import { onMounted, ref } from 'vue';
import { vi, afterEach, beforeAll, describe, expect, it } from 'vitest';
describe.only('CrudModel', () => {
let vm;
@ -13,7 +12,7 @@ describe.only('CrudModel', () => {
'useState',
'arrayData',
'useStateStore',
'useValidator',
'vue-i18n',
],
mocks: {
fetch: vi.fn(),
@ -27,6 +26,7 @@ describe.only('CrudModel', () => {
autoLoad: true,
},
dataKey: 'crudModelKey',
model: 'crudModel',
url: 'crudModelUrl',
},
attrs: {
@ -44,15 +44,14 @@ describe.only('CrudModel', () => {
describe('insert()', () => {
it('should new element in list with index 0 if formData not has data', () => {
// vi.spyOn(axios, 'get').mockResolvedValue({
// data: [
// { id: 1, name: 'Tony Stark' },
// { id: 2, name: 'Jessica Jones' },
// { id: 3, name: 'Bruce Wayne' },
// ],
// });
// vm.state.set('crudModel', []);
vm.formData = ref([]);
vi.spyOn(axios, 'get').mockResolvedValue({
data: [
{ id: 1, name: 'Tony Stark' },
{ id: 2, name: 'Jessica Jones' },
{ id: 3, name: 'Bruce Wayne' },
],
});
vm.state.set('crudModel', []);
vm.insert();

View File

@ -14,9 +14,6 @@ describe('ClaimLines', () => {
},
},
}).vm;
vi.mock('src/composables/useValidator', () => ({
fetch: () => vi.fn(),
}));
});
beforeEach(() => {

View File

@ -7,9 +7,11 @@ describe('WagonCreate', () => {
const entityId = 1;
beforeAll(() => {
vmEdit = createWrapper(WagonCreate, {propsData: {
vmEdit = createWrapper(WagonCreate, {
propsData: {
id: entityId,
}}).vm;
},
}).vm;
vmCreate = createWrapper(WagonCreate).vm;
});
@ -29,9 +31,7 @@ describe('WagonCreate', () => {
await vmCreate.onSubmit();
expect(axios.patch).toHaveBeenCalledWith(
`Wagons`, vmCreate.wagon
);
expect(axios.patch).toHaveBeenCalledWith(`Wagons`, vmCreate.wagon);
});
it('should update a wagon', async () => {
@ -46,9 +46,7 @@ describe('WagonCreate', () => {
await vmEdit.onSubmit();
expect(axios.patch).toHaveBeenCalledWith(
`Wagons`, vmEdit.wagon
);
expect(axios.patch).toHaveBeenCalledWith(`Wagons`, vmEdit.wagon);
});
});
@ -88,16 +86,12 @@ describe('WagonCreate', () => {
describe('fetch()', () => {
it('should fetch data', async () => {
vi.spyOn(axios, 'get').mockResolvedValue({ data: true });
vi.spyOn(axios, 'get').mockResolvedValue({ data: [] });
await vmEdit.fetch();
expect(axios.get).toHaveBeenCalledWith(
`WagonTypes`
);
expect(axios.get).toHaveBeenCalledWith(
`Wagons/${entityId}`
);
expect(axios.get).toHaveBeenCalledWith(`WagonTypes`);
expect(axios.get).toHaveBeenCalledWith(`Wagons/${entityId}`);
});
});
});

View File

@ -5,6 +5,7 @@ import { vi } from 'vitest';
import { i18n } from 'src/boot/i18n';
import { Notify, Dialog } from 'quasar';
import axios from 'axios';
import * as useValidator from 'src/composables/useValidator';
installQuasarPlugin({
plugins: {
@ -34,6 +35,10 @@ vi.mock('vue-router', () => ({
}),
}));
vi.spyOn(useValidator, 'useValidator').mockImplementation(() => {
return { validate: vi.fn(), fetch: vi.fn() };
});
class FormDataMock {
append() {
vi.fn();
@ -79,7 +84,6 @@ export function createWrapper(component, options) {
mountOptions.global.plugins = defaultOptions.global.plugins;
}
}
console.log(mountOptions);
const wrapper = mount(component, mountOptions);
const vm = wrapper.vm;