deadhead-space-freight-tycoon/apps/web/test/help-settings.test.tsx

52 lines
2.2 KiB
TypeScript

import { act, screen, within } from "@testing-library/react";
import userEvent from "@testing-library/user-event";
import { afterEach, describe, expect, it, vi } from "vitest";
import { DEFAULT_CAMERA, pan, useCamera } from "../src/map/camera";
import { DEFAULT_PREFERENCES, usePreferences } from "../src/state/preferences";
import { fakeApi, renderApp, samplePlayerState, sampleTutorialBoard } from "./render";
describe("help settings (Step 10K.4)", () => {
afterEach(() => {
vi.useRealTimers();
act(() => {
useCamera.setState(DEFAULT_CAMERA);
usePreferences.getState().set(DEFAULT_PREFERENCES);
});
});
it("saves the map view, and Reset map view restores the default and forgets it", async () => {
vi.useFakeTimers({ toFake: ["setTimeout", "clearTimeout"] });
act(() => useCamera.setState((c) => pan({ ...c, zoom: 3 }, 120, -80)));
act(() => vi.advanceTimersByTime(400));
expect(usePreferences.getState().mapCamera).toEqual({ zoom: 3, panX: 120, panY: -80 });
vi.useRealTimers();
renderApp(
fakeApi({ getPlayerState: () => samplePlayerState({ tutorial: null }) }),
"/settings",
);
await userEvent.click(await screen.findByRole("button", { name: "Reset map view" }));
expect(useCamera.getState()).toEqual(DEFAULT_CAMERA);
expect(usePreferences.getState().mapCamera).toBeNull();
});
it("brings a dismissed tip back with Show tips again", async () => {
renderApp(
fakeApi({
getPlayerState: () => samplePlayerState(),
getTutorialBoard: () => sampleTutorialBoard(),
}),
"/contracts",
);
const intro = await screen.findByLabelText("Intro");
await userEvent.click(within(intro).getByRole("button", { name: "Dismiss tip" }));
expect(screen.queryByLabelText("Intro")).not.toBeInTheDocument();
await userEvent.click(screen.getByRole("link", { name: "Settings" }));
await userEvent.click(await screen.findByRole("button", { name: "Show tips again" }));
const nav = screen.getByRole("navigation", { name: "Main" });
await userEvent.click(within(nav).getByRole("link", { name: /Jobs/ }));
expect(await screen.findByLabelText("Intro")).toBeInTheDocument();
});
});