Merge branch '8647_fix_warnings' of https: refs #8647//gitea.verdnatura.es/verdnatura/salix-front into 8647_fix_warnings
gitea/salix-front/pipeline/pr-dev This commit is unstable
Details
gitea/salix-front/pipeline/pr-dev This commit is unstable
Details
This commit is contained in:
commit
85fa1543c1
|
@ -67,7 +67,7 @@ describe('Axios boot', () => {
|
|||
};
|
||||
|
||||
const result = onResponseError(error);
|
||||
expect(result).rejects.toEqual(expect.objectContaining(error));
|
||||
await expect(result).rejects.toEqual(expect.objectContaining(error));
|
||||
});
|
||||
|
||||
it('should call to the Notify plugin with a message from the response property', async () => {
|
||||
|
@ -83,7 +83,7 @@ describe('Axios boot', () => {
|
|||
};
|
||||
|
||||
const result = onResponseError(error);
|
||||
expect(result).rejects.toEqual(expect.objectContaining(error));
|
||||
await expect(result).rejects.toEqual(expect.objectContaining(error));
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -61,7 +61,7 @@ const $props = defineProps({
|
|||
default: null,
|
||||
},
|
||||
saveFn: {
|
||||
type: [String, Function],
|
||||
type: Function,
|
||||
default: null,
|
||||
},
|
||||
beforeSaveFn: {
|
||||
|
|
|
@ -99,6 +99,10 @@ const $props = defineProps({
|
|||
type: Function,
|
||||
default: () => {},
|
||||
},
|
||||
preventSubmit: {
|
||||
type: Boolean,
|
||||
default: true,
|
||||
},
|
||||
});
|
||||
const emit = defineEmits(['onFetch', 'onDataSaved']);
|
||||
const modelValue = computed(
|
||||
|
@ -301,7 +305,7 @@ function onBeforeSave(formData, originalData) {
|
|||
);
|
||||
}
|
||||
async function onKeyup(evt) {
|
||||
if (evt.key === 'Enter' && !('prevent-submit' in attrs)) {
|
||||
if (evt.key === 'Enter' && !$props.preventSubmit) {
|
||||
const input = evt.target;
|
||||
if (input.type == 'textarea' && evt.shiftKey) {
|
||||
let { selectionStart, selectionEnd } = input;
|
||||
|
@ -330,6 +334,7 @@ defineExpose({
|
|||
<template>
|
||||
<div class="column items-center full-width">
|
||||
<QForm
|
||||
v-on="$attrs"
|
||||
ref="myForm"
|
||||
v-if="formData"
|
||||
@submit.prevent="save"
|
||||
|
|
|
@ -23,7 +23,7 @@ describe('CrudModel', () => {
|
|||
dataKey: 'crudModelKey',
|
||||
model: 'crudModel',
|
||||
url: 'crudModelUrl',
|
||||
saveFn: '',
|
||||
saveFn: vi.fn(),
|
||||
},
|
||||
});
|
||||
wrapper = wrapper.wrapper;
|
||||
|
@ -225,7 +225,7 @@ describe('CrudModel', () => {
|
|||
expect(vm.isLoading).toBe(false);
|
||||
expect(vm.hasChanges).toBe(false);
|
||||
|
||||
await wrapper.setProps({ saveFn: '' });
|
||||
await wrapper.setProps({ saveFn: null });
|
||||
});
|
||||
|
||||
it("should use default url if there's not saveFn", async () => {
|
||||
|
|
|
@ -152,10 +152,22 @@ const value = computed({
|
|||
},
|
||||
});
|
||||
|
||||
const arrayDataKey =
|
||||
$props.dataKey ??
|
||||
($props.url?.length > 0 ? $props.url : ($attrs.name ?? $attrs.label));
|
||||
|
||||
const arrayData = useArrayData(arrayDataKey, {
|
||||
url: $props.url,
|
||||
searchUrl: false,
|
||||
mapKey: $attrs['map-key'],
|
||||
});
|
||||
|
||||
const computedSortBy = computed(() => {
|
||||
return $props.sortBy || $props.optionLabel + ' ASC';
|
||||
});
|
||||
|
||||
const getVal = (val) => ($props.useLike ? { like: `%${val}%` } : val);
|
||||
|
||||
watch(options, (newValue) => {
|
||||
setOptions(newValue);
|
||||
});
|
||||
|
@ -174,16 +186,6 @@ onMounted(() => {
|
|||
if ($props.focusOnMount) setTimeout(() => vnSelectRef.value.showPopup(), 300);
|
||||
});
|
||||
|
||||
const arrayDataKey =
|
||||
$props.dataKey ??
|
||||
($props.url?.length > 0 ? $props.url : ($attrs.name ?? $attrs.label));
|
||||
|
||||
const arrayData = useArrayData(arrayDataKey, {
|
||||
url: $props.url,
|
||||
searchUrl: false,
|
||||
mapKey: $attrs['map-key'],
|
||||
});
|
||||
|
||||
function findKeyInOptions() {
|
||||
if (!$props.options) return;
|
||||
return filter($props.modelValue, $props.options)?.length;
|
||||
|
@ -287,8 +289,6 @@ function nullishToTrue(value) {
|
|||
return value ?? true;
|
||||
}
|
||||
|
||||
const getVal = (val) => ($props.useLike ? { like: `%${val}%` } : val);
|
||||
|
||||
async function onScroll({ to, direction, from, index }) {
|
||||
const lastIndex = myOptions.value.length - 1;
|
||||
|
||||
|
|
|
@ -41,10 +41,12 @@ describe('VnDms', () => {
|
|||
companyFk: 2,
|
||||
dmsTypeFk: 3,
|
||||
description: 'This is a test description',
|
||||
files: {
|
||||
name: 'example.txt',
|
||||
content: new Blob(['file content'], { type: 'text/plain' }),
|
||||
},
|
||||
files: [
|
||||
{
|
||||
name: 'example.txt',
|
||||
content: new Blob(['file content'], { type: 'text/plain' }),
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
const expectedBody = {
|
||||
|
|
|
@ -90,8 +90,10 @@ describe('VnLog', () => {
|
|||
|
||||
vm = createWrapper(VnLog, {
|
||||
global: {
|
||||
stubs: [],
|
||||
mocks: {},
|
||||
stubs: ['FetchData', 'vue-i18n'],
|
||||
mocks: {
|
||||
fetch: vi.fn(),
|
||||
},
|
||||
},
|
||||
propsData: {
|
||||
model: 'Claim',
|
||||
|
|
|
@ -12,7 +12,7 @@ const props = defineProps({
|
|||
default: '',
|
||||
},
|
||||
filter: {
|
||||
type: [String, Object],
|
||||
type: Object,
|
||||
default: null,
|
||||
},
|
||||
userFilter: {
|
||||
|
|
|
@ -69,7 +69,7 @@ const props = defineProps({
|
|||
default: null,
|
||||
},
|
||||
searchUrl: {
|
||||
type: String,
|
||||
type: [String, Boolean],
|
||||
default: null,
|
||||
},
|
||||
disableInfiniteScroll: {
|
||||
|
|
|
@ -31,7 +31,7 @@ describe('CardSummary', () => {
|
|||
propsData: {
|
||||
dataKey: 'cardSummaryKey',
|
||||
url: 'cardSummaryUrl',
|
||||
filter: 'cardFilter',
|
||||
filter: { key: 'cardFilter' },
|
||||
},
|
||||
});
|
||||
vm = wrapper.vm;
|
||||
|
@ -55,7 +55,7 @@ describe('CardSummary', () => {
|
|||
|
||||
it('should set correct props to the store', () => {
|
||||
expect(vm.store.url).toEqual('cardSummaryUrl');
|
||||
expect(vm.store.filter).toEqual('cardFilter');
|
||||
expect(vm.store.filter).toEqual({ key: 'cardFilter' });
|
||||
});
|
||||
|
||||
it('should respond to prop changes and refetch data', async () => {
|
||||
|
|
|
@ -4,6 +4,8 @@ import { useArrayData } from 'composables/useArrayData';
|
|||
import { useRouter } from 'vue-router';
|
||||
import * as vueRouter from 'vue-router';
|
||||
import { setActivePinia, createPinia } from 'pinia';
|
||||
import { defineComponent, h } from 'vue';
|
||||
import { mount } from '@vue/test-utils';
|
||||
|
||||
describe('useArrayData', () => {
|
||||
const filter = '{"limit":20,"skip":0}';
|
||||
|
@ -43,7 +45,7 @@ describe('useArrayData', () => {
|
|||
it('should fetch and replace url with new params', async () => {
|
||||
vi.spyOn(axios, 'get').mockResolvedValueOnce({ data: [] });
|
||||
|
||||
const arrayData = useArrayData('ArrayData', {
|
||||
const arrayData = mountArrayData('ArrayData', {
|
||||
url: 'mockUrl',
|
||||
searchUrl: 'params',
|
||||
});
|
||||
|
@ -72,7 +74,7 @@ describe('useArrayData', () => {
|
|||
data: [{ id: 1 }],
|
||||
});
|
||||
|
||||
const arrayData = useArrayData('ArrayData', {
|
||||
const arrayData = mountArrayData('ArrayData', {
|
||||
url: 'mockUrl',
|
||||
navigate: {},
|
||||
});
|
||||
|
@ -94,7 +96,7 @@ describe('useArrayData', () => {
|
|||
],
|
||||
});
|
||||
|
||||
const arrayData = useArrayData('ArrayData', {
|
||||
const arrayData = mountArrayData('ArrayData', {
|
||||
url: 'mockUrl',
|
||||
oneRecord: true,
|
||||
});
|
||||
|
@ -107,3 +109,17 @@ describe('useArrayData', () => {
|
|||
});
|
||||
});
|
||||
});
|
||||
|
||||
function mountArrayData(...args) {
|
||||
let arrayData;
|
||||
|
||||
const TestComponent = defineComponent({
|
||||
setup() {
|
||||
arrayData = useArrayData(...args);
|
||||
return () => h('div');
|
||||
},
|
||||
});
|
||||
|
||||
const asd = mount(TestComponent);
|
||||
return arrayData;
|
||||
}
|
||||
|
|
|
@ -64,88 +64,84 @@ describe('session', () => {
|
|||
});
|
||||
});
|
||||
|
||||
describe(
|
||||
'login',
|
||||
() => {
|
||||
const expectedUser = {
|
||||
id: 999,
|
||||
name: `T'Challa`,
|
||||
nickname: 'Black Panther',
|
||||
lang: 'en',
|
||||
userConfig: {
|
||||
darkMode: false,
|
||||
describe('login', () => {
|
||||
const expectedUser = {
|
||||
id: 999,
|
||||
name: `T'Challa`,
|
||||
nickname: 'Black Panther',
|
||||
lang: 'en',
|
||||
userConfig: {
|
||||
darkMode: false,
|
||||
},
|
||||
worker: { department: { departmentFk: 155 } },
|
||||
};
|
||||
const rolesData = [
|
||||
{
|
||||
role: {
|
||||
name: 'salesPerson',
|
||||
},
|
||||
worker: { department: { departmentFk: 155 } },
|
||||
};
|
||||
const rolesData = [
|
||||
{
|
||||
role: {
|
||||
name: 'salesPerson',
|
||||
},
|
||||
},
|
||||
{
|
||||
role: {
|
||||
name: 'admin',
|
||||
},
|
||||
{
|
||||
role: {
|
||||
name: 'admin',
|
||||
},
|
||||
},
|
||||
];
|
||||
beforeEach(() => {
|
||||
vi.spyOn(axios, 'get').mockImplementation((url) => {
|
||||
if (url === 'VnUsers/acls') return Promise.resolve({ data: [] });
|
||||
return Promise.resolve({
|
||||
data: { roles: rolesData, user: expectedUser },
|
||||
});
|
||||
},
|
||||
];
|
||||
beforeEach(() => {
|
||||
vi.spyOn(axios, 'get').mockImplementation((url) => {
|
||||
if (url === 'VnUsers/acls') return Promise.resolve({ data: [] });
|
||||
return Promise.resolve({
|
||||
data: { roles: rolesData, user: expectedUser },
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('should fetch the user roles and then set token in the sessionStorage', async () => {
|
||||
const expectedRoles = ['salesPerson', 'admin'];
|
||||
const expectedToken = 'mySessionToken';
|
||||
const expectedTokenMultimedia = 'mySessionTokenMultimedia';
|
||||
const keepLogin = false;
|
||||
it('should fetch the user roles and then set token in the sessionStorage', async () => {
|
||||
const expectedRoles = ['salesPerson', 'admin'];
|
||||
const expectedToken = 'mySessionToken';
|
||||
const expectedTokenMultimedia = 'mySessionTokenMultimedia';
|
||||
const keepLogin = false;
|
||||
|
||||
await session.login({
|
||||
token: expectedToken,
|
||||
tokenMultimedia: expectedTokenMultimedia,
|
||||
keepLogin,
|
||||
});
|
||||
|
||||
const roles = state.getRoles();
|
||||
const localToken = localStorage.getItem('token');
|
||||
const sessionToken = sessionStorage.getItem('token');
|
||||
|
||||
expect(roles.value).toEqual(expectedRoles);
|
||||
expect(localToken).toBeNull();
|
||||
expect(sessionToken).toEqual(expectedToken);
|
||||
|
||||
await session.destroy(); // this clears token and user for any other test
|
||||
await session.login({
|
||||
token: expectedToken,
|
||||
tokenMultimedia: expectedTokenMultimedia,
|
||||
keepLogin,
|
||||
});
|
||||
|
||||
it('should fetch the user roles and then set token in the localStorage', async () => {
|
||||
const expectedRoles = ['salesPerson', 'admin'];
|
||||
const expectedToken = 'myLocalToken';
|
||||
const expectedTokenMultimedia = 'myLocalTokenMultimedia';
|
||||
const keepLogin = true;
|
||||
const roles = state.getRoles();
|
||||
const localToken = localStorage.getItem('token');
|
||||
const sessionToken = sessionStorage.getItem('token');
|
||||
|
||||
await session.login({
|
||||
token: expectedToken,
|
||||
tokenMultimedia: expectedTokenMultimedia,
|
||||
keepLogin,
|
||||
});
|
||||
expect(roles.value).toEqual(expectedRoles);
|
||||
expect(localToken).toBeNull();
|
||||
expect(sessionToken).toEqual(expectedToken);
|
||||
|
||||
const roles = state.getRoles();
|
||||
const localToken = localStorage.getItem('token');
|
||||
const sessionToken = sessionStorage.getItem('token');
|
||||
await session.destroy(); // this clears token and user for any other test
|
||||
});
|
||||
|
||||
expect(roles.value).toEqual(expectedRoles);
|
||||
expect(localToken).toEqual(expectedToken);
|
||||
expect(sessionToken).toBeNull();
|
||||
it('should fetch the user roles and then set token in the localStorage', async () => {
|
||||
const expectedRoles = ['salesPerson', 'admin'];
|
||||
const expectedToken = 'myLocalToken';
|
||||
const expectedTokenMultimedia = 'myLocalTokenMultimedia';
|
||||
const keepLogin = true;
|
||||
|
||||
await session.destroy(); // this clears token and user for any other test
|
||||
await session.login({
|
||||
token: expectedToken,
|
||||
tokenMultimedia: expectedTokenMultimedia,
|
||||
keepLogin,
|
||||
});
|
||||
},
|
||||
{},
|
||||
);
|
||||
|
||||
const roles = state.getRoles();
|
||||
const localToken = localStorage.getItem('token');
|
||||
const sessionToken = sessionStorage.getItem('token');
|
||||
|
||||
expect(roles.value).toEqual(expectedRoles);
|
||||
expect(localToken).toEqual(expectedToken);
|
||||
expect(sessionToken).toBeNull();
|
||||
|
||||
await session.destroy(); // this clears token and user for any other test
|
||||
});
|
||||
});
|
||||
|
||||
describe('RenewToken', () => {
|
||||
const expectedToken = 'myToken';
|
||||
|
|
|
@ -6,26 +6,37 @@ import { buildFilter } from 'filters/filterPanel';
|
|||
import { isDialogOpened } from 'src/filters';
|
||||
|
||||
export function useArrayData(key, userOptions) {
|
||||
key ??= useRoute().meta.moduleName;
|
||||
let route = null;
|
||||
let router = null;
|
||||
|
||||
// Si no hay key, intentamos obtenerla del route
|
||||
if (!key) {
|
||||
key = initialRoute?.meta?.moduleName;
|
||||
route = initialRoute;
|
||||
router = initialRouter;
|
||||
}
|
||||
if (!key) throw new Error('ArrayData: A key is required to use this composable');
|
||||
const arrayDataStore = useArrayDataStore(); // Move inside function
|
||||
|
||||
if (!arrayDataStore.get(key)) arrayDataStore.set(key);
|
||||
|
||||
const store = arrayDataStore.get(key);
|
||||
const route = useRoute();
|
||||
const router = useRouter();
|
||||
let canceller = null;
|
||||
|
||||
const { route: initialRoute, router: initialRouter } = (() => {
|
||||
if (!route) route = useRoute();
|
||||
if (!router) router = useRouter();
|
||||
return { route, router };
|
||||
})();
|
||||
onMounted(() => {
|
||||
setOptions();
|
||||
reset(['skip']);
|
||||
|
||||
const query = route.query;
|
||||
route = initialRoute;
|
||||
router = initialRouter;
|
||||
const searchUrl = store.searchUrl;
|
||||
if (query[searchUrl]) {
|
||||
const params = JSON.parse(query[searchUrl]);
|
||||
const query = route.query[searchUrl];
|
||||
if (query) {
|
||||
const params = JSON.parse(query);
|
||||
const filter =
|
||||
params?.filter && typeof params?.filter == 'object'
|
||||
? params?.filter
|
||||
|
|
|
@ -4,6 +4,7 @@ import { createTestingPinia } from '@pinia/testing';
|
|||
import { vi } from 'vitest';
|
||||
import { i18n } from 'src/boot/i18n';
|
||||
import { Notify, Dialog } from 'quasar';
|
||||
import keyShortcut from 'src/boot/keyShortcut';
|
||||
import * as useValidator from 'src/composables/useValidator';
|
||||
|
||||
installQuasarPlugin({
|
||||
|
@ -26,8 +27,16 @@ vi.mock('vue', async (importOriginal) => {
|
|||
}
|
||||
return actual.inject(key);
|
||||
}),
|
||||
onMounted: vi.fn((fn) => (fn && typeof fn === 'function' ? fn() : undefined)),
|
||||
onBeforeMount: vi.fn((fn) => (fn && typeof fn === 'function' ? fn() : undefined)),
|
||||
onUpdated: vi.fn((fn) => (fn && typeof fn === 'function' ? fn() : undefined)),
|
||||
onUnmounted: vi.fn((fn) => (fn && typeof fn === 'function' ? fn() : undefined)),
|
||||
onBeforeUnmount: vi.fn((fn) =>
|
||||
fn && typeof fn === 'function' ? fn() : undefined,
|
||||
),
|
||||
};
|
||||
});
|
||||
|
||||
vi.mock('vue-router', () => ({
|
||||
useRouter: () => ({
|
||||
push: mockPush,
|
||||
|
|
|
@ -1,5 +1,26 @@
|
|||
// This file will be run before each test file, don't delete or vitest will not work.
|
||||
import { vi } from 'vitest';
|
||||
import { afterAll, beforeAll, vi } from 'vitest';
|
||||
|
||||
let vueWarnings = [];
|
||||
|
||||
const originalConsoleWarn = console.warn;
|
||||
|
||||
beforeAll(() => {
|
||||
console.warn = (...args) => {
|
||||
vueWarnings.push(args.join(' '));
|
||||
};
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
if (vueWarnings.length > 0) {
|
||||
const allWarnings = vueWarnings.join('\n');
|
||||
vueWarnings = [];
|
||||
throw new Error(`Vue warnings detected during test:\n${allWarnings}`);
|
||||
}
|
||||
});
|
||||
|
||||
afterAll(() => {
|
||||
console.warn = originalConsoleWarn;
|
||||
});
|
||||
|
||||
vi.mock('axios');
|
||||
vi.mock('vue-router', () => ({
|
||||
|
|
Loading…
Reference in New Issue