-
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.
test: FeedbackPhaseBanner component functionality and accessibility
- Loading branch information
1 parent
3d9cc81
commit b14b788
Showing
1 changed file
with
67 additions
and
0 deletions.
There are no files selected for viewing
67 changes: 67 additions & 0 deletions
67
editor.planx.uk/src/components/Feedback/FeedbackPhaseBanner.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,67 @@ | ||
import "@testing-library/jest-dom/extend-expect"; | ||
|
||
import { fireEvent } from "@testing-library/react"; | ||
import React from "react"; | ||
import { axe, setup } from "testUtils"; | ||
|
||
import FeedbackPhaseBanner from "./FeedbackPhaseBanner"; | ||
|
||
describe("FeedbackPhaseBanner presentation and functionality", () => { | ||
const handleFeedbackClick = jest.fn(); | ||
const handleReportAnIssueClick = jest.fn(); | ||
|
||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
test("renders PUBLIC BETA flag and buttons correctly", () => { | ||
const { getByText } = setup( | ||
<FeedbackPhaseBanner | ||
handleFeedbackClick={handleFeedbackClick} | ||
handleReportAnIssueClick={handleReportAnIssueClick} | ||
/>, | ||
); | ||
|
||
expect(getByText("PUBLIC BETA")).toBeInTheDocument(); | ||
expect(getByText("Report an issue with this page")).toBeInTheDocument(); | ||
expect(getByText("feedback")).toBeInTheDocument(); | ||
}); | ||
|
||
test("clicking on feedback link calls handleFeedbackClick", () => { | ||
const { getByText } = setup( | ||
<FeedbackPhaseBanner | ||
handleFeedbackClick={handleFeedbackClick} | ||
handleReportAnIssueClick={handleReportAnIssueClick} | ||
/>, | ||
); | ||
|
||
fireEvent.click(getByText("feedback")); | ||
expect(handleFeedbackClick).toHaveBeenCalledTimes(1); | ||
}); | ||
|
||
test("clicking on 'Report an issue with this page' button calls handleReportAnIssueClick", () => { | ||
const { getByText } = setup( | ||
<FeedbackPhaseBanner | ||
handleFeedbackClick={handleFeedbackClick} | ||
handleReportAnIssueClick={handleReportAnIssueClick} | ||
/>, | ||
); | ||
|
||
fireEvent.click(getByText("Report an issue with this page")); | ||
expect(handleReportAnIssueClick).toHaveBeenCalledTimes(1); | ||
}); | ||
}); | ||
|
||
describe("FeedbackPhaseBanner accessibility", () => { | ||
test("should have no accessibility violations", async () => { | ||
const { container } = setup( | ||
<FeedbackPhaseBanner | ||
handleFeedbackClick={() => {}} | ||
handleReportAnIssueClick={() => {}} | ||
/>, | ||
); | ||
|
||
const results = await axe(container); | ||
expect(results).toHaveNoViolations(); | ||
}); | ||
}); |