Skip to content

Commit

Permalink
test: adding getAppRoutes test
Browse files Browse the repository at this point in the history
  • Loading branch information
davidjoy committed Dec 13, 2024
1 parent 3251c22 commit a111d6a
Showing 1 changed file with 59 additions and 0 deletions.
59 changes: 59 additions & 0 deletions shell/router/getAppRoutes.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import { RouteObject } from 'react-router';
import { getConfig } from '../../runtime';
import getAppRoutes from './getAppRoutes';

jest.mock('../../runtime', () => ({
getConfig: jest.fn(),
}));

describe('getAppRoutes', () => {
it('should return an empty array when no apps are configured', () => {
(getConfig as jest.Mock).mockReturnValue({ apps: [] });

const routes = getAppRoutes();

expect(routes).toEqual([]);
});

it('should flatten and return routes from configured apps', () => {
const mockApps = [
{
routes: [
{ path: '/page1', element: <div>Page 1</div> },
{ path: '/page2', element: <div>Page 2</div> }
]
},
{
routes: [
{ path: '/page3', element: <div>Page 3</div> }
]
},
];

(getConfig as jest.Mock).mockReturnValue({ apps: mockApps });

const routes = getAppRoutes();

expect(routes).toEqual([
{ path: '/page1', element: <div>Page 1</div> },
{ path: '/page2', element: <div>Page 2</div> },
{ path: '/page3', element: <div>Page 3</div> }
]);
});

it('should ignore apps without routes', () => {
const mockRoutes: RouteObject[] = [
{ path: '/page1', element: <div>Page 1</div> },
];
const mockApps = [
{ routes: mockRoutes },
{ slots: [] },
];

(getConfig as jest.Mock).mockReturnValue({ apps: mockApps });

const routes = getAppRoutes();

expect(routes).toEqual(mockRoutes);
});
});

0 comments on commit a111d6a

Please sign in to comment.