-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into navigation-tests
- Loading branch information
Showing
7 changed files
with
109 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import { render } from "@testing-library/react"; | ||
import { screen } from "@testing-library/dom"; | ||
import userEvent from "@testing-library/user-event"; | ||
|
||
import CheckboxList from "./CheckboxList"; | ||
|
||
test("displays a label", () => { | ||
const label = "This is a list"; | ||
render( | ||
<CheckboxList | ||
label={label} | ||
values={[]} | ||
checkedValues={[]} | ||
toggleValue={vi.fn()} | ||
/>, | ||
); | ||
expect(screen.getByText(label)).toBeInTheDocument(); | ||
}); | ||
|
||
test("displays checkboxes", () => { | ||
render( | ||
<CheckboxList | ||
label="This is a list" | ||
values={["val1", "val2"]} | ||
checkedValues={[]} | ||
toggleValue={vi.fn()} | ||
/>, | ||
); | ||
expect(screen.getByRole("checkbox", { name: "val1" })).toBeInTheDocument(); | ||
expect(screen.getByRole("checkbox", { name: "val2" })).toBeInTheDocument(); | ||
}); | ||
|
||
test("checks selected checkboxes", () => { | ||
render( | ||
<CheckboxList | ||
label="This is a list" | ||
values={["val1", "val2"]} | ||
checkedValues={["val2"]} | ||
toggleValue={vi.fn()} | ||
/>, | ||
); | ||
expect(screen.getByRole("checkbox", { name: "val1" })).not.toBeChecked(); | ||
expect(screen.getByRole("checkbox", { name: "val2" })).toBeChecked(); | ||
}); | ||
|
||
test("changes checkbox state", async () => { | ||
const toggleValue = vi.fn(); | ||
render( | ||
<CheckboxList | ||
label="This is a list" | ||
values={["val1", "val2"]} | ||
checkedValues={[]} | ||
toggleValue={toggleValue} | ||
/>, | ||
); | ||
await userEvent.click(screen.getByRole("checkbox", { name: "val2" })); | ||
expect(toggleValue).toHaveBeenCalledWith("val2"); | ||
}); |
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,18 @@ | ||
import { render } from "@testing-library/react"; | ||
import { screen } from "@testing-library/dom"; | ||
|
||
import Loader from "./Loader"; | ||
|
||
test("displays a spinner", () => { | ||
render(<Loader />); | ||
const spinner = document.querySelector(".p-icon--spinner"); | ||
expect(spinner).toBeInTheDocument(); | ||
expect(screen.getByText("Loading...")).toBeInTheDocument(); | ||
}); | ||
|
||
test("displays custom loading text", () => { | ||
render(<Loader text="Spinning" />); | ||
const spinner = document.querySelector(".p-icon--spinner"); | ||
expect(spinner).toBeInTheDocument(); | ||
expect(screen.getByText("Spinning")).toBeInTheDocument(); | ||
}); |
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,15 @@ | ||
import { screen } from "@testing-library/dom"; | ||
|
||
import Logo from "./Logo"; | ||
import { SITE_NAME } from "consts"; | ||
import { renderComponent } from "test/utils"; | ||
|
||
test("links to the root", () => { | ||
renderComponent(<Logo />); | ||
expect(screen.getByRole("link")).toHaveAttribute("href", "/"); | ||
}); | ||
|
||
test("displays the site title", () => { | ||
renderComponent(<Logo />); | ||
expect(screen.getByText(SITE_NAME)).toBeInTheDocument(); | ||
}); |
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,12 @@ | ||
import { screen } from "@testing-library/dom"; | ||
import { render } from "@testing-library/react"; | ||
|
||
import NoMatch from "./NoMatch"; | ||
import { Label } from "./types"; | ||
|
||
test("displays a no-match message", () => { | ||
render(<NoMatch />); | ||
expect( | ||
screen.getByRole("heading", { name: Label.TITLE }), | ||
).toBeInTheDocument(); | ||
}); |
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,3 @@ | ||
export enum Label { | ||
TITLE = "404 Page not found", | ||
} |