-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[OUR415-313] Adds prop/slot for the "Clear Search" button in the SearchResults
component
#261
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import React from "react"; | ||
import { InstantSearch } from "react-instantsearch-core"; | ||
import { render, screen, waitFor } from "@testing-library/react"; | ||
import SearchResults from "components/search/SearchResults/SearchResults"; | ||
import { createSearchClient } from "../../../../test/helpers/createSearchClient"; | ||
import ClearSearchButton from "components/search/Refinements/ClearSearchButton"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. chore: let's remove this line |
||
|
||
describe("SearchResults", () => { | ||
test("renders the Clear Search button", async () => { | ||
const searchClient = createSearchClient(); | ||
|
||
render( | ||
<InstantSearch | ||
searchClient={searchClient} | ||
indexName="fake_test_search_index" | ||
initialUiState={{ | ||
fake_test_search_index: { | ||
query: "fake query", | ||
}, | ||
}} | ||
> | ||
<SearchResults | ||
mobileMapIsCollapsed={false} | ||
showClearSearchButton={true} | ||
/> | ||
</InstantSearch> | ||
); | ||
|
||
await waitFor(() => { | ||
expect(screen.getByTestId("clear-search-button")).toBeInTheDocument(); | ||
}); | ||
}); | ||
|
||
test("does not render the Clear Search button", async () => { | ||
const searchClient = createSearchClient(); | ||
|
||
render( | ||
<InstantSearch | ||
searchClient={searchClient} | ||
indexName="fake_test_search_index" | ||
initialUiState={{ | ||
fake_test_search_index: { | ||
query: "fake query", | ||
}, | ||
}} | ||
> | ||
<SearchResults mobileMapIsCollapsed={false} /> | ||
</InstantSearch> | ||
); | ||
|
||
await waitFor(() => { | ||
expect( | ||
screen.queryByTestId("clear-search-button") | ||
).not.toBeInTheDocument(); | ||
}); | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import React, { useCallback } from "react"; | ||
import React, { ReactNode, useCallback } from "react"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. chore: let's remove this too. notice we've let a lot of warnings through. i have some capacity and am happy to submit a PR to get rid of them |
||
import { SearchMap } from "components/search/SearchMap/SearchMap"; | ||
import { SearchResult } from "components/search/SearchResults/SearchResult"; | ||
import { | ||
|
@@ -11,18 +11,20 @@ | |
useSearchBox, | ||
} from "react-instantsearch"; | ||
import styles from "./SearchResults.module.scss"; | ||
import ClearSearchButton from "../Refinements/ClearSearchButton"; | ||
import { Loader } from "components/ui"; | ||
import { Loader } from "components/ui/Loader"; | ||
import ResultsPagination from "components/search/Pagination/ResultsPagination"; | ||
import ClearSearchButton from "components/search/Refinements/ClearSearchButton"; | ||
|
||
export enum SearchMapActions { | ||
SearchThisArea, | ||
} | ||
|
||
const SearchResults = ({ | ||
mobileMapIsCollapsed, | ||
showClearSearchButton, | ||
}: { | ||
mobileMapIsCollapsed: boolean; | ||
showClearSearchButton?: boolean; | ||
}) => { | ||
const { refine: refinePagination } = usePagination(); | ||
const { | ||
|
@@ -51,15 +53,15 @@ | |
<br /> Try a different location, filter, or search term. | ||
</div> | ||
|
||
{query && <ClearSearchButton />} | ||
{query && showClearSearchButton && <ClearSearchButton />} | ||
</div> | ||
); | ||
|
||
const searchResultsHeader = () => { | ||
return ( | ||
<div className={styles.searchResultsHeader}> | ||
<h2>{searchResults.nbHits} results</h2> | ||
<ClearSearchButton /> | ||
{showClearSearchButton && <ClearSearchButton />} | ||
</div> | ||
); | ||
}; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
interface Options { | ||
[key: string]: any; | ||
} | ||
|
||
/** | ||
|
@@ -30,7 +30,7 @@ | |
* @param options Additional customizations of the search response | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. question (if-minor): Is this type any because it could be anything? Hoping to avoid type any as much as possible, and if it is needed, we should add a lint ignore comment (it wouldn't let me comment on the actual line (line 2) |
||
* @returns | ||
*/ | ||
export function createSearchClient(options: Options) { | ||
export function createSearchClient(options?: Options) { | ||
return { | ||
search: (requests: any) => | ||
Promise.resolve({ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
// Webpack is not available in tests to handle the css import parsing and handling. Our test config tells jest to | ||
// replace any style imports it sees with this empty object. | ||
export default ""; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import React from "react"; | ||
|
||
const ReactMarkdown = ({ | ||
children, | ||
}: { | ||
children: string | JSX.Element | JSX.Element[] | (() => JSX.Element); | ||
}) => { | ||
return <>{children}</>; | ||
}; | ||
|
||
export default ReactMarkdown; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
note: Noticed this was unused.