Skip to content

Commit de224be

Browse files
remove react router (#1988)
1 parent 407ee1b commit de224be

File tree

10 files changed

+19
-100
lines changed

10 files changed

+19
-100
lines changed

frontends/main/src/components/ChannelMenu/ChannelMenu.test.tsx

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import React from "react"
22
import { screen } from "@testing-library/react"
3-
// eslint-disable-next-line import/no-extraneous-dependencies
4-
import { BrowserRouter } from "react-router-dom"
53

64
import ChannelMenu from "./ChannelMenu"
75
import { urls } from "api/test-utils"
@@ -17,9 +15,7 @@ describe("ChannelMenu", () => {
1715
)
1816

1917
renderWithTheme(
20-
<BrowserRouter>
21-
<ChannelMenu channelType={channel.channel_type} name={channel.name} />
22-
</BrowserRouter>,
18+
<ChannelMenu channelType={channel.channel_type} name={channel.name} />,
2319
)
2420
const dropdown = await screen.findByRole("button")
2521
await user.click(dropdown)

frontends/main/src/page-components/ChannelDetails/ChannelDetails.test.tsx

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import React from "react"
22
import { screen } from "@testing-library/react"
33
import { ChannelDetails } from "./ChannelDetails"
44
// eslint-disable-next-line import/no-extraneous-dependencies
5-
import { BrowserRouter } from "react-router-dom"
65
import { urls } from "api/test-utils"
76
import { renderWithTheme, setMockResponse } from "@/test-utils"
87
import { channels as factory } from "api/test-utils/factories"
@@ -17,11 +16,7 @@ describe("ChannelDetails", () => {
1716
urls.channels.details(channel.channel_type, channel.name),
1817
channel,
1918
)
20-
renderWithTheme(
21-
<BrowserRouter>
22-
<ChannelDetails channel={channel} />
23-
</BrowserRouter>,
24-
)
19+
renderWithTheme(<ChannelDetails channel={channel} />)
2520
const channelData = channel as unknown as Record<string, unknown>
2621
const unitDetail = channelData.unit_detail as unknown as Record<
2722
string,
@@ -49,11 +44,7 @@ describe("ChannelDetails", () => {
4944
urls.channels.details(channel.channel_type, channel.name),
5045
channel,
5146
)
52-
renderWithTheme(
53-
<BrowserRouter>
54-
<ChannelDetails channel={channel} />
55-
</BrowserRouter>,
56-
)
47+
renderWithTheme(<ChannelDetails channel={channel} />)
5748

5849
expect(screen.getByTestId("unit-details").firstChild).toHaveTextContent(
5950
"Offerings",

frontends/main/src/page-components/SearchDisplay/SearchDisplay.tsx

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -543,22 +543,6 @@ interface SearchDisplayProps {
543543
clearAllFacets: UseResourceSearchParamsResult["clearAllFacets"]
544544
toggleParamValue: UseResourceSearchParamsResult["toggleParamValue"]
545545
showProfessionalToggle?: boolean
546-
/**
547-
* NOTE: This is passed from parent, rather than obtained via useSearchParams,
548-
* because of quirks with react-router's useSearchParams hook.
549-
*
550-
* Multiple calls to React Router's useSearchParam hook do not use current
551-
* values for the search params.
552-
* See https://github.com/remix-run/react-router/issues/9757 for details.
553-
*
554-
* This is partially addressed by `@mitodl/course-search-utils`, which exports
555-
* a wrapper around `useSearchParams`: subsequent calls to `setSearchParams`
556-
* DO use the current value, with one caveat: The setSearchParams function
557-
* must be from the same "instance" of `useSearchParams`.
558-
*
559-
* Because of this, we pass the setSearchParams function from the parent
560-
* rather than from a new "instance" of `useSearchParams`.
561-
*/
562546
setSearchParams: UseResourceSearchParamsProps["setSearchParams"]
563547
resultsHeadingEl: React.ElementType
564548
filterHeadingEl: React.ElementType

frontends/ol-components/package.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,6 @@
3636
"ol-utilities": "0.0.0",
3737
"react": "^19.0.0",
3838
"react-dom": "^19.0.0",
39-
"react-router": "^6.22.2",
40-
"react-router-dom": "^6.22.2",
4139
"react-select": "^5.7.7",
4240
"react-share": "^5.0.3",
4341
"react-slick": "^0.30.2",

frontends/ol-components/src/components/Breadcrumbs/Breadcrumbs.test.tsx

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,6 @@ import { screen } from "@testing-library/react"
33
import { Breadcrumbs } from "./Breadcrumbs"
44
import { renderWithTheme } from "../../test-utils"
55

6-
// Mock react-router-dom's Link so we don't need to set up a Router
7-
jest.mock("react-router-dom", () => {
8-
return {
9-
Link: jest.fn((props) => <a href={props.to}>{props.children}</a>),
10-
}
11-
})
12-
136
describe("Breadcrumbs", () => {
147
test.each([
158
{ ancestors: [{ href: "/home", label: "Home" }] },

frontends/ol-components/src/components/LearningResourceCard/LearningResourceListCard.test.tsx

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import React from "react"
2-
import { BrowserRouter } from "react-router-dom"
32
import { screen, within } from "@testing-library/react"
43
import { LearningResourceListCard } from "./LearningResourceListCard"
54
import type { LearningResourceListCardProps } from "./LearningResourceListCard"
@@ -10,11 +9,7 @@ import { getByImageSrc } from "ol-test-utilities"
109
import { renderWithTheme } from "../../test-utils"
1110

1211
const setup = (props: LearningResourceListCardProps) => {
13-
return renderWithTheme(
14-
<BrowserRouter>
15-
<LearningResourceListCard {...props} />
16-
</BrowserRouter>,
17-
)
12+
return renderWithTheme(<LearningResourceListCard {...props} />)
1813
}
1914

2015
describe("Learning Resource List Card", () => {
@@ -118,13 +113,11 @@ describe("Learning Resource List Card", () => {
118113
const onAddToUserListClick = jest.fn()
119114

120115
renderWithTheme(
121-
<BrowserRouter>
122-
<LearningResourceListCard
123-
resource={resource}
124-
onAddToLearningPathClick={onAddToLearningPathClick}
125-
onAddToUserListClick={onAddToUserListClick}
126-
/>
127-
</BrowserRouter>,
116+
<LearningResourceListCard
117+
resource={resource}
118+
onAddToLearningPathClick={onAddToLearningPathClick}
119+
onAddToUserListClick={onAddToUserListClick}
120+
/>,
128121
)
129122

130123
const addToLearningPathButton = screen.getByLabelText(

frontends/ol-components/src/components/Link/Link.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ const BaseLink = ({
109109

110110
/**
111111
* A styled link. By default, renders a medium-sized black link using the Link
112-
* component from `react-router`. This is appropriate for in-app routing.
112+
* component from `next/link`. This is appropriate for in-app routing.
113113
*
114114
* If you need to force a full-page reload, e.g., for login/logout links, use
115115
* set `nativeAnchor={true}`.

frontends/ol-components/src/components/Lists/ListItemLink.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import Link from "next/link"
77
type ListItemLinkProps = ListItemButtonProps<"a">
88

99
/**
10-
* A ListItemButton that uses a Link component from react-router-dom.
10+
* A ListItemButton that uses a Link component from next/link.
1111
*
1212
* The purpose is to make the entire clickable area of a ListItem a link. Note
1313
* that `ListItem` should have `disablePadding` when it contains a `ListItemLink`

frontends/ol-components/src/components/SimpleMenu/SimpleMenu.test.tsx

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,19 @@ import { screen } from "@testing-library/react"
33
import user from "@testing-library/user-event"
44
import { SimpleMenu } from "./SimpleMenu"
55
import type { SimpleMenuItem } from "./SimpleMenu"
6-
import type { LinkProps } from "react-router-dom"
76
import { renderWithTheme } from "../../test-utils"
87

9-
// Mock react-router-dom's Link so we don't need to set up a Router
8+
// Mock next/link's Link so we don't need to set up a Router
109
jest.mock("next/link", () => {
1110
return {
1211
__esModule: true,
13-
default: React.forwardRef<HTMLAnchorElement, LinkProps>(
14-
jest.fn(({ children, ...props }, ref) => {
15-
return (
16-
<a {...props} ref={ref} data-react-component="next/link">
17-
{children}
18-
</a>
19-
)
20-
}),
21-
),
12+
default: jest.fn(({ children, ...props }) => {
13+
return (
14+
<a {...props} data-react-component="next/link">
15+
{children}
16+
</a>
17+
)
18+
}),
2219
}
2320
})
2421

yarn.lock

Lines changed: 0 additions & 33 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)