-
-
Notifications
You must be signed in to change notification settings - Fork 43
Expand file tree
/
Copy pathvalidators.test.js
More file actions
32 lines (25 loc) · 1.33 KB
/
validators.test.js
File metadata and controls
32 lines (25 loc) · 1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
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();
});