-
-
Notifications
You must be signed in to change notification settings - Fork 43
Expand file tree
/
Copy pathpermissions.test.jsx
More file actions
63 lines (52 loc) · 2.66 KB
/
permissions.test.jsx
File metadata and controls
63 lines (52 loc) · 2.66 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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import {beforeAll, describe, expect, test} from "vitest";
import {within} from "@testing-library/dom";
import {screen, waitFor} from "@testing-library/react";
import userEvent from "@testing-library/user-event";
global.pythonProcessPath = "examples/permissions.py";
describe("admin", () => {
beforeAll(() => setLogin("admin", ""));
test("view", async () => {
const table = await screen.findByRole("table");
const headers = within(table).getAllByRole("columnheader");
expect(headers.slice(1, -1).map((e) => e.textContent)).toEqual(["Id", "Num", "Optional Num"]);
const rows = within(table).getAllByRole("row");
const firstCells = within(rows[1]).getAllByRole("cell").slice(1, -1);
expect(firstCells.map((e) => e.textContent)).toEqual(["1", "5", ""]);
const secondCells = within(rows[2]).getAllByRole("cell").slice(1, -1);
expect(secondCells.map((e) => e.textContent)).toEqual(["2", "82", "12"]);
});
});
describe("filter", () => {
beforeAll(() => setLogin("filter", ""));
test("view", async () => {
const table = await screen.findByRole("table");
const rows = within(table).getAllByRole("row").slice(1);
expect(rows).toHaveLength(5);
expect(rows.map(r => within(r).getAllByRole("cell")[1].textContent)).toEqual(["1", "3", "4", "5", "6"]);
await userEvent.click(screen.getByRole("link", {"name": "Create"}));
await waitFor(() => screen.getByText("Create Simple"));
const num = screen.getByLabelText("Num *");
expect(num).toHaveAttribute("aria-disabled", "true");
expect(num).toHaveTextContent("5");
});
});
describe("admin", () => {
beforeAll(() => setLogin("admin", ""));
test("bulk update", async () => {
const container = await screen.findByRole("columnheader", {"name": "Select all"});
const selectAll = within(container).getByRole("checkbox");
await userEvent.click(selectAll);
expect(selectAll).toBeChecked();
await userEvent.click(await screen.findByRole("button", {"name": "Set to 7"}));
expect(await screen.findByText("Update 6 simples")).toBeInTheDocument();
await userEvent.click(screen.getByRole("button", {"name": "Confirm"}));
return; // Broken now
await waitFor(() => screen.getAllByText("7"));
const table = await screen.findByRole("table");
const rows = within(table).getAllByRole("row");
const firstCells = within(rows[1]).getAllByRole("cell");
const secondCells = within(rows[2]).getAllByRole("cell");
expect(firstCells[3]).toHaveTextContent("7");
expect(secondCells[3]).toHaveTextContent("7");
});
});