Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: fixed bug that prevents learner from seeing custom 404 #1228

Merged
merged 2 commits into from
Nov 28, 2024
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
11 changes: 8 additions & 3 deletions src/components/app/Layout.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Helmet } from 'react-helmet';
import { Outlet } from 'react-router-dom';
import { Outlet, useMatch } from 'react-router-dom';
import FooterSlot from '@openedx/frontend-slot-footer';
import { getConfig } from '@edx/frontend-platform/config';

Expand All @@ -17,12 +17,17 @@ export const DEFAULT_TITLE = 'edX';
const Layout = () => {
const config = getConfig();
const { data: enterpriseCustomer } = useEnterpriseCustomer();
const licenseActivationRouteMatch = useMatch('/:enterpriseSlug/licenses/:activationKey/activate');

const brandStyles = useStylesForCustomBrandColors(enterpriseCustomer);

// Authenticated user is NOT linked an enterprise customer, so
// render the not found page.
// Authenticated user is NOT linked to an enterprise customer.
if (!enterpriseCustomer) {
if (licenseActivationRouteMatch) {
// If the user is trying to activate a license, render the license activation route.
return <Outlet />;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It may be worth writing a test case(s) for rendering of child routes via Outlet when on the license activation route to prevent future regressions.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your suggestion I've added a test

}
// Otherwise, render the not found page.
return <NotFoundPage />;
}

Expand Down
22 changes: 22 additions & 0 deletions src/components/app/Layout.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,28 @@ describe('Layout', () => {
expect(screen.getByText('404', { selector: 'h1' })).toBeInTheDocument();
});

it('renders the license activation route when user is not linked to enterprise customer but accessing license activation', () => {
useEnterpriseCustomer.mockReturnValue({ data: null });

renderWithRouterProvider({
path: '/:enterpriseSlug/*',
element: <LayoutWrapper />,
children: [
{
path: 'licenses/:activationKey/activate',
element: <div data-testid="license-activation-page" />,
},
],
}, {
initialEntries: ['/enterprise-slug/licenses/12345678-1234-5678-1234-567812345678/activate'],
});

// Verify license activation page is rendered
expect(screen.getByTestId('license-activation-page')).toBeInTheDocument();
// Verify 404 is not rendered
expect(screen.queryByRole('heading', { name: '404' })).not.toBeInTheDocument();
});

it.each([
{
isSystemMaintenanceAlertOpen: false,
Expand Down