diff --git a/shell/router/getAppRoutes.test.tsx b/shell/router/getAppRoutes.test.tsx new file mode 100644 index 00000000..fd97e1b6 --- /dev/null +++ b/shell/router/getAppRoutes.test.tsx @@ -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:
Page 1
}, + { path: '/page2', element:
Page 2
} + ] + }, + { + routes: [ + { path: '/page3', element:
Page 3
} + ] + }, + ]; + + (getConfig as jest.Mock).mockReturnValue({ apps: mockApps }); + + const routes = getAppRoutes(); + + expect(routes).toEqual([ + { path: '/page1', element:
Page 1
}, + { path: '/page2', element:
Page 2
}, + { path: '/page3', element:
Page 3
} + ]); + }); + + it('should ignore apps without routes', () => { + const mockRoutes: RouteObject[] = [ + { path: '/page1', element:
Page 1
}, + ]; + const mockApps = [ + { routes: mockRoutes }, + { slots: [] }, + ]; + + (getConfig as jest.Mock).mockReturnValue({ apps: mockApps }); + + const routes = getAppRoutes(); + + expect(routes).toEqual(mockRoutes); + }); +});