|
| 1 | +import { cleanup, fireEvent, screen, waitFor } from "@testing-library/react"; |
| 2 | +import { afterEach, describe, expect, test } from "vitest"; |
| 3 | +import { FakeBotloft } from "../lib/fake"; |
| 4 | +import { crewOpened, renderApp } from "../test/app"; |
| 5 | +import { prefs } from "./prefs"; |
| 6 | + |
| 7 | +afterEach(() => { |
| 8 | + cleanup(); |
| 9 | + prefs.sidebar.reset(); |
| 10 | +}); |
| 11 | + |
| 12 | +const list = () => screen.getByRole("navigation", { name: "Crews", hidden: true }); |
| 13 | +const slot = () => list().closest(".sidebar-slot") as HTMLElement; |
| 14 | + |
| 15 | +async function oneCrew() { |
| 16 | + const fake = new FakeBotloft(); |
| 17 | + const crew = fake.addCrew("Ops"); |
| 18 | + const scout = fake.addBot(crew.id, "Scout"); |
| 19 | + renderApp(fake); |
| 20 | + await crewOpened("Ops"); |
| 21 | + return { fake, scout }; |
| 22 | +} |
| 23 | + |
| 24 | +describe("hiding the bots list", () => { |
| 25 | + test("the title bar button hides the list and brings it back, and it is remembered", async () => { |
| 26 | + await oneCrew(); |
| 27 | + expect(slot().dataset.open).toBe("true"); |
| 28 | + fireEvent.click(screen.getByRole("button", { name: "Hide the bots list" })); |
| 29 | + expect(slot().dataset.open).toBe("false"); |
| 30 | + expect(slot().hasAttribute("inert")).toBe(true); |
| 31 | + expect(localStorage.getItem("botloft.sidebar")).toBe("false"); |
| 32 | + fireEvent.click(screen.getByRole("button", { name: "Show the bots list" })); |
| 33 | + expect(slot().dataset.open).toBe("true"); |
| 34 | + expect(slot().hasAttribute("inert")).toBe(false); |
| 35 | + }); |
| 36 | + |
| 37 | + test("Ctrl+B does the same", async () => { |
| 38 | + await oneCrew(); |
| 39 | + fireEvent.keyDown(window, { key: "b", ctrlKey: true }); |
| 40 | + expect(slot().dataset.open).toBe("false"); |
| 41 | + fireEvent.keyDown(window, { key: "B", ctrlKey: true }); |
| 42 | + expect(slot().dataset.open).toBe("true"); |
| 43 | + fireEvent.keyDown(window, { key: "b" }); |
| 44 | + expect(slot().dataset.open).toBe("true"); |
| 45 | + }); |
| 46 | + |
| 47 | + test("with the list hidden, a dot on the button says a bot is waiting", async () => { |
| 48 | + const { fake, scout } = await oneCrew(); |
| 49 | + fireEvent.click(screen.getByRole("button", { name: "Hide the bots list" })); |
| 50 | + const button = screen.getByRole("button", { name: "Show the bots list" }); |
| 51 | + expect(button.parentElement?.querySelector(".live-dot")).toBeNull(); |
| 52 | + fake.setBotState(scout.id, "needs_approval"); |
| 53 | + await waitFor(() => expect(button.parentElement?.querySelector(".live-dot")).not.toBeNull()); |
| 54 | + }); |
| 55 | +}); |
0 commit comments