Skip to content

Commit

Permalink
remove react router (#1988)
Browse files Browse the repository at this point in the history
  • Loading branch information
ChristopherChudzicki authored Jan 28, 2025
1 parent 407ee1b commit de224be
Show file tree
Hide file tree
Showing 10 changed files with 19 additions and 100 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import React from "react"
import { screen } from "@testing-library/react"
// eslint-disable-next-line import/no-extraneous-dependencies
import { BrowserRouter } from "react-router-dom"

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

renderWithTheme(
<BrowserRouter>
<ChannelMenu channelType={channel.channel_type} name={channel.name} />
</BrowserRouter>,
<ChannelMenu channelType={channel.channel_type} name={channel.name} />,
)
const dropdown = await screen.findByRole("button")
await user.click(dropdown)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import React from "react"
import { screen } from "@testing-library/react"
import { ChannelDetails } from "./ChannelDetails"
// eslint-disable-next-line import/no-extraneous-dependencies
import { BrowserRouter } from "react-router-dom"
import { urls } from "api/test-utils"
import { renderWithTheme, setMockResponse } from "@/test-utils"
import { channels as factory } from "api/test-utils/factories"
Expand All @@ -17,11 +16,7 @@ describe("ChannelDetails", () => {
urls.channels.details(channel.channel_type, channel.name),
channel,
)
renderWithTheme(
<BrowserRouter>
<ChannelDetails channel={channel} />
</BrowserRouter>,
)
renderWithTheme(<ChannelDetails channel={channel} />)
const channelData = channel as unknown as Record<string, unknown>
const unitDetail = channelData.unit_detail as unknown as Record<
string,
Expand Down Expand Up @@ -49,11 +44,7 @@ describe("ChannelDetails", () => {
urls.channels.details(channel.channel_type, channel.name),
channel,
)
renderWithTheme(
<BrowserRouter>
<ChannelDetails channel={channel} />
</BrowserRouter>,
)
renderWithTheme(<ChannelDetails channel={channel} />)

expect(screen.getByTestId("unit-details").firstChild).toHaveTextContent(
"Offerings",
Expand Down
16 changes: 0 additions & 16 deletions frontends/main/src/page-components/SearchDisplay/SearchDisplay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -543,22 +543,6 @@ interface SearchDisplayProps {
clearAllFacets: UseResourceSearchParamsResult["clearAllFacets"]
toggleParamValue: UseResourceSearchParamsResult["toggleParamValue"]
showProfessionalToggle?: boolean
/**
* NOTE: This is passed from parent, rather than obtained via useSearchParams,
* because of quirks with react-router's useSearchParams hook.
*
* Multiple calls to React Router's useSearchParam hook do not use current
* values for the search params.
* See https://github.com/remix-run/react-router/issues/9757 for details.
*
* This is partially addressed by `@mitodl/course-search-utils`, which exports
* a wrapper around `useSearchParams`: subsequent calls to `setSearchParams`
* DO use the current value, with one caveat: The setSearchParams function
* must be from the same "instance" of `useSearchParams`.
*
* Because of this, we pass the setSearchParams function from the parent
* rather than from a new "instance" of `useSearchParams`.
*/
setSearchParams: UseResourceSearchParamsProps["setSearchParams"]
resultsHeadingEl: React.ElementType
filterHeadingEl: React.ElementType
Expand Down
2 changes: 0 additions & 2 deletions frontends/ol-components/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@
"ol-utilities": "0.0.0",
"react": "^19.0.0",
"react-dom": "^19.0.0",
"react-router": "^6.22.2",
"react-router-dom": "^6.22.2",
"react-select": "^5.7.7",
"react-share": "^5.0.3",
"react-slick": "^0.30.2",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,6 @@ import { screen } from "@testing-library/react"
import { Breadcrumbs } from "./Breadcrumbs"
import { renderWithTheme } from "../../test-utils"

// Mock react-router-dom's Link so we don't need to set up a Router
jest.mock("react-router-dom", () => {
return {
Link: jest.fn((props) => <a href={props.to}>{props.children}</a>),
}
})

describe("Breadcrumbs", () => {
test.each([
{ ancestors: [{ href: "/home", label: "Home" }] },
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import React from "react"
import { BrowserRouter } from "react-router-dom"
import { screen, within } from "@testing-library/react"
import { LearningResourceListCard } from "./LearningResourceListCard"
import type { LearningResourceListCardProps } from "./LearningResourceListCard"
Expand All @@ -10,11 +9,7 @@ import { getByImageSrc } from "ol-test-utilities"
import { renderWithTheme } from "../../test-utils"

const setup = (props: LearningResourceListCardProps) => {
return renderWithTheme(
<BrowserRouter>
<LearningResourceListCard {...props} />
</BrowserRouter>,
)
return renderWithTheme(<LearningResourceListCard {...props} />)
}

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

renderWithTheme(
<BrowserRouter>
<LearningResourceListCard
resource={resource}
onAddToLearningPathClick={onAddToLearningPathClick}
onAddToUserListClick={onAddToUserListClick}
/>
</BrowserRouter>,
<LearningResourceListCard
resource={resource}
onAddToLearningPathClick={onAddToLearningPathClick}
onAddToUserListClick={onAddToUserListClick}
/>,
)

const addToLearningPathButton = screen.getByLabelText(
Expand Down
2 changes: 1 addition & 1 deletion frontends/ol-components/src/components/Link/Link.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ const BaseLink = ({

/**
* A styled link. By default, renders a medium-sized black link using the Link
* component from `react-router`. This is appropriate for in-app routing.
* component from `next/link`. This is appropriate for in-app routing.
*
* If you need to force a full-page reload, e.g., for login/logout links, use
* set `nativeAnchor={true}`.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import Link from "next/link"
type ListItemLinkProps = ListItemButtonProps<"a">

/**
* A ListItemButton that uses a Link component from react-router-dom.
* A ListItemButton that uses a Link component from next/link.
*
* The purpose is to make the entire clickable area of a ListItem a link. Note
* that `ListItem` should have `disablePadding` when it contains a `ListItemLink`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,19 @@ import { screen } from "@testing-library/react"
import user from "@testing-library/user-event"
import { SimpleMenu } from "./SimpleMenu"
import type { SimpleMenuItem } from "./SimpleMenu"
import type { LinkProps } from "react-router-dom"
import { renderWithTheme } from "../../test-utils"

// Mock react-router-dom's Link so we don't need to set up a Router
// Mock next/link's Link so we don't need to set up a Router
jest.mock("next/link", () => {
return {
__esModule: true,
default: React.forwardRef<HTMLAnchorElement, LinkProps>(
jest.fn(({ children, ...props }, ref) => {
return (
<a {...props} ref={ref} data-react-component="next/link">
{children}
</a>
)
}),
),
default: jest.fn(({ children, ...props }) => {
return (
<a {...props} data-react-component="next/link">
{children}
</a>
)
}),
}
})

Expand Down
33 changes: 0 additions & 33 deletions yarn.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit de224be

Please sign in to comment.