-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move tab state for Search Results into localStorage and out of browse…
…r query params
- Loading branch information
1 parent
48361d4
commit bb9b42a
Showing
19 changed files
with
2,784 additions
and
1,462 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,37 @@ | ||
import { render, screen } from "@/test-utils"; | ||
|
||
import Search from "./Search"; | ||
import { UserContext } from "@/context/user-context"; | ||
import { UserContext as UserContextType } from "@/types/context/user"; | ||
import mockRouter from "next-router-mock"; | ||
import { renderHook } from "@testing-library/react"; | ||
import { useRouter } from "next/router"; | ||
import userEvent from "@testing-library/user-event"; | ||
|
||
const mockIsSearchActive = jest.fn(); | ||
|
||
const defaultUser = { | ||
user: { | ||
email: "[email protected]", | ||
isLoggedIn: true, | ||
isReadingRoom: false, | ||
name: "Ace Frehley", | ||
sub: "xyz123", | ||
}, | ||
}; | ||
|
||
const withUserProvider = ( | ||
Component: React.ReactNode, | ||
user: UserContextType = defaultUser, | ||
) => { | ||
return <UserContext.Provider value={user}>{Component}</UserContext.Provider>; | ||
}; | ||
|
||
describe("Search component", () => { | ||
beforeEach(() => { | ||
localStorage.clear(); | ||
}); | ||
|
||
it("renders the search ui component", () => { | ||
render(<Search isSearchActive={() => ({})} />); | ||
const wrapper = screen.getByTestId("search-ui-component"); | ||
|
@@ -71,19 +94,19 @@ describe("Search component", () => { | |
it("renders standard placeholder text for non AI search", () => { | ||
render(<Search isSearchActive={mockIsSearchActive} />); | ||
const input = screen.getByPlaceholderText( | ||
"Search by keyword or phrase, ex: Berkeley Music Festival" | ||
"Search by keyword or phrase, ex: Berkeley Music Festival", | ||
); | ||
expect(input).toBeInTheDocument(); | ||
}); | ||
|
||
it("renders generative AI placeholder text when AI search is active", () => { | ||
mockRouter.setCurrentUrl("/search?ai=true"); | ||
localStorage.setItem("ai", JSON.stringify("true")); | ||
|
||
render(withUserProvider(<Search isSearchActive={mockIsSearchActive} />)); | ||
|
||
render(<Search isSearchActive={mockIsSearchActive} />); | ||
const input = screen.getByPlaceholderText( | ||
"What can I show you from our collections?" | ||
"What can I show you from our collections?", | ||
); | ||
|
||
expect(input).toBeInTheDocument(); | ||
}); | ||
}); |
Oops, something went wrong.