import type { Contract, Ship } from "@deadhead/schema"; import { screen } from "@testing-library/react"; import { describe, expect, it } from "vitest"; import { carryLimit } from "../src/screens/LocationBoards"; import { fakeApi, renderApp, samplePlayerState } from "./render"; const NOW = Date.now(); const contract = (id: string, massTonnes: number): Contract => ({ id, originId: "earth", destinationId: "moon", cargoTypeId: "standard", goodId: "consumer-goods", shipper: "Pacific Orbital Logistics", priority: false, deliveryWindowGameHours: null, tier: 0, massTonnes, payout: 1000 + massTonnes, requiredSkill: null, requiredLongHaulLevel: 0, offeredAt: NOW, expiresAt: NOW + 30 * 60_000, firstContact: false, }); const ship = (id: string, overrides: Partial): Ship => ({ id, modelId: "courier", name: id, status: "idle", locationId: "earth", dispatchId: null, pilotId: null, lastArrivalAt: 0, ...overrides, }); const owner = (ships: Ship[]) => samplePlayerState({ tutorial: null, bays: [{ id: "b", locationId: "earth" }], ships }); const render = (ships: Ship[]) => renderApp( fakeApi({ getPlayerState: () => owner(ships), getContractBoard: () => ({ contracts: [contract("light", 10), contract("heavy", 50)], periodEndsAt: NOW + 600_000, }), }), "/contracts?location=earth", ); const card = async (payout: string) => (await screen.findByText(payout)).closest("li")!; describe("weight warning (Step 10F.1)", () => { it("flags a job heavier than every ship at the location", async () => { render([ship("Dusty Mule", {})]); expect(await card("1,050 cr")).toHaveTextContent("Too heavy"); expect(await card("1,010 cr")).not.toHaveTextContent("Too heavy"); }); it("uses the ships at the location, not elsewhere", async () => { render([ ship("Dusty Mule", { locationId: "moon" }), ship("Big Ox", { modelId: "freighter", locationId: "earth" }), ]); expect(await card("1,050 cr")).not.toHaveTextContent("Too heavy"); }); it("falls back to the whole fleet when no ship is at the location", () => { const state = owner([ ship("a", { locationId: "moon" }), ship("b", { modelId: "freighter", locationId: null, status: "in-flight" }), ]); expect(carryLimit(state, "earth")).toBe(100); expect(carryLimit(owner([]), "earth")).toBeNull(); }); });