Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions admin-js/tests/setupTests.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ beforeAll(async() => {
const parser = new DOMParser();
const doc = parser.parseFromString(html, "text/html");
STATE = JSON.parse(doc.querySelector("body").dataset.state);
if (STATE["js_module"] !== null)
STATE["js_module"] = "http://localhost:8080/admin" + STATE["js_module"];
resolve();
});
});
Expand Down
32 changes: 32 additions & 0 deletions admin-js/tests/validators.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import {within} from "@testing-library/dom";
import {screen, waitFor} from "@testing-library/react";
import userEvent from "@testing-library/user-event";

global.pythonProcessPath = "examples/validators.py";


test("validators work", async () => {
await userEvent.click((await screen.findAllByLabelText("Edit"))[0]);
await waitFor(() => screen.getByRole("link", {"name": "List"}));

const main = screen.getByRole("main");
const edit = main.querySelector("form");

const votes = within(edit).getByLabelText("Votes *");
await userEvent.clear(votes);
await userEvent.type(votes, "4");
const email = within(edit).getByLabelText("Email");
await userEvent.type(email, "foobar");
const username = within(edit).getByLabelText("Username *");
await userEvent.type(username, "123");
await userEvent.click(within(edit).getByRole("button", {"name": "Save"}));

expect(votes).toBeInvalid();
expect(email).toBeInvalid();
expect(username).toBeInvalid();

expect(votes).toHaveAccessibleErrorMessage("Votes must be an odd number");
expect(within(form).getByText("Votes must be an odd number")).toBeInTheDocument();
expect(within(form).getByText("Must be a valid email")).toBeInTheDocument();
expect(within(form).getByText("Must match a specific format (regexp): [object Object]")).toBeInTheDocument();
});