Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add validators test #846

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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();
});
Loading