-
Notifications
You must be signed in to change notification settings - Fork 16
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
testing: search page component test [1393] #2189
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
fc2d5de
wip, need to squash errors related to non react component children
doug-s-nava e3df0e6
basic test working
doug-s-nava 47e8e27
revert unnecessary changes
doug-s-nava 59f23fb
rename file
doug-s-nava f9ceacc
use new utils
doug-s-nava File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import { render, screen } from "@testing-library/react"; | ||
import { identity } from "lodash"; | ||
import Search from "src/app/[locale]/search/page"; | ||
import { MockSearchFetcher } from "src/services/search/searchfetcher/MockSearchFetcher"; | ||
import { useTranslationsMock } from "tests/utils/intlMocks"; | ||
|
||
// test without feature flag functionality | ||
jest.mock("src/hoc/search/withFeatureFlag", () => | ||
jest.fn((Component: React.Component) => Component), | ||
); | ||
|
||
jest.mock("next-intl/server", () => ({ | ||
getTranslations: () => identity, | ||
unstable_setRequestLocale: identity, | ||
})); | ||
|
||
jest.mock("next-intl", () => ({ | ||
useTranslations: () => useTranslationsMock(), | ||
})); | ||
|
||
// mock API interactions | ||
jest.mock("src/services/search/searchfetcher/SearchFetcherUtil", () => ({ | ||
getSearchFetcher: () => new MockSearchFetcher(), | ||
})); | ||
|
||
jest.mock("next/navigation", () => ({ | ||
...jest.requireActual<typeof import("next/navigation")>("next/navigation"), | ||
useRouter: () => ({ | ||
// eslint-disable-next-line @typescript-eslint/no-empty-function | ||
push: () => {}, | ||
}), | ||
})); | ||
|
||
/* | ||
nested async server components (< ...Fetcher />) are currently breaking the render. | ||
stated workarounds are not working. to get testing minimally working, overriding | ||
Suspense to force display of fallback UI. | ||
|
||
for more see https://github.com/testing-library/react-testing-library/issues/1209 | ||
*/ | ||
jest.mock("react", () => ({ | ||
...jest.requireActual<typeof import("react")>("react"), | ||
Suspense: ({ fallback }: { fallback: React.Component }) => fallback, | ||
})); | ||
|
||
describe("Search Route", () => { | ||
it("renders the search page with expected checkboxes checked", async () => { | ||
const mockSearchParams = { | ||
status: "forecasted,posted", | ||
}; | ||
|
||
render(<Search searchParams={mockSearchParams} />); | ||
|
||
// translation service is mocked, so the expected label here is the translation key rather than the label text | ||
const forecastedCheckbox = await screen.findByLabelText( | ||
"opportunityStatus.label.forecasted", | ||
); | ||
expect(forecastedCheckbox).toBeInTheDocument(); | ||
expect(forecastedCheckbox).toBeChecked(); | ||
|
||
const postedCheckbox = await screen.findByLabelText( | ||
"opportunityStatus.label.posted", | ||
); | ||
expect(postedCheckbox).toBeInTheDocument(); | ||
expect(postedCheckbox).toBeChecked(); | ||
|
||
const closedCheckbox = await screen.findByLabelText( | ||
"opportunityStatus.label.closed", | ||
); | ||
expect(closedCheckbox).toBeInTheDocument(); | ||
expect(closedCheckbox).not.toBeChecked(); | ||
|
||
const archivedCheckbox = await screen.findByLabelText( | ||
"opportunityStatus.label.archived", | ||
); | ||
expect(archivedCheckbox).toBeInTheDocument(); | ||
expect(archivedCheckbox).not.toBeChecked(); | ||
}); | ||
}); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I believe this change occurred automatically when I started up a local server, not entirely sure why.
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.
I get the same. It is a doc link update so I think we can just add it in this PR.