From e884bab1eadb9e3a867d6c2103216da560c430ef Mon Sep 17 00:00:00 2001 From: jtubau Date: Wed, 15 Jan 2025 06:56:15 +0100 Subject: [PATCH 1/4] test: refs #8380 add unit tests for VnImg component --- src/components/ui/__tests__/VnImg.spec.js | 92 +++++++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 src/components/ui/__tests__/VnImg.spec.js diff --git a/src/components/ui/__tests__/VnImg.spec.js b/src/components/ui/__tests__/VnImg.spec.js new file mode 100644 index 000000000..cb97d89f8 --- /dev/null +++ b/src/components/ui/__tests__/VnImg.spec.js @@ -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: { + 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); + }); + }); +}); \ No newline at end of file From 096f0c57ba73829420de4dae1ee4fcf2971232a4 Mon Sep 17 00:00:00 2001 From: jtubau Date: Mon, 20 Jan 2025 14:47:04 +0100 Subject: [PATCH 2/4] refactor: refs #8380 remove unnecessary stubs in VnImg test wrapper --- src/components/ui/__tests__/VnImg.spec.js | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/components/ui/__tests__/VnImg.spec.js b/src/components/ui/__tests__/VnImg.spec.js index cb97d89f8..39dd10775 100644 --- a/src/components/ui/__tests__/VnImg.spec.js +++ b/src/components/ui/__tests__/VnImg.spec.js @@ -8,9 +8,6 @@ const isEmployeeMock = vi.fn(); function generateWrapper(storage = 'images') { wrapper = createWrapper(VnImg, { - global: { - stubs: ['Qimg', 'QDialog'], - }, props: { id: 123, zoomResolution: '400x400', From 21251a51670856194dd820bb55d7d5ae4ec11095 Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Tue, 21 Jan 2025 13:25:45 +0100 Subject: [PATCH 3/4] fix: init --- src/components/UserPanel.vue | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/components/UserPanel.vue b/src/components/UserPanel.vue index a0ef73a1f..110828f55 100644 --- a/src/components/UserPanel.vue +++ b/src/components/UserPanel.vue @@ -22,6 +22,7 @@ const { t, locale } = useI18n(); const { copyText } = useClipboard(); const { notify } = useNotify(); +const langList = import.meta.glob('../../node_modules/quasar/lang/*.js'); const userLocale = computed({ get() { return locale.value; @@ -32,8 +33,7 @@ const userLocale = computed({ value = localeEquivalence[value] ?? value; try { - /* @vite-ignore */ - import(`../../node_modules/quasar/lang/${value}.mjs`).then((lang) => { + langList[`../../node_modules/quasar/lang/${value}.js`]().then((lang) => { Quasar.lang.set(lang.default); }); } catch (error) { From 00cea34ddef406bf937a1202795a2eb90ac436d2 Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Tue, 21 Jan 2025 13:55:20 +0100 Subject: [PATCH 4/4] perf: use util in OutLayout --- src/components/UserPanel.vue | 14 +++++--------- src/layouts/OutLayout.vue | 15 ++++----------- src/utils/quasarLang.js | 12 ++++++++++++ 3 files changed, 21 insertions(+), 20 deletions(-) create mode 100644 src/utils/quasarLang.js diff --git a/src/components/UserPanel.vue b/src/components/UserPanel.vue index 110828f55..5f3266eb2 100644 --- a/src/components/UserPanel.vue +++ b/src/components/UserPanel.vue @@ -1,6 +1,9 @@