30 lines
1.6 KiB
TypeScript
30 lines
1.6 KiB
TypeScript
import { screen, waitFor, within } from "@testing-library/react";
|
|
import userEvent from "@testing-library/user-event";
|
|
import { describe, expect, it, vi } from "vitest";
|
|
import { useClock } from "../src/clock/clock";
|
|
import { fakeApi, renderApp, samplePlayerState } from "./render";
|
|
|
|
describe("about and debug info (Step 10K.10)", () => {
|
|
it("shows the version and copies debug info with every field", async () => {
|
|
const writeText = vi.fn(() => Promise.resolve());
|
|
Object.defineProperty(navigator, "clipboard", { value: { writeText }, configurable: true });
|
|
renderApp(fakeApi({ getPlayerState: () => samplePlayerState({ tutorial: null }) }), "/fleet");
|
|
|
|
await userEvent.click(await screen.findByRole("link", { name: "Settings" }));
|
|
const about = await screen.findByRole("region", { name: "About" });
|
|
// vitest.config.ts stands in for the build-time version and commit.
|
|
expect(within(about).getByLabelText("Version")).toHaveTextContent("0.0.0-test · build test");
|
|
|
|
await userEvent.click(within(about).getByRole("button", { name: "Copy debug info" }));
|
|
await waitFor(() => expect(writeText).toHaveBeenCalledTimes(1));
|
|
const text = (writeText.mock.calls[0] as unknown as [string])[0];
|
|
expect(text).toContain("Version: 0.0.0-test");
|
|
expect(text).toContain("Build: test");
|
|
expect(text).toContain("Player: player-1");
|
|
expect(text).toMatch(/Server time: \d{4}-\d{2}-\d{2}T/);
|
|
// The app syncs its own clock, so expect whatever offset it holds now.
|
|
expect(text).toContain(`Clock offset: ${Math.round(useClock.getState().offsetMs)} ms`);
|
|
expect(text).toContain("Screen: /fleet");
|
|
});
|
|
});
|