Skip to content

Commit 387bb98

Browse files
committed
refactor: use Link from react-router in Breadcrumb links
1 parent 9aee1e4 commit 387bb98

2 files changed

Lines changed: 10 additions & 2 deletions

File tree

src/authz-module/components/AuthZTitle.test.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
1-
import React from 'react';
1+
import { ReactNode } from 'react';
22
import { render, screen, fireEvent } from '@testing-library/react';
33
import AuthZTitle, { AuthZTitleProps } from './AuthZTitle';
44

5+
jest.mock('react-router-dom', () => ({
6+
...jest.requireActual('react-router-dom'),
7+
Link: ({ children, to }:{ children:ReactNode, to:string }) => <a href={to}>{children}</a>,
8+
}));
9+
510
describe('AuthZTitle', () => {
611
const defaultProps: AuthZTitleProps = {
712
activeLabel: 'Current Page',
@@ -24,8 +29,9 @@ describe('AuthZTitle', () => {
2429

2530
render(<AuthZTitle {...defaultProps} navLinks={navLinks} />);
2631

27-
navLinks.forEach(({ label }) => {
32+
navLinks.forEach(({ label, to }) => {
2833
expect(screen.getByText(label)).toBeInTheDocument();
34+
expect(screen.getByText(label)).toHaveAttribute('href', expect.stringContaining(to));
2935
});
3036

3137
expect(screen.getByText(defaultProps.activeLabel)).toBeInTheDocument();

src/authz-module/components/AuthZTitle.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { ReactNode } from 'react';
2+
import { Link } from 'react-router-dom';
23
import {
34
Breadcrumb, Col, Container, Row, Button, Badge,
45
} from '@openedx/paragon';
@@ -26,6 +27,7 @@ const AuthZTitle = ({
2627
}: AuthZTitleProps) => (
2728
<Container className="p-5 bg-light-100">
2829
<Breadcrumb
30+
linkAs={Link}
2931
links={navLinks}
3032
activeLabel={activeLabel}
3133
/>

0 commit comments

Comments
 (0)