|
| 1 | +import { act, cleanup, fireEvent, screen, waitFor, within } from "@testing-library/react"; |
| 2 | +import { afterEach, describe, expect, test } from "vitest"; |
| 3 | +import { setLocaleChoice } from "../../i18n"; |
| 4 | +import { FakeBotloft } from "../../lib/fake"; |
| 5 | +import { crewOpened, openBot, renderApp } from "../../test/app"; |
| 6 | + |
| 7 | +afterEach(() => { |
| 8 | + act(() => setLocaleChoice("en")); |
| 9 | + cleanup(); |
| 10 | +}); |
| 11 | + |
| 12 | +async function details() { |
| 13 | + const fake = new FakeBotloft(); |
| 14 | + const ops = fake.addCrew("Ops"); |
| 15 | + const scout = fake.addBot(ops.id, "Scout", "Finds sources"); |
| 16 | + fake.setBotState(scout.id, "idle"); |
| 17 | + renderApp(fake); |
| 18 | + await crewOpened("Ops"); |
| 19 | + openBot("Scout"); |
| 20 | + await screen.findByRole("list", { name: "Messages" }); |
| 21 | + fireEvent.click(screen.getByRole("button", { name: /^Show details/ })); |
| 22 | + const about = screen.getByRole("complementary", { name: "About Scout" }); |
| 23 | + return { fake, scout, about }; |
| 24 | +} |
| 25 | + |
| 26 | +describe("the whole desktop", () => { |
| 27 | + test("is given only after the owner chooses a level and accepts the risks", async () => { |
| 28 | + const { fake, about } = await details(); |
| 29 | + fireEvent.click(await within(about).findByRole("button", { name: "Give the whole desktop" })); |
| 30 | + const dialog = screen.getByRole("dialog", { name: "Give Scout your whole desktop?" }); |
| 31 | + expect(within(dialog).getByText(/without asking you first/)).toBeDefined(); |
| 32 | + expect(within(dialog).getByText(/covered in black/)).toBeDefined(); |
| 33 | + const confirm = within(dialog).getByRole("button", { name: "Give it" }) as HTMLButtonElement; |
| 34 | + expect(confirm.disabled).toBe(true); |
| 35 | + |
| 36 | + fireEvent.click(within(dialog).getByRole("radio", { name: "Can see and use" })); |
| 37 | + fireEvent.click(within(dialog).getByRole("checkbox", { name: "I understand the risks" })); |
| 38 | + expect(confirm.disabled).toBe(false); |
| 39 | + fireEvent.click(confirm); |
| 40 | + await waitFor(() => expect(fake.desktop.grants[0]?.scope).toBe("desktop")); |
| 41 | + expect(fake.desktop.grants[0]?.level).toBe("act"); |
| 42 | + expect(fake.desktop.grants[0]?.acceptedRisksAt).not.toBeNull(); |
| 43 | + |
| 44 | + // Listed like any grant, with its options; the button goes. |
| 45 | + expect(await within(about).findByText("The whole desktop")).toBeDefined(); |
| 46 | + expect( |
| 47 | + within(about).getByRole("switch", { name: "Real mouse and keyboard: The whole desktop" }), |
| 48 | + ).toBeDefined(); |
| 49 | + expect(within(about).queryByRole("button", { name: "Give the whole desktop" })).toBeNull(); |
| 50 | + }, 15_000); |
| 51 | + |
| 52 | + test("speaks the owner's language", async () => { |
| 53 | + const { about } = await details(); |
| 54 | + act(() => setLocaleChoice("pt-BR")); |
| 55 | + fireEvent.click(await within(about).findByRole("button", { name: "Dar o desktop inteiro" })); |
| 56 | + expect( |
| 57 | + screen.getByRole("dialog", { name: "Dar a Scout o seu desktop inteiro?" }), |
| 58 | + ).toBeDefined(); |
| 59 | + }); |
| 60 | +}); |
0 commit comments