2023-08-21 13:14:19 +00:00
|
|
|
import { createWrapper, axios } from 'app/test/vitest/helper';
|
2023-08-17 13:32:56 +00:00
|
|
|
import CrudModel from 'components/CrudModel.vue';
|
2023-08-25 08:56:03 +00:00
|
|
|
import { vi, afterEach, beforeAll, describe, expect, it } from 'vitest';
|
2023-08-17 13:32:56 +00:00
|
|
|
|
|
|
|
describe.only('CrudModel', () => {
|
|
|
|
let vm;
|
|
|
|
beforeAll(() => {
|
|
|
|
vm = createWrapper(CrudModel, {
|
|
|
|
global: {
|
2023-08-24 13:05:31 +00:00
|
|
|
stubs: [
|
|
|
|
'vnPaginate',
|
|
|
|
'useState',
|
|
|
|
'arrayData',
|
|
|
|
'useStateStore',
|
2023-08-25 08:56:03 +00:00
|
|
|
'vue-i18n',
|
2023-08-24 13:05:31 +00:00
|
|
|
],
|
2023-08-21 13:14:19 +00:00
|
|
|
mocks: {
|
|
|
|
fetch: vi.fn(),
|
2023-08-24 13:05:31 +00:00
|
|
|
validate: vi.fn(),
|
2023-08-21 13:14:19 +00:00
|
|
|
},
|
2023-08-17 13:32:56 +00:00
|
|
|
},
|
|
|
|
propsData: {
|
|
|
|
dataRequired: {
|
|
|
|
id: 1,
|
|
|
|
name: 'name',
|
|
|
|
autoLoad: true,
|
|
|
|
},
|
2023-08-21 13:14:19 +00:00
|
|
|
dataKey: 'crudModelKey',
|
2023-08-25 08:56:03 +00:00
|
|
|
model: 'crudModel',
|
2023-08-21 13:14:19 +00:00
|
|
|
url: 'crudModelUrl',
|
|
|
|
},
|
|
|
|
attrs: {
|
|
|
|
url: 'crudModelUrl',
|
|
|
|
dataKey: 'CustomerList',
|
|
|
|
order: 'id DESC',
|
|
|
|
limit: 3,
|
2023-08-17 13:32:56 +00:00
|
|
|
},
|
|
|
|
}).vm;
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
vi.clearAllMocks();
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('insert()', () => {
|
2023-08-21 13:14:19 +00:00
|
|
|
it('should new element in list with index 0 if formData not has data', () => {
|
2023-08-25 08:56:03 +00:00
|
|
|
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', []);
|
2023-08-24 13:05:31 +00:00
|
|
|
|
2023-08-17 13:32:56 +00:00
|
|
|
vm.insert();
|
|
|
|
|
2023-08-21 13:14:19 +00:00
|
|
|
expect(vm.formData.length).toEqual(1);
|
|
|
|
expect(vm.formData[0].id).toEqual(1);
|
|
|
|
expect(vm.formData[0].$index).toEqual(0);
|
2023-08-17 13:32:56 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|