forked from openedx/frontend-base
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
59 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
}); |