#7058 LeftMenu vitest #1153
|
@ -2,10 +2,11 @@ import { vi, describe, expect, it, beforeAll, beforeEach, afterEach } from 'vite
|
||||||
import { createWrapper, axios } from 'app/test/vitest/helper';
|
import { createWrapper, axios } from 'app/test/vitest/helper';
|
||||||
import Leftmenu from 'components/LeftMenu.vue';
|
import Leftmenu from 'components/LeftMenu.vue';
|
||||||
import * as vueRouter from 'vue-router';
|
import * as vueRouter from 'vue-router';
|
||||||
|
|
||||||
import { useNavigationStore } from 'src/stores/useNavigationStore';
|
import { useNavigationStore } from 'src/stores/useNavigationStore';
|
||||||
|
|
||||||
let vm;
|
let vm;
|
||||||
let navigation;
|
let navigation;
|
||||||
|
|
||||||
vi.mock('src/router/modules', () => ({
|
vi.mock('src/router/modules', () => ({
|
||||||
default: [
|
default: [
|
||||||
{
|
{
|
||||||
|
@ -164,7 +165,7 @@ describe('getRoutes', () => {
|
||||||
expect(getMethodA).toHaveBeenCalled();
|
expect(getMethodA).toHaveBeenCalled();
|
||||||
expect(getMethodB).not.toHaveBeenCalled();
|
expect(getMethodB).not.toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
//WIP
|
|
||||||
it('should call getMethodA when source is main', () => {
|
it('should call getMethodA when source is main', () => {
|
||||||
jsegarra marked this conversation as resolved
Outdated
|
|||||||
let props = { source: 'methodC' };
|
let props = { source: 'methodC' };
|
||||||
expect(() => fn(props)).toThrowError('Method not defined');
|
expect(() => fn(props)).toThrowError('Method not defined');
|
||||||
|
@ -184,30 +185,10 @@ describe('Leftmenu as card', () => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
describe('Leftmenu as main', () => {
|
describe('Leftmenu as main', () => {
|
||||||
beforeAll(() => {
|
beforeEach(() => {
|
||||||
vm = mount('main').vm;
|
vm = mount('main').vm;
|
||||||
});
|
});
|
||||||
|
|
||||||
// WIP
|
|
||||||
it.skip('should return a proper formated object with two child items', async () => {
|
|
||||||
const expectedMenuItem = [
|
|
||||||
{
|
|
||||||
children: null,
|
|
||||||
name: 'CustomerList',
|
|
||||||
title: 'globals.pageTitles.list',
|
|
||||||
icon: 'view_list',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
children: null,
|
|
||||||
name: 'CustomerCreate',
|
|
||||||
title: 'globals.pageTitles.createCustomer',
|
|
||||||
icon: 'vn:addperson',
|
|
||||||
},
|
|
||||||
];
|
|
||||||
const firstMenuItem = vm.items[0];
|
|
||||||
expect(firstMenuItem.children).toEqual(expect.arrayContaining(expectedMenuItem));
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should initialize with default props', () => {
|
it('should initialize with default props', () => {
|
||||||
expect(vm.source).toBe('main');
|
expect(vm.source).toBe('main');
|
||||||
});
|
});
|
||||||
|
@ -215,7 +196,6 @@ describe('Leftmenu as main', () => {
|
||||||
it('should filter items based on search input', async () => {
|
it('should filter items based on search input', async () => {
|
||||||
vm.search = 'Rou';
|
vm.search = 'Rou';
|
||||||
jorgep marked this conversation as resolved
Outdated
jorgep
commented
Estaría bien crear un test que devuelva algún resultado, mockea otra para comprobar que solo te va a devolver esa. Estaría bien crear un test que devuelva algún resultado, mockea otra para comprobar que solo te va a devolver esa.
jsegarra
commented
He usado cust para que compruebe customer He usado cust para que compruebe customer
|
|||||||
await vm.$nextTick();
|
await vm.$nextTick();
|
||||||
// expect(vm.filterItems).toHaveBeenCalled();
|
|
||||||
expect(vm.filterItems()).toEqual([]);
|
expect(vm.filterItems()).toEqual([]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -343,7 +323,6 @@ describe('normalize', () => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
// WIP
|
|
||||||
describe('addChildren', () => {
|
describe('addChildren', () => {
|
||||||
jorgep marked this conversation as resolved
Outdated
jorgep
commented
En estos tests, solo veo que compruebes que la función haya sido llamada, no se debería comprobar si navigation ha cambiado? En estos tests, solo veo que compruebes que la función haya sido llamada, no se debería comprobar si navigation ha cambiado?
jorgep
commented
El test no comprueba que se ha añadido el item, solo que la función addMenuItem ha sido llamada. Quitar test y comprobar si se han añadido en los tests de useNavigationStore. El test no comprueba que se ha añadido el item, solo que la función addMenuItem ha sido llamada. Quitar test y comprobar si se han añadido en los tests de useNavigationStore.
|
|||||||
const route = {
|
const route = {
|
||||||
meta: {
|
meta: {
|
||||||
|
@ -378,19 +357,6 @@ describe('addChildren', () => {
|
||||||
expect(useNavigationStore().addMenuItem).toHaveBeenCalled();
|
expect(useNavigationStore().addMenuItem).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
// WIP
|
|
||||||
it.skip('should not add menu items if no matches are found', () => {
|
|
||||||
const module = 'testModule';
|
|
||||||
const route = {
|
|
||||||
meta: { menu: 'child3', menuChildren: [] },
|
|
||||||
children: [{ name: 'child3', meta: { menuChildren: [] } }],
|
|
||||||
};
|
|
||||||
const parent = [];
|
|
||||||
|
|
||||||
vm.addChildren(module, route, parent);
|
|
||||||
expect(useNavigationStore().addMenuItem).toHaveBeenCalled();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should handle routes with no meta menu', () => {
|
it('should handle routes with no meta menu', () => {
|
||||||
const module = 'testModule';
|
const module = 'testModule';
|
||||||
const parent = [];
|
const parent = [];
|
||||||
|
@ -399,19 +365,6 @@ describe('addChildren', () => {
|
||||||
expect(useNavigationStore().addMenuItem).toHaveBeenCalled();
|
expect(useNavigationStore().addMenuItem).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
// WIP
|
|
||||||
it.skip('should handle routes with no matches', () => {
|
|
||||||
const module = 'testModule';
|
|
||||||
const route = {
|
|
||||||
meta: { menu: 'child4' },
|
|
||||||
children: [{ name: 'child4', meta: { menuChildren: [] } }],
|
|
||||||
};
|
|
||||||
const parent = [];
|
|
||||||
|
|
||||||
vm.addChildren(module, route, parent);
|
|
||||||
expect(useNavigationStore().addMenuItem).toHaveBeenCalled();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should handle empty parent array', () => {
|
it('should handle empty parent array', () => {
|
||||||
const module = 'testModule';
|
const module = 'testModule';
|
||||||
const parent = [];
|
const parent = [];
|
||||||
|
|
Loading…
Reference in New Issue
Poner otro nombre, está repetido.
oh vaya
should not call getMethodA when method is undefined por ej.