diff --git a/app/components/search/Refinements/ClearSearchButton.tsx b/app/components/search/Refinements/ClearSearchButton.tsx
index 32c810c47..8285fea5e 100644
--- a/app/components/search/Refinements/ClearSearchButton.tsx
+++ b/app/components/search/Refinements/ClearSearchButton.tsx
@@ -26,7 +26,7 @@ const ClearSearchButton = () => {
mobileFullWidth={false}
onClick={handleOnClick}
>
- Clear Search
+ Clear Search
);
};
diff --git a/app/components/search/SearchResults/SearchResult.tsx b/app/components/search/SearchResults/SearchResult.tsx
index a585daac5..91cdf17a9 100644
--- a/app/components/search/SearchResults/SearchResult.tsx
+++ b/app/components/search/SearchResults/SearchResult.tsx
@@ -2,7 +2,6 @@ import React, { forwardRef } from "react";
import { TransformedSearchHit } from "models";
import { Link } from "react-router-dom";
import { LabelTag } from "components/ui/LabelTag";
-import { Tooltip } from "react-tippy";
import { formatPhoneNumber, renderAddressMetadata } from "utils";
import { removeAsterisksAndHashes } from "utils/strings";
import ReactMarkdown from "react-markdown";
diff --git a/app/components/search/SearchResults/SearchResults.test.tsx b/app/components/search/SearchResults/SearchResults.test.tsx
new file mode 100644
index 000000000..634840f73
--- /dev/null
+++ b/app/components/search/SearchResults/SearchResults.test.tsx
@@ -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";
+
+describe("SearchResults", () => {
+ test("renders the Clear Search button", async () => {
+ const searchClient = createSearchClient();
+
+ render(
+
+
+
+ );
+
+ await waitFor(() => {
+ expect(screen.getByTestId("clear-search-button")).toBeInTheDocument();
+ });
+ });
+
+ test("does not render the Clear Search button", async () => {
+ const searchClient = createSearchClient();
+
+ render(
+
+
+
+ );
+
+ await waitFor(() => {
+ expect(
+ screen.queryByTestId("clear-search-button")
+ ).not.toBeInTheDocument();
+ });
+ });
+});
diff --git a/app/components/search/SearchResults/SearchResults.tsx b/app/components/search/SearchResults/SearchResults.tsx
index 0c56ab032..c49eb5aaf 100644
--- a/app/components/search/SearchResults/SearchResults.tsx
+++ b/app/components/search/SearchResults/SearchResults.tsx
@@ -1,4 +1,4 @@
-import React, { useCallback } from "react";
+import React, { ReactNode, useCallback } from "react";
import { SearchMap } from "components/search/SearchMap/SearchMap";
import { SearchResult } from "components/search/SearchResults/SearchResult";
import {
@@ -11,9 +11,9 @@ import {
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,
@@ -21,8 +21,10 @@ export enum SearchMapActions {
const SearchResults = ({
mobileMapIsCollapsed,
+ showClearSearchButton,
}: {
mobileMapIsCollapsed: boolean;
+ showClearSearchButton?: boolean;
}) => {
const { refine: refinePagination } = usePagination();
const {
@@ -51,7 +53,7 @@ const SearchResults = ({
Try a different location, filter, or search term.
- {query && }
+ {query && showClearSearchButton && }
);
@@ -59,7 +61,7 @@ const SearchResults = ({
return (
{searchResults.nbHits} results
-
+ {showClearSearchButton && }
);
};
diff --git a/app/pages/SearchResultsPage/SearchResultsPage.tsx b/app/pages/SearchResultsPage/SearchResultsPage.tsx
index 8cdd087e0..855b86366 100644
--- a/app/pages/SearchResultsPage/SearchResultsPage.tsx
+++ b/app/pages/SearchResultsPage/SearchResultsPage.tsx
@@ -6,6 +6,7 @@ import styles from "./SearchResultsPage.module.scss";
import { DEFAULT_AROUND_PRECISION, useAppContext } from "utils";
import { Configure } from "react-instantsearch-core";
import classNames from "classnames";
+import ClearSearchButton from "components/search/Refinements/ClearSearchButton";
// NOTE: The .searchResultsPage is added plain so that it can be targeted by print-specific css
export const SearchResultsPage = () => {
@@ -28,7 +29,10 @@ export const SearchResultsPage = () => {
/>
-
+
diff --git a/jest.config.ts b/jest.config.ts
index 9c5edbc96..4df688939 100644
--- a/jest.config.ts
+++ b/jest.config.ts
@@ -91,6 +91,9 @@ const config: Config = {
moduleNameMapper: {
// Ensures style imports don't break tests
"\\.(css|scss)$": "/test/jest/__mocks__/styleMock.ts",
+ "react-markdown": "/test/jest/__mocks__/react-markdown.tsx",
+ "\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$":
+ "/test/jest/__mocks__/fileMock.js",
},
// An array of regexp pattern strings, matched against all module paths before considered 'visible' to the module loader
diff --git a/test/helpers/createSearchClient.ts b/test/helpers/createSearchClient.ts
index 9b2433ba0..b20093ca8 100644
--- a/test/helpers/createSearchClient.ts
+++ b/test/helpers/createSearchClient.ts
@@ -30,7 +30,7 @@ interface Options {
* @param options Additional customizations of the search response
* @returns
*/
-export function createSearchClient(options: Options) {
+export function createSearchClient(options?: Options) {
return {
search: (requests: any) =>
Promise.resolve({
diff --git a/test/jest/__mocks__/fileMock.ts b/test/jest/__mocks__/fileMock.ts
new file mode 100644
index 000000000..00629187f
--- /dev/null
+++ b/test/jest/__mocks__/fileMock.ts
@@ -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 "";
diff --git a/test/jest/__mocks__/react-markdown.tsx b/test/jest/__mocks__/react-markdown.tsx
new file mode 100644
index 000000000..608bd4abd
--- /dev/null
+++ b/test/jest/__mocks__/react-markdown.tsx
@@ -0,0 +1,11 @@
+import React from "react";
+
+const ReactMarkdown = ({
+ children,
+}: {
+ children: string | JSX.Element | JSX.Element[] | (() => JSX.Element);
+}) => {
+ return <>{children}>;
+};
+
+export default ReactMarkdown;