-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch '3.1.0' into CRDCDH-1428
- Loading branch information
Showing
2 changed files
with
101 additions
and
17 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,80 @@ | ||
import { axe } from "jest-axe"; | ||
import { render } from "@testing-library/react"; | ||
import { render, waitFor, within } from "@testing-library/react"; | ||
import userEvent from "@testing-library/user-event"; | ||
import NodeChart from "./index"; | ||
|
||
it("should not have any accessibility violations", async () => { | ||
const data = [ | ||
{ label: "New" as SeriesLabel, value: 50, color: "#000000" }, | ||
{ label: "Passed" as SeriesLabel, value: 25, color: "#ffffff" }, | ||
{ label: "Error" as SeriesLabel, value: 25, color: "#3b3b3b" }, | ||
]; | ||
const { container } = render(<NodeChart label="Test Chart" centerCount={3} data={data} />); | ||
const mockData: PieSectorDataItem[] = [ | ||
{ label: "New", value: 50, color: "#000000" }, | ||
{ label: "Passed", value: 25, color: "#ffffff" }, | ||
{ label: "Error", value: 25, color: "#3b3b3b" }, | ||
]; | ||
|
||
const results = await axe(container); | ||
describe("Accessibility", () => { | ||
it("should not have any accessibility violations", async () => { | ||
const { container } = render(<NodeChart label="Test Chart" centerCount={3} data={mockData} />); | ||
|
||
expect(results).toHaveNoViolations(); | ||
const results = await axe(container); | ||
|
||
expect(results).toHaveNoViolations(); | ||
}); | ||
}); | ||
|
||
describe("Basic Functionality", () => { | ||
it("should trim the chart label if it exceeds 14 characters", () => { | ||
const { getByText, rerender } = render( | ||
<NodeChart label="This Is A Very Long Label" centerCount={3} data={mockData} /> | ||
); | ||
|
||
expect(getByText("This Is A Very...")).toBeInTheDocument(); | ||
|
||
rerender(<NodeChart label="Short Label" centerCount={3} data={mockData} />); | ||
|
||
expect(getByText("Short Label")).toBeInTheDocument(); | ||
}); | ||
|
||
it("should replace underscores with spaces in the chart label", () => { | ||
const { getByText } = render( | ||
<NodeChart label="Test_Label_1" centerCount={3} data={mockData} /> | ||
); | ||
|
||
expect(getByText("Test Label 1")).toBeInTheDocument(); | ||
}); | ||
|
||
it("should perform a title case transformation on the chart label if it contains spaces", async () => { | ||
const { getByText, getByRole } = render( | ||
<NodeChart label="principal investigator" centerCount={3} data={mockData} /> | ||
); | ||
|
||
expect(getByText("Principal Inve...")).toBeInTheDocument(); | ||
|
||
userEvent.hover(getByText("Principal Inve...")); | ||
|
||
await waitFor(() => { | ||
expect(getByRole("tooltip")).toBeVisible(); | ||
}); | ||
|
||
// NOTE: We're asserting that the same transformation is applied to the tooltip | ||
expect(within(getByRole("tooltip")).getByText("Principal Investigator")).toBeInTheDocument(); | ||
}); | ||
|
||
// NOTE: Since we're splitting at underscores, let's individually test this too | ||
it("should perform title case transformation on the chart label if it would contain spaces", () => { | ||
const { getByText } = render( | ||
<NodeChart label="principal_investigator" centerCount={3} data={mockData} /> | ||
); | ||
|
||
expect(getByText("Principal Inve...")).toBeInTheDocument(); | ||
}); | ||
|
||
it("should persist existing casing if the label does not contain spaces", () => { | ||
const { getByText } = render( | ||
<NodeChart label="NonDICOMCTimages" centerCount={3} data={mockData} /> | ||
); | ||
|
||
expect(getByText("NonDICOMCTimag...")).toBeInTheDocument(); | ||
}); | ||
|
||
it.each([null, "", undefined])("should not crash if the label is %s", (value) => { | ||
expect(() => render(<NodeChart label={value} centerCount={3} data={mockData} />)).not.toThrow(); | ||
}); | ||
}); |
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