0
0
Fork 0

test: add front test

This commit is contained in:
Alex Moreno 2024-09-20 14:14:17 +02:00
parent 0897c6c39c
commit b48cba686e
4 changed files with 51 additions and 2 deletions

View File

@ -19,9 +19,15 @@ export function useStateQuery() {
queries.value.delete(hash); queries.value.delete(hash);
} }
function reset() {
queries.value = new Set();
}
return { return {
add, add,
isLoading, isLoading,
remove, remove,
queries,
reset,
}; };
} }

View File

@ -0,0 +1,42 @@
import { describe, expect, it, beforeEach } from 'vitest';
import { useStateQuery } from 'src/composables/useStateQuery';
describe('useStateQuery', () => {
const { add, isLoading, remove, reset, queries } = useStateQuery();
beforeEach(() => {
reset();
expect(queries.value.size).toBeFalsy();
});
it('should add two queries', async () => {
expect(queries.value.size).toBeFalsy();
const hash = add();
expect(queries.value.size).toBeTruthy();
expect(queries.value.has(hash)).toBeTruthy();
add();
expect(queries.value.size).toBe(2);
});
it('should add and remove loading state', async () => {
expect(isLoading().value).toBeFalsy();
const hash = add();
expect(isLoading().value).toBeTruthy();
remove(hash);
expect(isLoading().value).toBeFalsy();
});
it('should add and remove hash', async () => {
add();
add();
add();
const beforeCount = queries.value.size;
const hash = add();
expect(queries.value.has(hash)).toBeTruthy();
remove(hash);
expect(queries.value.has(hash)).toBeFalsy();
expect(queries.value.size).toBe(beforeCount);
});
});

View File

@ -6,6 +6,7 @@ describe('InvoiceInIntrastat', () => {
let vm; let vm;
beforeAll(() => { beforeAll(() => {
vi.spyOn(axios, 'get').mockResolvedValue({ data: [{}] });
vm = createWrapper(InvoiceInIntrastat, { vm = createWrapper(InvoiceInIntrastat, {
global: { global: {
stubs: ['vnPaginate'], stubs: ['vnPaginate'],
@ -14,7 +15,6 @@ describe('InvoiceInIntrastat', () => {
}, },
}, },
}).vm; }).vm;
vi.spyOn(axios, 'get').mockResolvedValue({ data: [{}] });
}); });
describe('getTotal()', () => { describe('getTotal()', () => {

View File

@ -1,11 +1,12 @@
import { vi, describe, expect, it, beforeAll } from 'vitest'; import { vi, describe, expect, it, beforeAll } from 'vitest';
import { createWrapper } from 'app/test/vitest/helper'; import { createWrapper, axios } from 'app/test/vitest/helper';
import InvoiceInVat from 'src/pages/InvoiceIn/Card/InvoiceInVat.vue'; import InvoiceInVat from 'src/pages/InvoiceIn/Card/InvoiceInVat.vue';
describe('InvoiceInVat', () => { describe('InvoiceInVat', () => {
let vm; let vm;
beforeAll(() => { beforeAll(() => {
vi.spyOn(axios, 'get').mockResolvedValue({ data: [{}] });
vm = createWrapper(InvoiceInVat, { vm = createWrapper(InvoiceInVat, {
global: { global: {
stubs: [], stubs: [],