-
Notifications
You must be signed in to change notification settings - Fork 16
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
Showing
2 changed files
with
58 additions
and
0 deletions.
There are no files selected for viewing
38 changes: 38 additions & 0 deletions
38
assets/src/scripts/__tests__/components/DescendantToggle.spec.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,38 @@ | ||
import "@testing-library/jest-dom"; | ||
import { render, screen } from "@testing-library/react"; | ||
import { userEvent } from "@testing-library/user-event"; | ||
import React from "react"; | ||
import { expect, it, vi } from "vitest"; | ||
import DescendantToggle from "../../components/DescendantToggle"; | ||
|
||
it("Show a minus symbol if expanded", async () => { | ||
render( | ||
<DescendantToggle isExpanded path="/" toggleVisibility={() => null} />, | ||
); | ||
expect(screen.queryByText("⊟")).toBeVisible; | ||
expect(screen.queryByText("⊞")).toBeNull; | ||
}); | ||
|
||
it("Show a plus symbol if not expanded", async () => { | ||
render( | ||
<DescendantToggle | ||
isExpanded={false} | ||
path="/" | ||
toggleVisibility={() => null} | ||
/>, | ||
); | ||
expect(screen.queryByText("⊞")).toBeVisible; | ||
expect(screen.queryByText("⊟")).toBeNull; | ||
}); | ||
|
||
it("Triggers the toggle visibility function", async () => { | ||
const fn = vi.fn(); | ||
|
||
render( | ||
<DescendantToggle isExpanded path="/test-path/" toggleVisibility={fn} />, | ||
); | ||
|
||
await userEvent.click(screen.getByText("⊟")); | ||
|
||
expect(fn.mock.calls[0][0]).toBe("/test-path/"); | ||
}); |
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,20 @@ | ||
import { expect, it } from "vitest"; | ||
import { getCookie, readValueFromPage } from "../_utils"; | ||
|
||
it("gets the cookie value", () => { | ||
const name = "csrftoken"; | ||
const value = "01JJ6V33G19M1ZFEB4JAQMMTQW"; | ||
document.cookie = `${name}=${value || ""};`; | ||
expect(getCookie(name)).toBe(value); | ||
}); | ||
|
||
it("reads the values of a JSON script on the page", () => { | ||
const blob = { | ||
hello: "world", | ||
}; | ||
document.body.innerHTML = ` | ||
<script id="all-codes">${JSON.stringify(blob)}</script> | ||
`; | ||
|
||
expect(readValueFromPage("all-codes")).toEqual(blob); | ||
}); |