57 lines
1.6 KiB
JavaScript
57 lines
1.6 KiB
JavaScript
|
import { describe, expect, it, beforeEach, beforeAll } from 'vitest';
|
||
|
import { createWrapper } from 'app/test/vitest/helper';
|
||
|
|
||
|
import { useStateQueryStore } from 'src/stores/useStateQueryStore';
|
||
|
|
||
|
describe('useStateQueryStore', () => {
|
||
|
beforeAll(() => {
|
||
|
createWrapper({}, {});
|
||
|
});
|
||
|
|
||
|
const stateQueryStore = useStateQueryStore();
|
||
|
const { add, isLoading, remove, reset } = useStateQueryStore();
|
||
|
const firstQuery = { url: 'myQuery' };
|
||
|
const secondQuery = { url: 'myQuery' };
|
||
|
|
||
|
function getQueries() {
|
||
|
return stateQueryStore.queries;
|
||
|
}
|
||
|
|
||
|
beforeEach(() => {
|
||
|
reset();
|
||
|
expect(getQueries().size).toBeFalsy();
|
||
|
});
|
||
|
|
||
|
it('should add two queries', async () => {
|
||
|
expect(getQueries().size).toBeFalsy();
|
||
|
add(firstQuery);
|
||
|
|
||
|
expect(getQueries().size).toBeTruthy();
|
||
|
expect(getQueries().has(firstQuery)).toBeTruthy();
|
||
|
|
||
|
add();
|
||
|
expect(getQueries().size).toBe(2);
|
||
|
});
|
||
|
|
||
|
it('should add and remove loading state', async () => {
|
||
|
expect(isLoading().value).toBeFalsy();
|
||
|
add(firstQuery);
|
||
|
expect(isLoading().value).toBeTruthy();
|
||
|
remove(firstQuery);
|
||
|
expect(isLoading().value).toBeFalsy();
|
||
|
});
|
||
|
|
||
|
it('should add and remove hash', async () => {
|
||
|
add(firstQuery);
|
||
|
add(secondQuery);
|
||
|
|
||
|
const beforeCount = getQueries().size;
|
||
|
const hash = add();
|
||
|
expect(getQueries().has(hash)).toBeTruthy();
|
||
|
|
||
|
remove(hash);
|
||
|
expect(getQueries().has(hash)).toBeFalsy();
|
||
|
expect(getQueries().size).toBe(beforeCount);
|
||
|
});
|
||
|
});
|