test: refs #7058 getRoutes
This commit is contained in:
parent
4618ba87fa
commit
94c9e1e84a
|
@ -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 () => {
|
||||
const expectedMenuItem = [
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue