deadhead-space-freight-tycoon/apps/web/test/viewed-contract.test.tsx

46 lines
1.5 KiB
TypeScript

import type { Contract } from "@deadhead/schema";
import { screen } from "@testing-library/react";
import userEvent from "@testing-library/user-event";
import { describe, expect, it, vi } from "vitest";
import { fakeApi, renderApp, samplePlayerState } from "./render";
const NOW = Date.now();
const job: Contract = {
id: "earth:7:0",
originId: "earth",
destinationId: "moon",
cargoTypeId: "standard",
goodId: "consumer-goods",
shipper: "Pacific Orbital Logistics",
priority: false,
deliveryWindowGameHours: null,
tier: 0,
massTonnes: 6,
payout: 1_000,
requiredSkill: null,
requiredLongHaulLevel: 0,
offeredAt: NOW,
expiresAt: NOW + 600_000,
firstContact: false,
};
describe("the open contract (Step 21.5, decision 0.5.126)", () => {
it("tells the engine which contract the dispatch sheet has open, and when it closes", async () => {
const setViewedContract = vi.fn();
const api = Object.assign(
fakeApi({
getPlayerState: () =>
samplePlayerState({ tutorial: null, bays: [{ id: "b", locationId: "earth" }] }),
getContractBoard: () => ({ contracts: [job], periodEndsAt: NOW + 600_000 }),
}),
{ setViewedContract },
);
renderApp(api, "/contracts?location=earth");
await userEvent.click(await screen.findByRole("button", { name: "Dispatch" }));
expect(setViewedContract).toHaveBeenLastCalledWith("earth:7:0");
await userEvent.click(screen.getByRole("button", { name: "Cancel" }));
expect(setViewedContract).toHaveBeenLastCalledWith(null);
});
});