Compare commits

..

5 Commits

Author SHA1 Message Date
Jose Antonio Tubau 9c6e41d2ae Merge branch 'dev' into 8380-createTestToVnImg
gitea/salix-front/pipeline/pr-dev This commit looks good Details
2025-01-20 13:49:54 +00:00
Jose Antonio Tubau 6f8b04a3ed Merge branch '8380-createTestToVnImg' of https://gitea.verdnatura.es/verdnatura/salix-front into 8380-createTestToVnImg
gitea/salix-front/pipeline/pr-dev This commit looks good Details
2025-01-20 14:47:06 +01:00
Jose Antonio Tubau 096f0c57ba refactor: refs #8380 remove unnecessary stubs in VnImg test wrapper 2025-01-20 14:47:04 +01:00
Jose Antonio Tubau 3305bb4222 Merge branch 'dev' into 8380-createTestToVnImg
gitea/salix-front/pipeline/pr-dev This commit looks good Details
2025-01-17 10:33:08 +00:00
Jose Antonio Tubau e884bab1ea test: refs #8380 add unit tests for VnImg component
gitea/salix-front/pipeline/pr-dev This commit looks good Details
2025-01-15 06:56:15 +01:00
2 changed files with 90 additions and 3 deletions

View File

@ -0,0 +1,89 @@
import { vi, describe, expect, it, beforeEach, afterEach } from 'vitest';
import { createWrapper } from 'app/test/vitest/helper';
import VnImg from 'src/components/ui/VnImg.vue';
let wrapper;
let vm;
const isEmployeeMock = vi.fn();
function generateWrapper(storage = 'images') {
wrapper = createWrapper(VnImg, {
props: {
id: 123,
zoomResolution: '400x400',
storage,
}
});
wrapper = wrapper.wrapper;
vm = wrapper.vm;
vm.timeStamp = 'timestamp';
};
vi.mock('src/composables/useSession', () => ({
useSession: () => ({
getTokenMultimedia: () => 'token',
}),
}));
vi.mock('src/composables/useRole', () => ({
useRole: () => ({
isEmployee: isEmployeeMock,
}),
}));
describe('VnImg', () => {
beforeEach(() => {
isEmployeeMock.mockReset();
});
afterEach(() => {
vi.clearAllMocks();
});
describe('getUrl', () => {
it('should return /api/{storage}/{id}/downloadFile?access_token={token} when storage is dms', async () => {
isEmployeeMock.mockReturnValue(false);
generateWrapper('dms');
await vm.$nextTick();
const url = vm.getUrl();
expect(url).toBe('/api/dms/123/downloadFile?access_token=token');
});
it('should return /no-user.png when role is not employee and storage is not dms', async () => {
isEmployeeMock.mockReturnValue(false);
generateWrapper();
await vm.$nextTick();
const url = vm.getUrl();
expect(url).toBe('/no-user.png');
});
it('should return /api/{storage}/{collection}/{curResolution}/{id}/download?access_token={token}&{timeStamp} when zoom is false and role is employee and storage is not dms', async () => {
isEmployeeMock.mockReturnValue(true);
generateWrapper();
await vm.$nextTick();
const url = vm.getUrl();
expect(url).toBe('/api/images/catalog/200x200/123/download?access_token=token&timestamp');
});
it('should return /api/{storage}/{collection}/{curResolution}/{id}/download?access_token={token}&{timeStamp} when zoom is true and role is employee and storage is not dms', async () => {
isEmployeeMock.mockReturnValue(true);
generateWrapper();
await vm.$nextTick();
const url = vm.getUrl(true);
expect(url).toBe('/api/images/catalog/400x400/123/download?access_token=token&timestamp');
});
});
describe('reload', () => {
it('should update the timestamp', async () => {
generateWrapper();
const initialTimestamp = wrapper.vm.timeStamp;
wrapper.vm.reload();
const newTimestamp = wrapper.vm.timeStamp;
expect(initialTimestamp).not.toEqual(newTimestamp);
});
});
});

View File

@ -7,9 +7,7 @@ import { isDialogOpened } from 'src/filters';
const arrayDataStore = useArrayDataStore(); const arrayDataStore = useArrayDataStore();
export function useArrayData(key, userOptions) { export function useArrayData(key = useRoute().meta.moduleName, userOptions) {
key ??= useRoute().meta.moduleName;
if (!key) throw new Error('ArrayData: A key is required to use this composable'); if (!key) throw new Error('ArrayData: A key is required to use this composable');
if (!arrayDataStore.get(key)) arrayDataStore.set(key); if (!arrayDataStore.get(key)) arrayDataStore.set(key);