-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
60a8978
commit 6ae0dee
Showing
4 changed files
with
107 additions
and
5 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
93 changes: 93 additions & 0 deletions
93
frontend/tests/components/search/SearchResultsList.test.tsx
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 |
---|---|---|
@@ -0,0 +1,93 @@ | ||
import { render, screen } from "@testing-library/react"; | ||
import { axe } from "jest-axe"; | ||
import { identity } from "lodash"; | ||
import { SearchAPIResponse } from "src/types/search/searchResponseTypes"; | ||
import { useTranslationsMock } from "src/utils/testing/intlMocks"; | ||
|
||
import SearchResultsList from "src/components/search/SearchResultsList"; | ||
|
||
jest.mock("next-intl/server", () => ({ | ||
getTranslations: () => useTranslationsMock(), | ||
})); | ||
|
||
jest.mock("next-intl", () => ({ | ||
useTranslations: () => useTranslationsMock(), | ||
})); | ||
|
||
const makeSearchResults = (overrides: Partial<SearchAPIResponse>) => ({ | ||
status_code: 200, | ||
data: [], | ||
pagination_info: { | ||
order_by: "whatever", | ||
page_offset: 1, | ||
page_size: 1, | ||
sort_direction: "up", | ||
total_pages: 1, | ||
total_records: 1, | ||
}, | ||
message: "", | ||
...overrides, | ||
}); | ||
|
||
const makeOpportunity = (overrides) => ({ | ||
agency: "DMFHDLSKD", | ||
category: "good", | ||
category_explanation: "how to explain good", | ||
created_at: "today", | ||
opportunity_assistance_listings: [], | ||
opportunity_id: 1, | ||
opportunity_number: "111111", | ||
opportunity_status: "archived", | ||
opportunity_title: "This Opportunity", | ||
summary: { | ||
summary_description: "<p>Summary Description</p>", | ||
applicant_types: [ | ||
"state_governments", | ||
"nonprofits_non_higher_education_with_501c3", | ||
"unknown_type", | ||
], | ||
applicant_eligibility_description: "<p>Eligibility Description</p>", | ||
agency_contact_description: "<p>Contact Description</p>", | ||
agency_email_address: "contact@example.com", | ||
agency_email_address_description: "Contact Email Description", | ||
}, | ||
updated_at: "today", | ||
...overrides, | ||
}); | ||
|
||
describe("SearchResultsList", () => { | ||
it("should not have accessibility violations", async () => { | ||
const component = await SearchResultsList({ | ||
searchResults: makeSearchResults({}), | ||
}); | ||
const { container } = render(component); | ||
const results = await axe(container); | ||
expect(results).toHaveNoViolations(); | ||
}); | ||
it("renders an error if search results have no data", async () => { | ||
const component = await SearchResultsList({ | ||
searchResults: makeSearchResults({ status_code: 404 }), | ||
}); | ||
render(component); | ||
expect(screen.getByRole("heading")).toHaveTextContent("heading"); | ||
}); | ||
it('renders a "not found" page if no records are passed in', async () => { | ||
const component = await SearchResultsList({ | ||
searchResults: makeSearchResults({}), | ||
}); | ||
render(component); | ||
expect(screen.getByRole("heading")).toHaveTextContent( | ||
"resultsListFetch.noResultsTitle", | ||
); | ||
}); | ||
it("renders an list item for each search result", async () => { | ||
const component = await SearchResultsList({ | ||
searchResults: makeSearchResults({ | ||
data: [makeOpportunity({}), makeOpportunity({ opportunity_id: 2 })], | ||
}), | ||
}); | ||
render(component); | ||
const listItems = screen.getAllByRole("listitem"); | ||
expect(listItems).toHaveLength(2); | ||
}); | ||
}); |