Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dgcohen committed Nov 7, 2023
1 parent 72448ff commit 8e1d797
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions __test__/pages/search/searchResults.test.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React from "react"
import userEvent from "@testing-library/user-event"
import { render, screen } from "@testing-library/react"

import mockRouter from "next-router-mock"
Expand All @@ -23,6 +24,20 @@ describe("Search Results page", () => {
const cards = screen.getAllByRole("heading", { level: 3 })
expect(cards).toHaveLength(50)
})
it("renders the sort select field and updates the query string in the url on changes", async () => {
const query = "spaghetti"
await mockRouter.push(`/search?q=${query}`)
render(<SearchResults results={results} />)

const sortSelect = screen.getByLabelText("Sort by")
expect(sortSelect).toHaveValue("relevance")
await userEvent.selectOptions(sortSelect, "Title (A - Z)")
expect(sortSelect).toHaveValue("title_asc")

expect(mockRouter.asPath).toBe(
"/?q=spaghetti&sort=title&sort_direction=asc"
)
})
})
describe("No bibs", () => {
it("displays No results message", () => {
Expand Down

0 comments on commit 8e1d797

Please sign in to comment.