2024-10-18 09:03:43 +00:00
|
|
|
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' };
|
|
|
|
|
|
|
|
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();
|
|
|
|
});
|
|
|
|
|
2024-10-18 09:06:06 +00:00
|
|
|
it('should add and remove query', async () => {
|
2024-10-21 10:04:20 +00:00
|
|
|
const secondQuery = { ...firstQuery };
|
|
|
|
const thirdQuery = { ...firstQuery };
|
|
|
|
|
2024-10-18 09:03:43 +00:00
|
|
|
add(firstQuery);
|
|
|
|
add(secondQuery);
|
|
|
|
|
|
|
|
const beforeCount = getQueries().size;
|
2024-10-18 09:06:06 +00:00
|
|
|
add(thirdQuery);
|
|
|
|
expect(getQueries().has(thirdQuery)).toBeTruthy();
|
2024-10-18 09:03:43 +00:00
|
|
|
|
2024-10-18 09:06:06 +00:00
|
|
|
remove(thirdQuery);
|
|
|
|
expect(getQueries().has(thirdQuery)).toBeFalsy();
|
2024-10-18 09:03:43 +00:00
|
|
|
expect(getQueries().size).toBe(beforeCount);
|
|
|
|
});
|
|
|
|
});
|