Build Seth's changes C1 to C11 (Gitea issues 1, 8, 18, 23, 24, 25, 27, 31, 32, 33, 36)
2026-10-30 13:33:51 -06:00
|
|
|
import { fireEvent, screen, waitFor, within } from "@testing-library/react";
|
|
|
|
|
import { beforeEach, describe, expect, it, vi } from "vitest";
|
2026-10-21 18:27:09 -06:00
|
|
|
import { adminBase } from "../../test/admin";
|
|
|
|
|
import { renderApp } from "../../test/auth";
|
|
|
|
|
import { callsTo, mockFetch } from "../../test/fetchMock";
|
Build Seth's changes C1 to C11 (Gitea issues 1, 8, 18, 23, 24, 25, 27, 31, 32, 33, 36)
2026-10-30 13:33:51 -06:00
|
|
|
import { memoryStorage } from "../supervisor/memoryStorage";
|
2026-10-21 18:27:09 -06:00
|
|
|
|
Build Seth's changes C1 to C11 (Gitea issues 1, 8, 18, 23, 24, 25, 27, 31, 32, 33, 36)
2026-10-30 13:33:51 -06:00
|
|
|
const ITEMS = [{ group: "Before welding", key: "dwg", text: "Drawing {drawing} Rev {rev} matches the packet" }];
|
2026-10-21 18:27:09 -06:00
|
|
|
|
Build Seth's changes C1 to C11 (Gitea issues 1, 8, 18, 23, 24, 25, 27, 31, 32, 33, 36)
2026-10-30 13:33:51 -06:00
|
|
|
beforeEach(() => {
|
|
|
|
|
vi.stubGlobal("localStorage", memoryStorage());
|
|
|
|
|
});
|
2026-10-21 18:27:09 -06:00
|
|
|
|
|
|
|
|
describe("Admin Checklists tab", () => {
|
Build Seth's changes C1 to C11 (Gitea issues 1, 8, 18, 23, 24, 25, 27, 31, 32, 33, 36)
2026-10-30 13:33:51 -06:00
|
|
|
it("shows the department editor on the new endpoints and links the Checklists screen", async () => {
|
2026-10-21 18:27:09 -06:00
|
|
|
const fetch = mockFetch({
|
|
|
|
|
...adminBase(),
|
Build Seth's changes C1 to C11 (Gitea issues 1, 8, 18, 23, 24, 25, 27, 31, 32, 33, 36)
2026-10-30 13:33:51 -06:00
|
|
|
"GET /api/checklists": {
|
|
|
|
|
body: [
|
|
|
|
|
{ dept_code: "03", dept_name: "Weld Parts", weld: true, custom: false, version: 0, editable: true },
|
|
|
|
|
{ dept_code: "14", dept_name: "Electrical", weld: false, custom: true, version: 2, editable: true },
|
|
|
|
|
],
|
2026-10-21 18:27:09 -06:00
|
|
|
},
|
Build Seth's changes C1 to C11 (Gitea issues 1, 8, 18, 23, 24, 25, 27, 31, 32, 33, 36)
2026-10-30 13:33:51 -06:00
|
|
|
"GET /api/checklists/03": {
|
|
|
|
|
body: { dept_code: "03", dept_name: "Weld Parts", weld: true, custom: false, version: 0, editable: true, items: ITEMS, defaults: ITEMS },
|
2026-10-21 18:27:09 -06:00
|
|
|
},
|
|
|
|
|
});
|
Build Seth's changes C1 to C11 (Gitea issues 1, 8, 18, 23, 24, 25, 27, 31, 32, 33, 36)
2026-10-30 13:33:51 -06:00
|
|
|
renderApp("/admin");
|
|
|
|
|
fireEvent.click(await screen.findByRole("tab", { name: "Checklists" }));
|
|
|
|
|
expect(await screen.findByLabelText("Item 1 text")).toHaveValue(ITEMS[0]?.text);
|
|
|
|
|
expect(within(screen.getByRole("main")).getByRole("link", { name: "Checklists" })).toHaveAttribute("href", "/checklists");
|
|
|
|
|
expect(screen.getByRole("combobox", { name: "Department" })).toHaveValue("03");
|
|
|
|
|
await waitFor(() => expect(callsTo(fetch, "GET", "/api/admin/checklists")).toHaveLength(0));
|
2026-10-21 18:27:09 -06:00
|
|
|
});
|
|
|
|
|
});
|