#7058 LeftMenu vitest #1153

Merged
jsegarra merged 26 commits from 7058_leftMenu_vitest into dev 2025-02-06 21:45:16 +00:00
1 changed files with 33 additions and 27 deletions
Showing only changes of commit 94c9e1e84a - Show all commits

View File

@ -1,4 +1,4 @@
import { vi, describe, expect, it, beforeAll, beforeEach } from 'vitest';
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';
@ -72,6 +72,38 @@ function mount(source) {
return wrapper;
}
describe('getRoutes', () => {
afterEach(() => vi.clearAllMocks());
const getRoutes = vi
.fn()
.mockImplementation((props, getMainRoutes, getCardRoutes) => {
const handleRoutes = {
main: getMainRoutes,
card: getCardRoutes,
};
console.log(props.source);
handleRoutes[props.source]();
});
const getMainRoutes = vi.fn();
const getCardRoutes = vi.fn();
it('should call getCardRoutes when source is card', () => {
let props = { source: 'card' };
getRoutes(props, getMainRoutes, getCardRoutes);
expect(getCardRoutes).toHaveBeenCalled();
expect(getMainRoutes).not.toHaveBeenCalled();
});
it('should call getMainRoutes when source is main', () => {
let props = { source: 'main' };
getRoutes(props, getMainRoutes, getCardRoutes);
expect(getMainRoutes).toHaveBeenCalled();
expect(getCardRoutes).not.toHaveBeenCalled();
});
});
describe('Leftmenu as card', () => {
beforeAll(() => {
vi.spyOn(vueRouter, 'useRoute').mockReturnValue({
@ -133,33 +165,7 @@ describe('Leftmenu as main', () => {
beforeAll(() => {
vm = mount('main').vm;
});
// WIP
it.skip('should call getMainRoutes when source is main', () => {
vm.getRoutes = vi
.fn()
.mockImplementation((props, getMainRoutes, getCardRoutes) => {
const handleRoutes = {
main: getMainRoutes,
card: getCardRoutes,
};
console.log(props.source);
handleRoutes[props.source]();
});
let props = { source: 'main' };
const getMainRoutes = vi.fn();
const getCardRoutes = vi.fn();
vm.getRoutes(props, getMainRoutes, getCardRoutes);
expect(getMainRoutes).toHaveBeenCalled();
expect(getCardRoutes).not.toHaveBeenCalled();
props = { source: 'card' };
vm.getRoutes(props, getMainRoutes, getCardRoutes);
expect(getCardRoutes).toHaveBeenCalled();
expect(getMainRoutes).not.toHaveBeenCalled();
});
it('should return a proper formated object with two child items', async () => {
jsegarra marked this conversation as resolved Outdated

Poner otro nombre, está repetido.

Poner otro nombre, está repetido.

oh vaya

oh vaya

should not call getMethodA when method is undefined por ej.

should not call getMethodA when method is undefined por ej.
const expectedMenuItem = [
{