Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 4 additions & 13 deletions src/routes.test.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { Suspense } from 'react';
import { screen } from '@testing-library/react';
import { authenticatedLoader } from '@openedx/frontend-base';
import { renderWrapper, initializeMocks } from '@src/testUtils';
Expand Down Expand Up @@ -27,24 +26,16 @@ describe('routes', () => {
it('requires authentication via the authenticated loader', () => {
expect(routes[0].loader).toBe(authenticatedLoader);
});

it('provides a Component for the route', () => {
expect(routes[0].Component).toBeDefined();
});
});

describe('Component', () => {
describe('lazy', () => {
beforeEach(() => {
initializeMocks();
});

it('lazily loads Main', async () => {
const { Component } = routes[0];
renderWrapper(
<Suspense fallback={<div>loading</div>}>
<Component />
</Suspense>,
);
it('resolves Main as the route Component', async () => {
const { Component } = await routes[0].lazy();
renderWrapper(<Component />);
expect(await screen.findByTestId('authz-module')).toBeInTheDocument();
});
});
Expand Down
8 changes: 4 additions & 4 deletions src/routes.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import { lazy } from 'react';
import { authenticatedLoader } from '@openedx/frontend-base';

import { AUTHZ_HOME_PATH } from './authz-module/constants';

const Main = lazy(() => import('./Main'));

const routes = [
{
id: 'org.openedx.frontend.route.adminConsole.main',
path: `${AUTHZ_HOME_PATH}/*`,
loader: authenticatedLoader,
Component: Main,
async lazy() {
const { default: Main } = await import('./Main');
return { Component: Main };
},
handle: {
roles: ['org.openedx.frontend.role.adminConsole'],
},
Expand Down
Loading