forked from verdnatura/salix-front
test(arrayData) add front test
This commit is contained in:
parent
92cac607e4
commit
40842f4ba6
|
@ -1,10 +1,13 @@
|
|||
import { describe, expect, it, beforeAll, afterEach, vi } from 'vitest';
|
||||
import { describe, expect, it, beforeEach, afterEach, vi } from 'vitest';
|
||||
import { axios, flushPromises } from 'app/test/vitest/helper';
|
||||
import { useArrayData } from 'composables/useArrayData';
|
||||
import { useRouter } from 'vue-router';
|
||||
import * as vueRouter from 'vue-router';
|
||||
|
||||
describe('useArrayData', () => {
|
||||
beforeAll(() => {
|
||||
const filter = '{"order":"","limit":10,"skip":0}';
|
||||
const params = { supplierFk: 2 };
|
||||
beforeEach(() => {
|
||||
vi.spyOn(useRouter(), 'replace');
|
||||
vi.spyOn(useRouter(), 'push');
|
||||
});
|
||||
|
@ -18,8 +21,6 @@ describe('useArrayData', () => {
|
|||
|
||||
const arrayData = useArrayData('ArrayData', { url: 'mockUrl' });
|
||||
|
||||
const filter = '{"order":"","limit":10,"skip":0}';
|
||||
const params = { supplierFk: 2 };
|
||||
arrayData.store.userParams = params;
|
||||
arrayData.fetch({});
|
||||
|
||||
|
@ -41,8 +42,6 @@ describe('useArrayData', () => {
|
|||
|
||||
const arrayData = useArrayData('ArrayData', { url: 'mockUrl', navigate: {} });
|
||||
|
||||
const filter = '{"order":"","limit":10,"skip":0}';
|
||||
const params = { supplierFk: 2 };
|
||||
arrayData.store.userParams = params;
|
||||
arrayData.fetch({});
|
||||
|
||||
|
@ -57,25 +56,43 @@ describe('useArrayData', () => {
|
|||
expect(routerPush.query).toBeUndefined();
|
||||
});
|
||||
|
||||
// it('Should get data and send new URL keeping parameters, if you have more than one record', async () => {
|
||||
// vi.spyOn(axios, 'get').mockReturnValueOnce({ data: [{ id: 1 }, { id: 2 }] });
|
||||
it('Should get data and send new URL keeping parameters, if you have more than one record', async () => {
|
||||
vi.spyOn(axios, 'get').mockReturnValueOnce({ data: [{ id: 1 }, { id: 2 }] });
|
||||
|
||||
// const arrayData = useArrayData('ArrayData', { url: 'mockUrl', navigate: {} });
|
||||
vi.spyOn(vueRouter, 'useRoute').mockReturnValue({
|
||||
matched: [],
|
||||
query: {},
|
||||
params: {},
|
||||
meta: { moduleName: 'mockName' },
|
||||
path: 'mockName/1',
|
||||
});
|
||||
vi.spyOn(vueRouter, 'useRouter').mockReturnValue({
|
||||
push: vi.fn(),
|
||||
replace: vi.fn(),
|
||||
currentRoute: {
|
||||
value: {
|
||||
params: {
|
||||
id: 1,
|
||||
},
|
||||
meta: { moduleName: 'mockName' },
|
||||
matched: [{ path: 'mockName/:id' }],
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
// const filter = '{"order":"","limit":10,"skip":0}';
|
||||
// const params = { supplierFk: 2 };
|
||||
// arrayData.store.userParams = params;
|
||||
// arrayData.fetch({});
|
||||
const arrayData = useArrayData('ArrayData', { url: 'mockUrl', navigate: {} });
|
||||
|
||||
// await flushPromises();
|
||||
// const routerPush = useRouter().push.mock.calls[0][0];
|
||||
// console.log('routerPush: ', routerPush);
|
||||
arrayData.store.userParams = params;
|
||||
arrayData.fetch({});
|
||||
|
||||
// expect(axios.get.mock.calls[0][1].params).toEqual({
|
||||
// filter,
|
||||
// supplierFk: 2,
|
||||
// });
|
||||
// expect(routerPush.path).toEqual('mockName/1');
|
||||
// expect(routerPush.query).toBeUndefined();
|
||||
// });
|
||||
await flushPromises();
|
||||
const routerPush = useRouter().push.mock.calls[0][0];
|
||||
|
||||
expect(axios.get.mock.calls[0][1].params).toEqual({
|
||||
filter,
|
||||
supplierFk: 2,
|
||||
});
|
||||
expect(routerPush.path).toEqual('mockName/');
|
||||
expect(routerPush.query.params).toBeDefined();
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue