Compare commits

..

No commits in common. "update_vitest_version" and "dev" have entirely different histories.

40 changed files with 2423 additions and 1378 deletions

View File

@ -40,8 +40,6 @@
"validator": "^13.9.0",
"vue": "^3.5.13",
"vue-i18n": "^9.4.0",
"@eslint/eslintrc": "^3.2.0",
"@eslint/js": "^9.20.0",
"vue-router": "^4.2.5"
},
"devDependencies": {
@ -61,7 +59,6 @@
"cypress-mochawesome-reporter": "^3.8.2",
"eslint": "^9.18.0",
"eslint-config-prettier": "^10.0.1",
"eslint-import-resolver-alias": "^1.1.2",
"eslint-plugin-cypress": "^4.1.0",
"eslint-plugin-import": "^2.31.0",
"eslint-plugin-vue": "^9.32.0",
@ -72,7 +69,8 @@
"postcss": "^8.4.23",
"prettier": "^3.4.2",
"sass": "^1.83.4",
"vitest": "^3.0.3",
"vitepress": "^1.6.3",
"vitest": "^0.34.0",
"xunit-viewer": "^10.6.1"
},
"engines": {

File diff suppressed because it is too large Load Diff

View File

@ -1,227 +0,0 @@
/* eslint-disable */
/**
* THIS FILE IS GENERATED AUTOMATICALLY.
* 1. DO NOT edit this file directly as it won't do anything.
* 2. EDIT the original quasar.config file INSTEAD.
* 3. DO NOT git commit this file. It should be ignored.
*
* This file is still here because there was an error in
* the original quasar.config file and this allows you to
* investigate the Node.js stack error.
*
* After you fix the original file, this file will be
* deleted automatically.
**/
// quasar.config.js
import { configure } from "quasar/wrappers";
import VueI18nPlugin from "@intlify/unplugin-vue-i18n/vite";
import path from "path";
var __quasar_inject_dirname__ = "/home/jsegarra/Projects/salix-front";
var target = `http://${process.env.CI ? "back" : "localhost"}:3000`;
var quasar_config_default = configure(function() {
return {
eslint: {
// fix: true,
// include = [],
// exclude = [],
// rawOptions = {},
warnings: true,
errors: true
},
// https://v2.quasar.dev/quasar-cli/prefetch-feature
// preFetch: true,
// app boot file (/src/boot)
// --> boot files are part of "main.js"
// https://v2.quasar.dev/quasar-cli/boot-files
boot: ["i18n", "axios", "vnDate", "validations", "quasar", "quasar.defaults"],
// https://v2.quasar.dev/quasar-cli-vite/quasar-config-js#css
css: ["app.scss"],
// https://github.com/quasarframework/quasar/tree/dev/extras
extras: [
// 'ionicons-v4',
// 'mdi-v5',
// 'fontawesome-v6',
// 'eva-icons',
// 'themify',
// 'line-awesome',
// 'roboto-font-latin-ext', // this or either 'roboto-font', NEVER both!
"roboto-font",
"material-icons-outlined",
"material-symbols-outlined"
],
// Full list of options: https://v2.quasar.dev/quasar-cli-vite/quasar-config-js#build
build: {
target: {
browser: ["es2022", "edge88", "firefox78", "chrome87", "safari13.1"],
node: "node20"
},
vueRouterMode: "hash",
// available values: 'hash', 'history'
// vueRouterBase,
// vueDevtools,
// vueOptionsAPI: false,
// rebuildCache: true, // rebuilds Vite/linter/etc cache on startup
// publicPath: '/',
// analyze: true,
// env: {},
rawDefine: {
"process.env.NODE_ENV": JSON.stringify(process.env.NODE_ENV)
},
// ignorePublicFolder: true,
// minify: false,
// polyfillModulePreload: true,
// distDir
extendViteConf(viteConf) {
delete viteConf.build.polyfillModulePreload;
viteConf.build.modulePreload = {
polyfill: false
};
},
// viteVuePluginOptions: {},
alias: {
composables: path.join(__quasar_inject_dirname__, "./src/composables"),
filters: path.join(__quasar_inject_dirname__, "./src/filters")
},
vitePlugins: [
[
VueI18nPlugin({
strictMessage: false,
runtimeOnly: false,
include: [
path.resolve(__quasar_inject_dirname__, "./src/i18n/locale/**"),
path.resolve(__quasar_inject_dirname__, "./src/pages/**/locale/**")
]
})
]
]
},
// Full list of options: https://v2.quasar.dev/quasar-cli-vite/quasar-config-js#devServer
devServer: {
server: {
type: "http"
},
proxy: {
"/api": {
target,
logLevel: "debug",
changeOrigin: true,
secure: false
}
},
open: false,
allowedHosts: [
"front",
// Agrega este nombre de host
"localhost"
// Opcional, para pruebas locales
]
},
// https://v2.quasar.dev/quasar-cli-vite/quasar-config-js#framework
framework: {
config: {
config: {
dark: "auto"
}
},
lang: "en-GB",
// iconSet: 'material-icons', // Quasar icon set
// lang: 'en-US', // Quasar language pack
// For special cases outside of where the auto-import strategy can have an impact
// (like functional components as one of the examples),
// you can manually specify Quasar components/directives to be available everywhere:
//
// components: [],
// directives: [],
// Quasar plugins
plugins: ["Notify", "Dialog"],
all: "auto",
autoImportComponentCase: "pascal"
},
// animations: 'all', // --- includes all animations
// https://v2.quasar.dev/options/animations
animations: [],
// https://v2.quasar.dev/quasar-cli-vite/quasar-config-js#property-sourcefiles
// sourceFiles: {
// rootComponent: 'src/App.vue',
// router: 'src/router/index',
// store: 'src/store/index',
// registerServiceWorker: 'src-pwa/register-service-worker',
// serviceWorker: 'src-pwa/custom-service-worker',
// pwaManifestFile: 'src-pwa/manifest.json',
// electronMain: 'src-electron/electron-main',
// electronPreload: 'src-electron/electron-preload'
// },
// https://v2.quasar.dev/quasar-cli/developing-ssr/configuring-ssr
ssr: {
// ssrPwaHtmlFilename: 'offline.html', // do NOT use index.html as name!
// will mess up SSR
// extendSSRWebserverConf (esbuildConf) {},
// extendPackageJson (json) {},
pwa: false,
// manualStoreHydration: true,
// manualPostHydrationTrigger: true,
prodPort: 3e3,
// The default port that the production server should use
// (gets superseded if process.env.PORT is specified at runtime)
middlewares: [
"render"
// keep this as last one
]
},
// https://v2.quasar.dev/quasar-cli/developing-pwa/configuring-pwa
pwa: {
workboxMode: "generateSW",
// or 'injectManifest'
injectPwaMetaTags: true,
swFilename: "sw.js",
manifestFilename: "manifest.json",
useCredentialsForManifestTag: false
// useFilenameHashes: true,
// extendGenerateSWOptions (cfg) {}
// extendInjectManifestOptions (cfg) {},
// extendManifestJson (json) {}
// extendPWACustomSWConf (esbuildConf) {}
},
// Full list of options: https://v2.quasar.dev/quasar-cli/developing-cordova-apps/configuring-cordova
cordova: {
// noIosLegacyBuildFlag: true, // uncomment only if you know what you are doing
},
// Full list of options: https://v2.quasar.dev/quasar-cli/developing-capacitor-apps/configuring-capacitor
capacitor: {
hideSplashscreen: true
},
// Full list of options: https://v2.quasar.dev/quasar-cli/developing-electron-apps/configuring-electron
electron: {
// extendElectronMainConf (esbuildConf)
// extendElectronPreloadConf (esbuildConf)
inspectPort: 5858,
bundler: "packager",
// 'packager' or 'builder'
packager: {
// https://github.com/electron-userland/electron-packager/blob/master/docs/api.md#options
// OS X / Mac App Store
// appBundleId: '',
// appCategoryType: '',
// osxSign: '',
// protocol: 'myapp://path',
// Windows only
// win32metadata: { ... }
},
builder: {
// https://www.electron.build/configuration/configuration
appId: "salix-frontend"
}
},
// Full list of options: https://v2.quasar.dev/quasar-cli-vite/developing-browser-extensions/configuring-bex
bex: {
contentScripts: ["my-content-script"]
// extendBexScriptsConf (esbuildConf) {}
// extendBexManifestJson (json) {}
}
};
});
export {
quasar_config_default as default
};

View File

@ -9,30 +9,6 @@ vi.mock('src/composables/useSession', () => ({
}),
}));
// Mock axios
vi.mock('axios', () => ({
default: {
create: vi.fn(() => ({
interceptors: {
request: { use: vi.fn() },
response: { use: vi.fn() },
},
})),
interceptors: {
request: { use: vi.fn() },
response: { use: vi.fn() },
},
defaults: {
baseURL: '',
},
},
}));
vi.mock('src/router', () => ({
Router: {
push: vi.fn(),
},
}));
vi.mock('src/stores/useStateQueryStore', () => ({
useStateQueryStore: () => ({
add: () => vi.fn(),
@ -53,7 +29,7 @@ describe('Axios boot', () => {
'Accept-Language': 'en-US',
Authorization: 'DEFAULT_TOKEN',
},
}),
})
);
});
});

View File

@ -1,7 +1,8 @@
import { describe, expect, it, beforeEach, afterEach, vi } from 'vitest';
import { createWrapper } from 'app/test/vitest/helper';
import VnVisibleColumn from '../VnVisibleColumn.vue';
import { default as axios } from 'axios';
import { axios } from 'app/test/vitest/helper';
describe('VnVisibleColumns', () => {
let wrapper;
let vm;

View File

@ -1,6 +1,4 @@
import { createWrapper } from 'app/test/vitest/helper';
import { default as axios } from 'axios';
import { createWrapper, axios } from 'app/test/vitest/helper';
import CrudModel from 'components/CrudModel.vue';
import { vi, afterEach, beforeEach, beforeAll, describe, expect, it } from 'vitest';

View File

@ -1,5 +1,4 @@
import { createWrapper } from 'app/test/vitest/helper';
import { default as axios } from 'axios';
import { createWrapper, axios } from 'app/test/vitest/helper';
import EditForm from 'components/EditTableCellValueForm.vue';
import { vi, afterEach, beforeAll, describe, expect, it } from 'vitest';

View File

@ -1,6 +1,4 @@
import { createWrapper } from 'app/test/vitest/helper';
import { default as axios } from 'axios';
import { createWrapper, axios } from 'app/test/vitest/helper';
import FilterItemForm from 'src/components/FilterItemForm.vue';
import { vi, beforeAll, describe, expect, it } from 'vitest';
@ -40,9 +38,9 @@ describe('FilterItemForm', () => {
{ relation: 'producer', scope: { fields: ['name'] } },
{ relation: 'ink', scope: { fields: ['name'] } },
],
where: { name: { like: '%bolas de madera%' } },
where: {"name":{"like":"%bolas de madera%"}},
};
expect(axios.get).toHaveBeenCalledWith('Items/withName', {
params: { filter: JSON.stringify(expectedFilter) },
});
@ -81,4 +79,4 @@ describe('FilterItemForm', () => {
vm.selectItem({ id: 12345 });
expect(wrapper.emitted('itemSelected')[0]).toEqual([12345]);
});
});
});

View File

@ -1,7 +1,5 @@
import { describe, expect, it, beforeAll, vi, afterAll } from 'vitest';
import { createWrapper } from 'app/test/vitest/helper';
import { default as axios } from 'axios';
import { createWrapper, axios } from 'app/test/vitest/helper';
import FormModel from 'src/components/FormModel.vue';
describe('FormModel', () => {

View File

@ -1,7 +1,6 @@
import { vi, describe, expect, it, beforeAll, afterEach, beforeEach } from 'vitest';
import { default as axios } from 'axios';
import { createWrapper } from 'app/test/vitest/helper';
import LeftMenu from 'components/LeftMenu.vue';
import { vi, describe, expect, it, beforeAll, beforeEach, afterEach } from 'vitest';
import { createWrapper, axios } from 'app/test/vitest/helper';
import Leftmenu from 'components/LeftMenu.vue';
import * as vueRouter from 'vue-router';
import { useNavigationStore } from 'src/stores/useNavigationStore';
@ -102,7 +101,7 @@ function mount(source = 'main') {
vi.spyOn(axios, 'get').mockResolvedValue({
data: [],
});
const wrapper = createWrapper(LeftMenu, {
const wrapper = createWrapper(Leftmenu, {
propsData: {
source,
},
@ -165,7 +164,7 @@ describe('getRoutes', () => {
});
});
describe('LeftMenu as card', () => {
describe('Leftmenu as card', () => {
beforeAll(() => {
vm = mount('card').vm;
});
@ -174,7 +173,7 @@ describe('LeftMenu as card', () => {
vm.getRoutes();
});
});
describe('LeftMenu as main', () => {
describe('Leftmenu as main', () => {
beforeEach(() => {
vm = mount().vm;
});

View File

@ -1,5 +1,4 @@
import axios from 'axios';
import { createWrapper } from 'app/test/vitest/helper';
import { createWrapper, axios } from 'app/test/vitest/helper';
import VnChangePassword from 'src/components/common/VnChangePassword.vue';
import { vi, beforeEach, afterEach, beforeAll, describe, expect, it } from 'vitest';
import { Notify } from 'quasar';

View File

@ -1,5 +1,4 @@
import { createWrapper } from 'app/test/vitest/helper';
import { default as axios } from 'axios';
import { createWrapper, axios } from 'app/test/vitest/helper';
import { vi, afterEach, beforeEach, beforeAll, describe, expect, it } from 'vitest';
import VnDms from 'src/components/common/VnDms.vue';
@ -41,10 +40,7 @@ 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 = {
@ -63,7 +59,7 @@ describe('VnDms', () => {
url: '/test',
formInitialData: { id: 1, reference: 'test' },
model: 'Worker',
},
}
});
wrapper = wrapper.wrapper;
vm = wrapper.vm;
@ -102,7 +98,7 @@ describe('VnDms', () => {
expect(vm.getUrl()).toBe('/test');
});
it('should returns url dms/"props.formInitialData.id"/updateFile when prop url is null', async () => {
it('should returns url dms/"props.formInitialData.id"/updateFile when prop url is null', async () => {
await wrapper.setProps({ url: null });
expect(vm.getUrl()).toBe('dms/1/updateFile');
});
@ -117,9 +113,7 @@ describe('VnDms', () => {
describe('save', () => {
it('should save data correctly', async () => {
await vm.save();
expect(postMock).toHaveBeenCalledWith(vm.getUrl(), expect.any(FormData), {
params: expectedBody,
});
expect(postMock).toHaveBeenCalledWith(vm.getUrl(), expect.any(FormData), { params: expectedBody });
expect(wrapper.emitted('onDataSaved')).toBeTruthy();
});
});
@ -133,8 +127,8 @@ describe('VnDms', () => {
warehouseFk: 2,
companyFk: 3,
dmsTypeFk: 2,
description: 'This is a test description',
};
description: 'This is a test description'
}
await wrapper.setProps({ formInitialData: testData });
vm.defaultData();
@ -143,10 +137,10 @@ describe('VnDms', () => {
it('should add reference with "route.params.id" to dms if formInitialData is null', async () => {
await wrapper.setProps({ formInitialData: null });
vm.route.params.id = '111';
vm.route.params.id= '111';
vm.defaultData();
expect(vm.dms.reference).toBe('111');
});
});
});
});

View File

@ -1,6 +1,4 @@
import { createWrapper } from 'app/test/vitest/helper';
import { default as axios } from 'axios';
import { createWrapper, axios } from 'app/test/vitest/helper';
import VnDmsList from 'src/components/common/VnDmsList.vue';
import { vi, afterEach, beforeAll, describe, expect, it } from 'vitest';

View File

@ -1,6 +1,5 @@
import { vi, describe, expect, it, beforeAll, afterEach } from 'vitest';
import axios from 'axios';
import { createWrapper } from 'app/test/vitest/helper';
import { createWrapper, axios } from 'app/test/vitest/helper';
import VnLog from 'src/components/common/VnLog.vue';
describe('VnLog', () => {

View File

@ -1,6 +1,5 @@
import { describe, it, expect, vi, afterEach, beforeEach, afterAll } from 'vitest';
import { createWrapper } from 'app/test/vitest/helper';
import { default as axios } from 'axios';
import { createWrapper, axios } from 'app/test/vitest/helper';
import VnNotes from 'src/components/ui/VnNotes.vue';
describe('VnNotes', () => {

View File

@ -1,7 +1,5 @@
import { vi, describe, expect, it, beforeAll, afterEach, beforeEach } from 'vitest';
import { createWrapper } from 'app/test/vitest/helper';
import { default as axios } from 'axios';
import { createWrapper, axios } from 'app/test/vitest/helper';
import CardSummary from 'src/components/ui/CardSummary.vue';
import * as vueRouter from 'vue-router';

View File

@ -1,6 +1,5 @@
import { vi, describe, expect, it, beforeAll, afterEach } from 'vitest';
import axios from 'axios';
import { createWrapper } from 'app/test/vitest/helper';
import { createWrapper, axios } from 'app/test/vitest/helper';
import VnPaginate from 'src/components/ui/VnPaginate.vue';
describe('VnPaginate', () => {

View File

@ -1,5 +1,5 @@
import { describe, it, expect, beforeAll, vi } from 'vitest';
import axios from 'axios';
import { axios } from 'app/test/vitest/helper';
import parsePhone from 'src/filters/parsePhone';
describe('parsePhone filter', () => {

View File

@ -1,6 +1,5 @@
import { vi, describe, expect, it, beforeAll, afterEach } from 'vitest';
import axios from 'axios';
import { createWrapper } from 'app/test/vitest/helper';
import { createWrapper, axios } from 'app/test/vitest/helper';
import VnSms from 'src/components/ui/VnSms.vue';
describe('VnSms', () => {

View File

@ -1,5 +1,5 @@
import { vi, describe, expect, it, beforeAll, afterAll } from 'vitest';
import axios from 'axios';
import { axios } from 'app/test/vitest/helper';
import { downloadFile } from 'src/composables/downloadFile';
import { useSession } from 'src/composables/useSession';
const session = useSession();

View File

@ -1,7 +1,5 @@
import { vi, describe, expect, it, beforeAll, afterAll } from 'vitest';
import axios from 'axios';
import { flushPromises } from '@vue/test-utils';
import { axios, flushPromises } from 'app/test/vitest/helper';
import { useAcl } from 'src/composables/useAcl';
describe('useAcl', () => {

View File

@ -1,39 +1,15 @@
import { describe, expect, it, beforeEach, afterEach, vi } from 'vitest';
import { default as axios } from 'axios';
import { axios, flushPromises } from 'app/test/vitest/helper';
import { useArrayData } from 'composables/useArrayData';
import { useRouter } from 'vue-router';
import * as vueRouter from 'vue-router';
import { setActivePinia, createPinia } from 'pinia';
describe('useArrayData', () => {
const filter = '{"limit":20,"skip":0}';
const params = { supplierFk: 2 };
beforeEach(() => {
setActivePinia(createPinia());
// Mock route
vi.spyOn(vueRouter, 'useRoute').mockReturnValue({
path: 'mockSection/list',
matched: [],
query: {},
params: {},
meta: { moduleName: 'mockName' },
});
// Mock router
vi.spyOn(vueRouter, 'useRouter').mockReturnValue({
push: vi.fn(),
replace: vi.fn(),
currentRoute: {
value: {
path: 'mockSection/list',
params: { id: 1 },
meta: { moduleName: 'mockName' },
matched: [{ path: 'mockName/:id' }],
},
},
});
vi.spyOn(useRouter(), 'replace');
vi.spyOn(useRouter(), 'push');
});
afterEach(() => {
@ -41,69 +17,103 @@ describe('useArrayData', () => {
});
it('should fetch and replace url with new params', async () => {
vi.spyOn(axios, 'get').mockResolvedValueOnce({ data: [] });
vi.spyOn(axios, 'get').mockReturnValueOnce({ data: [] });
const arrayData = useArrayData('ArrayData', {
url: 'mockUrl',
searchUrl: 'params',
});
const arrayData = useArrayData('ArrayData', { url: 'mockUrl' });
arrayData.store.userParams = params;
await arrayData.fetch({});
arrayData.fetch({});
await flushPromises();
const routerReplace = useRouter().replace.mock.calls[0][0];
expect(axios.get).toHaveBeenCalledWith('mockUrl', {
signal: expect.any(Object),
params: {
filter,
supplierFk: 2,
},
expect(axios.get.mock.calls[0][1].params).toEqual({
filter,
supplierFk: 2,
});
expect(routerReplace.path).toBe('mockSection/list');
expect(routerReplace.path).toEqual('mockSection/list');
expect(JSON.parse(routerReplace.query.params)).toEqual(
expect.objectContaining(params),
);
});
it('should redirect to detail when single record is returned with navigation', async () => {
vi.spyOn(axios, 'get').mockResolvedValueOnce({
data: [{ id: 1 }],
});
it('should get data and send new URL without keeping parameters, if there is only one record', async () => {
vi.spyOn(axios, 'get').mockReturnValueOnce({ data: [{ id: 1 }] });
const arrayData = useArrayData('ArrayData', {
url: 'mockUrl',
navigate: {},
});
const arrayData = useArrayData('ArrayData', { url: 'mockUrl', navigate: {} });
arrayData.store.userParams = params;
await arrayData.fetch({});
arrayData.fetch({});
await flushPromises();
const routerPush = useRouter().push.mock.calls[0][0];
expect(routerPush.path).toBe('mockName/1');
expect(axios.get.mock.calls[0][1].params).toEqual({
filter,
supplierFk: 2,
});
expect(routerPush.path).toEqual('mockName/1');
expect(routerPush.query).toBeUndefined();
});
it('should return one record when oneRecord is true', async () => {
vi.spyOn(axios, 'get').mockResolvedValueOnce({
it('should get data and send new URL keeping parameters, if you have more than one record', async () => {
vi.spyOn(axios, 'get').mockReturnValueOnce({ data: [{ id: 1 }, { id: 2 }] });
vi.spyOn(vueRouter, 'useRoute').mockReturnValue({
matched: [],
query: {},
params: {},
meta: { moduleName: 'mockName' },
path: 'mockName/1',
});
vi.spyOn(vueRouter, 'useRouter').mockReturnValue({
push: vi.fn(),
replace: vi.fn(),
currentRoute: {
value: {
params: {
id: 1,
},
meta: { moduleName: 'mockName' },
matched: [{ path: 'mockName/:id' }],
},
},
});
const arrayData = useArrayData('ArrayData', { url: 'mockUrl', navigate: {} });
arrayData.store.userParams = params;
arrayData.fetch({});
await flushPromises();
const routerPush = useRouter().push.mock.calls[0][0];
expect(axios.get.mock.calls[0][1].params).toEqual({
filter,
supplierFk: 2,
});
expect(routerPush.path).toEqual('mockName/');
expect(routerPush.query.params).toBeDefined();
});
it('should return one record', async () => {
vi.spyOn(axios, 'get').mockReturnValueOnce({
data: [
{ id: 1, name: 'Entity 1' },
{ id: 2, name: 'Entity 2' },
],
});
const arrayData = useArrayData('ArrayData', {
url: 'mockUrl',
oneRecord: true,
});
const arrayData = useArrayData('ArrayData', { url: 'mockUrl', oneRecord: true });
await arrayData.fetch({});
expect(arrayData.store.data).toEqual({
id: 1,
name: 'Entity 1',
});
expect(arrayData.store.data).toEqual({ id: 1, name: 'Entity 1' });
});
it('should handle empty data gracefully if has to return one record', async () => {
vi.spyOn(axios, 'get').mockReturnValueOnce({ data: [] });
const arrayData = useArrayData('ArrayData', { url: 'mockUrl', oneRecord: true });
await arrayData.fetch({});
expect(arrayData.store.data).toBeUndefined();
});
});

View File

@ -1,6 +1,5 @@
import { vi, describe, expect, it } from 'vitest';
import axios from 'axios';
import { flushPromises } from '@vue/test-utils';
import { axios, flushPromises } from 'app/test/vitest/helper';
import { useRole } from 'composables/useRole';
const role = useRole();

View File

@ -1,5 +1,5 @@
import { vi, describe, expect, it, beforeAll, beforeEach } from 'vitest';
import axios from 'axios';
import { axios } from 'app/test/vitest/helper';
import { useSession } from 'composables/useSession';
import { useState } from 'composables/useState';

View File

@ -1,6 +1,5 @@
import { vi, describe, expect, it } from 'vitest';
import axios from 'axios';
import { flushPromises } from '@vue/test-utils';
import { axios, flushPromises } from 'app/test/vitest/helper';
import { useTokenConfig } from 'composables/useTokenConfig';
const tokenConfig = useTokenConfig();

View File

@ -5,11 +5,12 @@ import { useArrayDataStore } from 'stores/useArrayDataStore';
import { buildFilter } from 'filters/filterPanel';
import { isDialogOpened } from 'src/filters';
const arrayDataStore = useArrayDataStore();
export function useArrayData(key, userOptions) {
key ??= useRoute().meta.moduleName;
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);

View File

@ -60,7 +60,7 @@ export function useSession() {
const { data: isValidToken } = await axios.get('VnUsers/validateToken');
if (isValidToken)
destroyTokenPromises = Object.entries(tokens).map(([key, url]) =>
destroyToken(url, storage, key),
destroyToken(url, storage, key)
);
}
} finally {

View File

@ -1,6 +1,5 @@
import { vi, describe, expect, it, beforeAll, afterEach } from 'vitest';
import axios from 'axios';
import { createWrapper } from 'app/test/vitest/helper';
import { createWrapper, axios } from 'app/test/vitest/helper';
import ClaimDescriptorMenu from 'pages/Claim/Card/ClaimDescriptorMenu.vue';
describe('ClaimDescriptorMenu', () => {

View File

@ -1,6 +1,5 @@
import { vi, describe, expect, it, beforeAll, beforeEach, afterEach } from 'vitest';
import axios from 'axios';
import { createWrapper } from 'app/test/vitest/helper';
import { createWrapper, axios } from 'app/test/vitest/helper';
import ClaimLines from '/src/pages/Claim/Card/ClaimLines.vue';
describe('ClaimLines', () => {

View File

@ -1,6 +1,5 @@
import { vi, describe, expect, it, beforeAll, beforeEach, afterEach } from 'vitest';
import axios from 'axios';
import { createWrapper } from 'app/test/vitest/helper';
import { createWrapper, axios } from 'app/test/vitest/helper';
import ClaimLinesImport from 'pages/Claim/Card/ClaimLinesImport.vue';
describe('ClaimLinesImport', () => {

View File

@ -1,7 +1,7 @@
import { vi, describe, expect, it, beforeAll, afterEach } from 'vitest';
import axios from 'axios';
import { createWrapper } from 'app/test/vitest/helper';
import { createWrapper, axios } from 'app/test/vitest/helper';
import ClaimPhoto from 'pages/Claim/Card/ClaimPhoto.vue';
describe('ClaimPhoto', () => {
let vm;
@ -61,7 +61,7 @@ describe('ClaimPhoto', () => {
title: 'This file will be deleted',
icon: 'delete',
data: { index: 1 },
promise: vm.deleteDms,
promise: vm.deleteDms
},
})
);

View File

@ -1,6 +1,5 @@
import { vi, describe, expect, it, beforeAll, afterEach } from 'vitest';
import axios from 'axios';
import { createWrapper } from 'app/test/vitest/helper';
import { createWrapper, axios } from 'app/test/vitest/helper';
import CustomerPayments from 'src/pages/Customer/Payments/CustomerPayments.vue';
describe('CustomerPayments', () => {

View File

@ -1,7 +1,6 @@
import { vi, describe, expect, it, beforeAll, afterEach } from 'vitest';
import { createWrapper } from 'app/test/vitest/helper';
import { createWrapper, axios } from 'app/test/vitest/helper';
import Login from 'pages/Login/LoginMain.vue';
import axios from 'axios';
describe('Login', () => {
let vm;

View File

@ -1,6 +1,5 @@
import { vi, describe, expect, it, beforeAll, afterEach } from 'vitest';
import axios from 'axios';
import { createWrapper } from 'app/test/vitest/helper';
import { createWrapper, axios } from 'app/test/vitest/helper';
import TicketBoxing from 'pages/Ticket/Card/TicketBoxing.vue';
// #4836 - Investigate how to test q-drawer outside
@ -22,11 +21,7 @@ describe('TicketBoxing', () => {
min: 1,
max: 2,
};
const videoList = [
'2022-01-01T01-01-00.mp4',
'2022-02-02T02-02-00.mp4',
'2022-03-03T03-03-00.mp4',
];
const videoList = ['2022-01-01T01-01-00.mp4', '2022-02-02T02-02-00.mp4', '2022-03-03T03-03-00.mp4'];
vi.spyOn(axios, 'get').mockResolvedValue({ data: videoList });
vi.spyOn(vm.quasar, 'notify');
@ -49,9 +44,7 @@ describe('TicketBoxing', () => {
await vm.getVideoList(expeditionId, timed);
expect(vm.quasar.notify).toHaveBeenCalledWith(
expect.objectContaining({ type: 'negative' })
);
expect(vm.quasar.notify).toHaveBeenCalledWith(expect.objectContaining({ type: 'negative' }));
});
});
});

View File

@ -1,6 +1,5 @@
import { vi, describe, expect, it, beforeAll, afterEach, beforeEach } from 'vitest';
import axios from 'axios';
import { createWrapper } from 'app/test/vitest/helper';
import { createWrapper, axios } from 'app/test/vitest/helper';
import TicketAdvance from 'pages/Ticket/TicketAdvance.vue';
import { Notify } from 'quasar';
import { nextTick } from 'vue';

View File

@ -1,6 +1,5 @@
import { vi, describe, expect, it, beforeAll, afterEach } from 'vitest';
import axios from 'axios';
import { createWrapper } from 'app/test/vitest/helper';
import { createWrapper, axios } from 'app/test/vitest/helper';
import WagonCreate from 'pages/Wagon/WagonCreate.vue';
describe('WagonCreate', () => {

View File

@ -1,95 +0,0 @@
import { describe, expect, it, beforeEach } from 'vitest';
import { setActivePinia, createPinia } from 'pinia';
import { useArrayDataStore } from '../useArrayDataStore';
describe('useArrayDataStore', () => {
beforeEach(() => {
setActivePinia(createPinia());
});
it('should get undefined for non-existent key', () => {
const store = useArrayDataStore();
expect(store.get('nonExistent')).toBeUndefined();
});
it('should set default state for new key', () => {
const store = useArrayDataStore();
store.set('test');
const state = store.get('test');
expect(state).toMatchObject({
filter: {},
userFilter: {},
userParams: {},
url: '',
limit: 20,
skip: 0,
order: '',
isLoading: false,
userParamsChanged: false,
exprBuilder: null,
searchUrl: 'params',
navigate: null,
page: 1,
mapKey: 'id',
oneRecord: false,
});
});
it('should clear state for specific key', () => {
const store = useArrayDataStore();
store.set('test');
store.clear('test');
expect(store.get('test')).toBeUndefined();
});
it('should reset all properties when no options provided', () => {
const store = useArrayDataStore();
store.set('test');
const state = store.get('test');
state.limit = 50;
state.page = 3;
store.reset('test');
expect(store.get('test').limit).toBe(20);
expect(store.get('test').page).toBe(1);
});
it('should reset only specified properties', () => {
const store = useArrayDataStore();
store.set('test');
const state = store.get('test');
state.limit = 50;
state.page = 3;
state.url = 'test-url';
store.reset('test', ['limit', 'page']);
expect(state.limit).toBe(20);
expect(state.page).toBe(1);
expect(state.url).toBe('test-url');
});
it('should reset nested properties', () => {
const store = useArrayDataStore();
store.set('test');
const state = store.get('test');
state.filter.skip = 10;
store.reset('test', ['filter.skip']);
expect(state.filter.skip).toBe(0);
});
it('should reset pagination properties', () => {
const store = useArrayDataStore();
store.set('test');
const state = store.get('test');
state.skip = 20;
state.filter.skip = 20;
state.page = 3;
store.resetPagination('test');
expect(state.skip).toBe(0);
expect(state.filter.skip).toBe(0);
expect(state.page).toBe(1);
});
});

View File

@ -1,17 +1,15 @@
import { setActivePinia, createPinia } from 'pinia';
import { describe, beforeEach, afterEach, it, expect, vi } from 'vitest';
import { describe, beforeEach, afterEach, it, expect, vi, beforeAll } from 'vitest';
import { useNavigationStore } from '../useNavigationStore';
import { default as axios } from 'axios';
import axios from 'axios';
let store;
vi.mock('src/router/modules', () => ({
default: [
{ name: 'Item', meta: {} },
{ name: 'Shelving', meta: {} },
{ name: 'Order', meta: {} },
],
}));
vi.mock('src/router/modules', () => [
{ name: 'Item', meta: {} },
{ name: 'Shelving', meta: {} },
{ name: 'Order', meta: {} },
]);
vi.mock('src/filters', () => ({
toLowerCamel: vi.fn((name) => name.toLowerCase()),

View File

@ -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 axios from 'axios';
import * as useValidator from 'src/composables/useValidator';
installQuasarPlugin({
@ -40,6 +41,8 @@ vi.mock('vue-router', () => ({
onBeforeRouteLeave: () => {},
}));
vi.mock('axios');
vi.spyOn(useValidator, 'useValidator').mockImplementation(() => {
return {
validate: vi.fn(),
@ -109,4 +112,5 @@ export function createWrapper(component, options) {
return { vm, wrapper };
}
export { flushPromises };
export { axios, flushPromises };

View File

@ -1,27 +1 @@
// This file will be run before each test file, don't delete or vitest will not work.
import { vi } from 'vitest';
vi.mock('axios');
vi.mock('vue-router', () => ({
useRouter: () => ({
push: vi.fn(),
replace: vi.fn(),
currentRoute: {
value: {
params: {
id: 1,
},
meta: { moduleName: 'mockName' },
matched: [{ path: 'mockName/list' }],
},
},
}),
useRoute: () => ({
matched: [],
query: {},
params: {},
meta: { moduleName: 'mockName' },
path: 'mockSection/list',
}),
onBeforeRouteLeave: () => {},
}));