test: improve test
This commit is contained in:
parent
fd036138e4
commit
d406715a70
|
@ -1,7 +1,7 @@
|
||||||
import { vi, describe, expect, it, beforeAll } from 'vitest';
|
import { vi, describe, expect, it, beforeAll, afterEach, beforeEach } from 'vitest';
|
||||||
import axios from 'axios';
|
import { default as axios } from 'axios';
|
||||||
import { createWrapper } from 'app/test/vitest/helper';
|
import { createWrapper } from 'app/test/vitest/helper';
|
||||||
import Leftmenu from 'components/LeftMenu.vue';
|
import LeftMenu from 'components/LeftMenu.vue';
|
||||||
import * as vueRouter from 'vue-router';
|
import * as vueRouter from 'vue-router';
|
||||||
import { useNavigationStore } from 'src/stores/useNavigationStore';
|
import { useNavigationStore } from 'src/stores/useNavigationStore';
|
||||||
|
|
||||||
|
@ -102,7 +102,7 @@ function mount(source = 'main') {
|
||||||
vi.spyOn(axios, 'get').mockResolvedValue({
|
vi.spyOn(axios, 'get').mockResolvedValue({
|
||||||
data: [],
|
data: [],
|
||||||
});
|
});
|
||||||
const wrapper = createWrapper(Leftmenu, {
|
const wrapper = createWrapper(LeftMenu, {
|
||||||
propsData: {
|
propsData: {
|
||||||
source,
|
source,
|
||||||
},
|
},
|
||||||
|
@ -165,7 +165,7 @@ describe('getRoutes', () => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Leftmenu as card', () => {
|
describe('LeftMenu as card', () => {
|
||||||
beforeAll(() => {
|
beforeAll(() => {
|
||||||
vm = mount('card').vm;
|
vm = mount('card').vm;
|
||||||
});
|
});
|
||||||
|
@ -174,7 +174,7 @@ describe('Leftmenu as card', () => {
|
||||||
vm.getRoutes();
|
vm.getRoutes();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
describe('Leftmenu as main', () => {
|
describe('LeftMenu as main', () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
vm = mount().vm;
|
vm = mount().vm;
|
||||||
});
|
});
|
||||||
|
|
|
@ -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 { vi, afterEach, beforeEach, beforeAll, describe, expect, it } from 'vitest';
|
import { vi, afterEach, beforeEach, beforeAll, describe, expect, it } from 'vitest';
|
||||||
import VnDms from 'src/components/common/VnDms.vue';
|
import VnDms from 'src/components/common/VnDms.vue';
|
||||||
|
|
||||||
|
@ -40,7 +41,10 @@ describe('VnDms', () => {
|
||||||
companyFk: 2,
|
companyFk: 2,
|
||||||
dmsTypeFk: 3,
|
dmsTypeFk: 3,
|
||||||
description: 'This is a test description',
|
description: 'This is a test description',
|
||||||
files: { name: 'example.txt', content: new Blob(['file content'], { type: 'text/plain' })},
|
files: {
|
||||||
|
name: 'example.txt',
|
||||||
|
content: new Blob(['file content'], { type: 'text/plain' }),
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
const expectedBody = {
|
const expectedBody = {
|
||||||
|
@ -59,7 +63,7 @@ describe('VnDms', () => {
|
||||||
url: '/test',
|
url: '/test',
|
||||||
formInitialData: { id: 1, reference: 'test' },
|
formInitialData: { id: 1, reference: 'test' },
|
||||||
model: 'Worker',
|
model: 'Worker',
|
||||||
}
|
},
|
||||||
});
|
});
|
||||||
wrapper = wrapper.wrapper;
|
wrapper = wrapper.wrapper;
|
||||||
vm = wrapper.vm;
|
vm = wrapper.vm;
|
||||||
|
@ -98,7 +102,7 @@ describe('VnDms', () => {
|
||||||
expect(vm.getUrl()).toBe('/test');
|
expect(vm.getUrl()).toBe('/test');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should returns url dms/"props.formInitialData.id"/updateFile when prop url is null', async () => {
|
it('should returns url dms/"props.formInitialData.id"/updateFile when prop url is null', async () => {
|
||||||
await wrapper.setProps({ url: null });
|
await wrapper.setProps({ url: null });
|
||||||
expect(vm.getUrl()).toBe('dms/1/updateFile');
|
expect(vm.getUrl()).toBe('dms/1/updateFile');
|
||||||
});
|
});
|
||||||
|
@ -113,7 +117,9 @@ describe('VnDms', () => {
|
||||||
describe('save', () => {
|
describe('save', () => {
|
||||||
it('should save data correctly', async () => {
|
it('should save data correctly', async () => {
|
||||||
await vm.save();
|
await vm.save();
|
||||||
expect(postMock).toHaveBeenCalledWith(vm.getUrl(), expect.any(FormData), { params: expectedBody });
|
expect(postMock).toHaveBeenCalledWith(vm.getUrl(), expect.any(FormData), {
|
||||||
|
params: expectedBody,
|
||||||
|
});
|
||||||
expect(wrapper.emitted('onDataSaved')).toBeTruthy();
|
expect(wrapper.emitted('onDataSaved')).toBeTruthy();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -127,8 +133,8 @@ describe('VnDms', () => {
|
||||||
warehouseFk: 2,
|
warehouseFk: 2,
|
||||||
companyFk: 3,
|
companyFk: 3,
|
||||||
dmsTypeFk: 2,
|
dmsTypeFk: 2,
|
||||||
description: 'This is a test description'
|
description: 'This is a test description',
|
||||||
}
|
};
|
||||||
await wrapper.setProps({ formInitialData: testData });
|
await wrapper.setProps({ formInitialData: testData });
|
||||||
vm.defaultData();
|
vm.defaultData();
|
||||||
|
|
||||||
|
@ -137,10 +143,10 @@ describe('VnDms', () => {
|
||||||
|
|
||||||
it('should add reference with "route.params.id" to dms if formInitialData is null', async () => {
|
it('should add reference with "route.params.id" to dms if formInitialData is null', async () => {
|
||||||
await wrapper.setProps({ formInitialData: null });
|
await wrapper.setProps({ formInitialData: null });
|
||||||
vm.route.params.id= '111';
|
vm.route.params.id = '111';
|
||||||
vm.defaultData();
|
vm.defaultData();
|
||||||
|
|
||||||
expect(vm.dms.reference).toBe('111');
|
expect(vm.dms.reference).toBe('111');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import { describe, it, expect, vi, afterEach, beforeEach, afterAll } from 'vitest';
|
import { describe, it, expect, vi, afterEach, beforeEach, 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 VnNotes from 'src/components/ui/VnNotes.vue';
|
import VnNotes from 'src/components/ui/VnNotes.vue';
|
||||||
|
|
||||||
describe('VnNotes', () => {
|
describe('VnNotes', () => {
|
||||||
|
|
|
@ -1,15 +1,17 @@
|
||||||
import { setActivePinia, createPinia } from 'pinia';
|
import { setActivePinia, createPinia } from 'pinia';
|
||||||
import { describe, beforeEach, afterEach, it, expect, vi, beforeAll } from 'vitest';
|
import { describe, beforeEach, afterEach, it, expect, vi } from 'vitest';
|
||||||
import { useNavigationStore } from '../useNavigationStore';
|
import { useNavigationStore } from '../useNavigationStore';
|
||||||
import axios from 'axios';
|
import { default as axios } from 'axios';
|
||||||
|
|
||||||
let store;
|
let store;
|
||||||
|
|
||||||
vi.mock('src/router/modules', () => [
|
vi.mock('src/router/modules', () => ({
|
||||||
{ name: 'Item', meta: {} },
|
default: [
|
||||||
{ name: 'Shelving', meta: {} },
|
{ name: 'Item', meta: {} },
|
||||||
{ name: 'Order', meta: {} },
|
{ name: 'Shelving', meta: {} },
|
||||||
]);
|
{ name: 'Order', meta: {} },
|
||||||
|
],
|
||||||
|
}));
|
||||||
|
|
||||||
vi.mock('src/filters', () => ({
|
vi.mock('src/filters', () => ({
|
||||||
toLowerCamel: vi.fn((name) => name.toLowerCase()),
|
toLowerCamel: vi.fn((name) => name.toLowerCase()),
|
||||||
|
|
Loading…
Reference in New Issue