2026-10-16 22:46:56 -06:00
|
|
|
import { fireEvent, screen, waitFor, within } from "@testing-library/react";
|
|
|
|
|
import { beforeEach, describe, expect, it, vi } from "vitest";
|
|
|
|
|
import { LAST_SCREEN_KEY } from "../auth/roles";
|
|
|
|
|
import { memoryStorage } from "../screens/supervisor/memoryStorage";
|
|
|
|
|
import { DEPARTMENTS, makeMe, renderApp } from "../test/auth";
|
|
|
|
|
import { mockFetch } from "../test/fetchMock";
|
|
|
|
|
|
|
|
|
|
const LOU = makeMe({ roles: ["shop:03:lead"], screens: ["supervisor", "stall"], user: { sam_account: "lead.lou", display_name: "Lou Lead" } });
|
|
|
|
|
|
|
|
|
|
function routes() {
|
|
|
|
|
return {
|
|
|
|
|
"/api/auth/me": { body: LOU },
|
|
|
|
|
"/api/departments": { body: DEPARTMENTS },
|
|
|
|
|
"/api/shop/board": { body: {} },
|
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
|
|
|
"/api/stall/mine": { body: { mine: [], submitted: [] } },
|
2026-10-16 22:46:56 -06:00
|
|
|
"/api/projects": { body: [] },
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
|
vi.stubGlobal("localStorage", memoryStorage());
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
describe("RoleSwitcher", () => {
|
|
|
|
|
it("lands on the first screen, and remembers the screen picked", async () => {
|
|
|
|
|
mockFetch(routes());
|
|
|
|
|
renderApp("/");
|
|
|
|
|
const nav = await screen.findByRole("navigation", { name: "Screens" });
|
|
|
|
|
await waitFor(() => expect(within(nav).getByRole("button", { name: "Supervisor" })).toHaveAttribute("aria-pressed", "true"));
|
|
|
|
|
fireEvent.click(within(nav).getByRole("button", { name: "Weld Stall" }));
|
|
|
|
|
expect(window.localStorage.getItem(LAST_SCREEN_KEY)).toBe("stall");
|
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
|
|
|
expect(await screen.findByText("Your supervisor assigns packets to you.")).toBeInTheDocument();
|
2026-10-16 22:46:56 -06:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("lands on the remembered screen when it is still allowed", async () => {
|
|
|
|
|
window.localStorage.setItem(LAST_SCREEN_KEY, "stall");
|
|
|
|
|
mockFetch(routes());
|
|
|
|
|
renderApp("/");
|
|
|
|
|
const nav = await screen.findByRole("navigation", { name: "Screens" });
|
|
|
|
|
await waitFor(() => expect(within(nav).getByRole("button", { name: "Weld Stall" })).toHaveAttribute("aria-pressed", "true"));
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("ignores a remembered screen the user no longer has", async () => {
|
|
|
|
|
window.localStorage.setItem(LAST_SCREEN_KEY, "warehouse");
|
|
|
|
|
mockFetch(routes());
|
|
|
|
|
renderApp("/");
|
|
|
|
|
const nav = await screen.findByRole("navigation", { name: "Screens" });
|
|
|
|
|
await waitFor(() => expect(within(nav).getByRole("button", { name: "Supervisor" })).toHaveAttribute("aria-pressed", "true"));
|
|
|
|
|
});
|
|
|
|
|
});
|