Merge branch 'dev' into 7065-testUserPanel
gitea/salix-front/pipeline/pr-dev This commit looks good Details

This commit is contained in:
PAU ROVIRA ROSALENY 2025-01-21 13:37:15 +00:00
commit faf1d15283
6 changed files with 145 additions and 25 deletions

View File

@ -1,6 +1,9 @@
<script setup> <script setup>
import quasarLang from 'src/utils/quasarLang';
import { onMounted, computed, ref } from 'vue'; import { onMounted, computed, ref } from 'vue';
import { Dark, Quasar } from 'quasar';
import { Dark } from 'quasar';
import { useI18n } from 'vue-i18n'; import { useI18n } from 'vue-i18n';
import { useRouter } from 'vue-router'; import { useRouter } from 'vue-router';
import axios from 'axios'; import axios from 'axios';
@ -31,14 +34,7 @@ const userLocale = computed({
value = localeEquivalence[value] ?? value; value = localeEquivalence[value] ?? value;
try { quasarLang(value);
/* @vite-ignore */
import(`../../node_modules/quasar/lang/${value}.mjs`).then((lang) => {
Quasar.lang.set(lang.default);
});
} catch (error) {
//
}
}, },
}); });

View File

@ -0,0 +1,121 @@
import { describe, expect, it, beforeEach, afterEach, vi } from 'vitest';
import { createWrapper } from 'app/test/vitest/helper';
import VnVisibleColumn from '../VnVisibleColumn.vue';
import { axios } from 'app/test/vitest/helper';
describe('VnVisibleColumns', () => {
let wrapper;
let vm;
beforeEach(() => {
wrapper = createWrapper(VnVisibleColumn, {
propsData: {
tableCode: 'testTable',
skip: ['skippedColumn'],
},
});
vm = wrapper.vm;
});
afterEach(() => {
vi.clearAllMocks();
});
describe('setUserConfigViewData()', () => {
it('should initialize localColumns with visible configuration', () => {
vm.columns = [
{ name: 'columnMockName', label: undefined },
{ name: 'columnMockAddress', label: undefined },
{ name: 'columnMockId', label: undefined },
];
const configuration = {
columnMockName: true,
columnMockAddress: false,
columnMockId: true,
};
const expectedColumns = [
{ name: 'columnMockName', label: undefined, visible: true },
{ name: 'columnMockAddress', label: undefined, visible: false },
{ name: 'columnMockId', label: undefined, visible: true },
];
vm.setUserConfigViewData(configuration, false);
expect(vm.localColumns).toEqual(expectedColumns);
});
it('should skip columns based on props', () => {
vm.columns = [
{ name: 'columnMockName', label: undefined },
{ name: 'columnMockId', label: undefined },
{ name: 'skippedColumn', label: 'Skipped Column' },
];
const configuration = {
columnMockName: true,
skippedColumn: false,
columnMockId: true,
};
const expectedColumns = [
{ name: 'columnMockName', label: undefined, visible: true },
{ name: 'columnMockId', label: undefined, visible: true },
];
vm.setUserConfigViewData(configuration, false);
expect(vm.localColumns).toEqual(expectedColumns);
});
});
describe('toggleMarkAll()', () => {
it('should set all localColumns to visible=true', () => {
vm.localColumns = [
{ name: 'columnMockName', visible: false },
{ name: 'columnMockId', visible: false },
];
vm.toggleMarkAll(true);
expect(vm.localColumns.every((col) => col.visible)).toBe(true);
});
it('should set all localColumns to visible=false', () => {
vm.localColumns = [
{ name: 'columnMockName', visible: true },
{ name: 'columnMockId', visible: true },
];
vm.toggleMarkAll(false);
expect(vm.localColumns.every((col) => col.visible)).toBe(false);
});
});
describe('saveConfig()', () => {
it('should call setUserConfigViewData and axios.post with correct params', async () => {
const mockAxiosPost = vi.spyOn(axios, 'post').mockResolvedValue({
data: [{ id: 1 }],
});
vm.localColumns = [
{ name: 'columnMockName', visible: true },
{ name: 'columnMockId', visible: false },
];
await vm.saveConfig();
expect(mockAxiosPost).toHaveBeenCalledWith('UserConfigViews/crud', {
creates: [
{
userFk: vm.user.id,
tableCode: vm.tableCode,
tableConfig: vm.tableCode,
configuration: {
columnMockName: true,
columnMockId: false,
},
},
],
});
});
});
});

View File

@ -70,9 +70,6 @@ const handleModelValue = (data) => {
<VnSelectDialog <VnSelectDialog
v-model="modelValue" v-model="modelValue"
option-filter-value="search" option-filter-value="search"
:option-label="
(opt) => (typeof modelValue === 'string' ? modelValue : showLabel(opt))
"
url="Postcodes/filter" url="Postcodes/filter"
@update:model-value="handleModelValue" @update:model-value="handleModelValue"
:use-like="false" :use-like="false"

View File

@ -55,7 +55,7 @@ const url = computed(() => {
sort-by="nickname ASC" sort-by="nickname ASC"
> >
<template #prepend v-if="$props.hasAvatar"> <template #prepend v-if="$props.hasAvatar">
<VnAvatar :worker-id="value" color="primary" :title="title" /> <VnAvatar :worker-id="value" color="primary" v-bind="$attrs" />
</template> </template>
<template #append v-if="$props.hasInfo"> <template #append v-if="$props.hasInfo">
<QIcon name="info" class="cursor-pointer"> <QIcon name="info" class="cursor-pointer">
@ -72,7 +72,8 @@ const url = computed(() => {
{{ scope.opt.nickname }} {{ scope.opt.nickname }}
</QItemLabel> </QItemLabel>
<QItemLabel caption v-else> <QItemLabel caption v-else>
#{{ scope.opt.id }}, {{ scope.opt.nickname }}, {{ scope.opt.code }} #{{ scope.opt.id }}, {{ scope.opt.nickname }},
{{ scope.opt.code }}
</QItemLabel> </QItemLabel>
</QItemSection> </QItemSection>
</QItem> </QItem>

View File

@ -2,6 +2,8 @@
import { Dark, Quasar } from 'quasar'; import { Dark, Quasar } from 'quasar';
import { computed } from 'vue'; import { computed } from 'vue';
import { useI18n } from 'vue-i18n'; import { useI18n } from 'vue-i18n';
import { localeEquivalence } from 'src/i18n/index';
import quasarLang from 'src/utils/quasarLang';
const { t, locale } = useI18n(); const { t, locale } = useI18n();
@ -12,18 +14,9 @@ const userLocale = computed({
set(value) { set(value) {
locale.value = value; locale.value = value;
if (value === 'en') value = 'en-GB'; value = localeEquivalence[value] ?? value;
// FIXME: Dynamic imports from absolute paths are not compatible with vite: quasarLang(value);
// https://github.com/rollup/plugins/tree/master/packages/dynamic-import-vars#limitations
try {
const langList = import.meta.glob('../../node_modules/quasar/lang/*.mjs');
langList[`../../node_modules/quasar/lang/${value}.mjs`]().then((lang) => {
Quasar.lang.set(lang.default);
});
} catch (error) {
//
}
}, },
}); });

12
src/utils/quasarLang.js Normal file
View File

@ -0,0 +1,12 @@
const langList = import.meta.glob('../../node_modules/quasar/lang/*.js');
import { Quasar } from 'quasar';
export default function (value) {
try {
langList[`../../node_modules/quasar/lang/${value}.js`]().then((lang) => {
Quasar.lang.set(lang.default);
});
} catch (error) {
//
}
}