Merge pull request 'feat: #7087 created CardSummary test' (!1197) from 7087-testCardSummary into dev
gitea/salix-front/pipeline/head This commit looks good
Details
gitea/salix-front/pipeline/head This commit looks good
Details
Reviewed-on: #1197 Reviewed-by: Javier Segarra <jsegarra@verdnatura.es>
This commit is contained in:
commit
4b9453380a
|
@ -2,7 +2,6 @@
|
|||
import { ref, computed, watch, onBeforeMount } from 'vue';
|
||||
import { useRoute } from 'vue-router';
|
||||
import SkeletonSummary from 'components/ui/SkeletonSummary.vue';
|
||||
import VnLv from 'src/components/ui/VnLv.vue';
|
||||
import { useArrayData } from 'src/composables/useArrayData';
|
||||
import { isDialogOpened } from 'src/filters';
|
||||
import VnMoreOptions from './VnMoreOptions.vue';
|
||||
|
|
|
@ -0,0 +1,78 @@
|
|||
import { vi, describe, expect, it, beforeAll, afterEach, beforeEach } from 'vitest';
|
||||
import { createWrapper, axios } from 'app/test/vitest/helper';
|
||||
import CardSummary from 'src/components/ui/CardSummary.vue';
|
||||
import * as vueRouter from 'vue-router';
|
||||
|
||||
describe('CardSummary', () => {
|
||||
let vm;
|
||||
let wrapper;
|
||||
|
||||
beforeAll(() => {
|
||||
vi.spyOn(axios, 'get').mockResolvedValue({ data: [] });
|
||||
});
|
||||
|
||||
vi.spyOn(vueRouter, 'useRoute').mockReturnValue({
|
||||
query: {},
|
||||
params: {},
|
||||
meta: { moduleName: 'mockName' },
|
||||
path: 'mockName/1/summary',
|
||||
name: 'CardSummary',
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
wrapper = createWrapper(CardSummary, {
|
||||
propsData: {
|
||||
dataKey: 'cardSummaryKey',
|
||||
url: 'cardSummaryUrl',
|
||||
filter: 'cardFilter',
|
||||
},
|
||||
});
|
||||
vm = wrapper.vm;
|
||||
wrapper = wrapper.wrapper;
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
vi.clearAllMocks();
|
||||
});
|
||||
|
||||
it('should fetch data correctly', async () => {
|
||||
const fetchSpy = vi
|
||||
.spyOn(vm.arrayData, 'fetch')
|
||||
.mockResolvedValue({ data: [{ id: 1, name: 'Test Entity' }] });
|
||||
await vm.fetch();
|
||||
|
||||
expect(fetchSpy).toHaveBeenCalledWith({ append: false, updateRouter: false });
|
||||
expect(wrapper.emitted('onFetch')).toBeTruthy();
|
||||
expect(vm.isLoading).toBe(false);
|
||||
});
|
||||
|
||||
it('should set correct props to the store', () => {
|
||||
expect(vm.store.url).toEqual('cardSummaryUrl');
|
||||
expect(vm.store.filter).toEqual('cardFilter');
|
||||
});
|
||||
|
||||
it('should compute entity correctly from store data', () => {
|
||||
vm.store.data = [{ id: 1, name: 'Entity 1' }];
|
||||
expect(vm.entity).toEqual({ id: 1, name: 'Entity 1' });
|
||||
});
|
||||
|
||||
it('should handle empty data gracefully', () => {
|
||||
vm.store.data = [];
|
||||
expect(vm.entity).toBeUndefined();
|
||||
});
|
||||
|
||||
it('should respond to prop changes and refetch data', async () => {
|
||||
const newUrl = 'CardSummary/35';
|
||||
const newKey = 'cardSummaryKey/35';
|
||||
const fetchSpy = vi.spyOn(vm.arrayData, 'fetch');
|
||||
await wrapper.setProps({ url: newUrl, filter: { key: newKey } });
|
||||
|
||||
expect(fetchSpy).toHaveBeenCalled();
|
||||
expect(vm.store.url).toBe(newUrl);
|
||||
expect(vm.store.filter).toEqual({ key: newKey });
|
||||
});
|
||||
|
||||
it('should return true if route path ends with /summary' , () => {
|
||||
expect(vm.isSummary).toBe(true);
|
||||
});
|
||||
});
|
Loading…
Reference in New Issue