test: refs #7058 getRoutes

This commit is contained in:
Javier Segarra 2025-01-03 15:48:53 +01:00
parent e5940ff785
commit 42f113ccf6
1 changed files with 43 additions and 1 deletions

View File

@ -132,6 +132,48 @@ function mount(source) {
return wrapper;
}
describe('getRoutes', () => {
afterEach(() => vi.clearAllMocks());
const getRoutes = vi.fn().mockImplementation((props, getMethodA, getMethodB) => {
const handleRoutes = {
methodA: getMethodA,
methodB: getMethodB,
};
try {
handleRoutes[props.source]();
} catch (error) {
throw Error('Method not defined');
}
});
const getMethodA = vi.fn();
const getMethodB = vi.fn();
const fn = (props) => getRoutes(props, getMethodA, getMethodB);
it('should call getMethodB when source is card', () => {
let props = { source: 'methodB' };
fn(props);
expect(getMethodB).toHaveBeenCalled();
expect(getMethodA).not.toHaveBeenCalled();
});
it('should call getMethodA when source is main', () => {
let props = { source: 'methodA' };
fn(props);
expect(getMethodA).toHaveBeenCalled();
expect(getMethodB).not.toHaveBeenCalled();
});
//WIP
it('should call getMethodA when source is main', () => {
let props = { source: 'methodC' };
expect(fn(props)).toThrowError('Method not defined');
expect(getMethodA).not.toHaveBeenCalled();
expect(getMethodB).not.toHaveBeenCalled();
});
});
describe('Leftmenu as card', () => {
beforeAll(() => {
vm = mount('card').vm;
@ -335,7 +377,7 @@ describe.only('addChildren', () => {
expect(useNavigationStore().addMenuItem).toHaveBeenCalled();
});
it.only('should not add menu items if no matches are found', () => {
it('should not add menu items if no matches are found', () => {
const module = 'testModule';
const route = {
meta: { menu: 'child3', menuChildren: [] },