test: refs #8380 add unit tests for VnImg component #1218
|
@ -0,0 +1,92 @@
|
||||||
|
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, {
|
||||||
|
global: {
|
||||||
jtubau marked this conversation as resolved
|
|||||||
|
stubs: ['Qimg', 'QDialog'],
|
||||||
|
},
|
||||||
|
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×tamp');
|
||||||
|
});
|
||||||
|
|
||||||
|
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×tamp');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
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);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
Loading…
Reference in New Issue
sin global.stubs me pasa, puedes validarlo?
según leí y si mal no entendí, el global stubs sirve para que no renderice los componentes que se le pasan ahí (en este caso crearía una etiqueta QImg y QDialog sin lógica ) y solo seria para que el test sea mas rápido y evitar cargar componentes secundarios que no tendrían que ver con la prueba.
pega el enlace porfavor
https://chatgpt.com/share/678e3575-4790-8011-ba76-ac45f5d0c96a