58 lines
2.5 KiB
TypeScript
58 lines
2.5 KiB
TypeScript
import { content } from "@deadhead/content";
|
|
import { screen, within } from "@testing-library/react";
|
|
import userEvent from "@testing-library/user-event";
|
|
import { describe, expect, it } from "vitest";
|
|
import { fakeApi, renderApp, samplePlayerState } from "./render";
|
|
|
|
const item = (name: string) => screen.getByText(name).closest("li")!;
|
|
|
|
describe("locations screen", () => {
|
|
it("hides details of undiscovered locations", async () => {
|
|
renderApp(fakeApi({ getPlayerState: () => samplePlayerState() }), "/locations");
|
|
await screen.findByText("Mars");
|
|
const mars = item("Mars");
|
|
expect(mars).toHaveTextContent("Undiscovered — deliver here to unlock.");
|
|
expect(mars).not.toHaveTextContent("Produces");
|
|
expect(within(mars).queryByRole("button")).not.toBeInTheDocument();
|
|
});
|
|
|
|
it("shows details of discovered locations, with distance from Earth", async () => {
|
|
renderApp(fakeApi({ getPlayerState: () => samplePlayerState() }), "/locations");
|
|
await screen.findByText("Moon");
|
|
const moon = item("Moon");
|
|
expect(moon).toHaveTextContent("TypeAirless body");
|
|
expect(moon).toHaveTextContent("LandingAny ship");
|
|
expect(moon).toHaveTextContent("ProducesStandard, Heavy");
|
|
expect(moon).toHaveTextContent(/M km from Earth/);
|
|
expect(item("Earth")).toHaveTextContent("Home");
|
|
});
|
|
|
|
it("offers leasing only at discovered locations without a bay", async () => {
|
|
const api = fakeApi({
|
|
getPlayerState: () =>
|
|
samplePlayerState({
|
|
company: { id: "c", name: "D", credits: 100_000 },
|
|
bays: [{ id: "b1", locationId: "earth" }],
|
|
}),
|
|
});
|
|
renderApp(api, "/locations");
|
|
await screen.findByText("Moon");
|
|
|
|
expect(item("Earth")).toHaveTextContent("Bay owned");
|
|
expect(within(item("Earth")).queryByRole("button")).not.toBeInTheDocument();
|
|
|
|
const moonPrice = content.location("moon")!.bayLeasePrice;
|
|
const lease = within(item("Moon")).getByRole("button", { name: "Lease bay at Moon" });
|
|
expect(lease).toHaveTextContent(`Lease bay (${moonPrice.toLocaleString("en-US")} cr)`);
|
|
await userEvent.click(lease);
|
|
expect(api.call).toHaveBeenCalledWith("leaseBay", { locationId: "moon" });
|
|
|
|
expect(screen.queryByRole("button", { name: "Lease bay at Mars" })).not.toBeInTheDocument();
|
|
});
|
|
|
|
it("disables leasing the player cannot afford", async () => {
|
|
renderApp(fakeApi({ getPlayerState: () => samplePlayerState() }), "/locations");
|
|
expect(await screen.findByRole("button", { name: "Lease bay at Earth" })).toBeDisabled();
|
|
});
|
|
});
|