deadhead-space-freight-tycoon/apps/web/test/map-overlays.test.ts

62 lines
2.0 KiB
TypeScript

import type { Ship } from "@deadhead/schema";
import { describe, expect, it } from "vitest";
import { locationOverlays } from "../src/map/overlays";
import { buildScene } from "../src/map/scene";
import { mapStyle } from "../src/map/style";
import { samplePlayerState } from "./render";
const NOW = Date.parse("2100-01-01T00:00:00Z");
const idleAtMoon = (id: string): Ship => ({
id,
modelId: "courier",
name: id,
status: "idle",
locationId: "moon",
dispatchId: null,
pilotId: null,
lastArrivalAt: 0,
});
/** After the deal: an Earth bay, two idle ships at the Moon, Mars and beyond undiscovered. */
const scene = () =>
buildScene(
samplePlayerState({
tutorial: null,
bays: [{ id: "b1", locationId: "earth" }],
ships: [idleAtMoon("s1"), idleAtMoon("s2")],
}),
NOW,
);
describe("location state overlays (Step 10C.7)", () => {
it("desaturates, dims and locks undiscovered locations only", () => {
const overlays = new Map(locationOverlays(scene()).map((o) => [o.id, o]));
for (const id of ["mars", "ceres-station", "jupiter-cloud-platform"]) {
expect(overlays.get(id), id).toMatchObject({
locked: true,
desaturate: true,
alpha: mapStyle.undiscoveredAlpha,
});
}
for (const id of ["earth", "moon"]) {
expect(overlays.get(id), id).toMatchObject({ locked: false, desaturate: false, alpha: 1 });
}
});
it("marks bay locations as HQs", () => {
const hqs = locationOverlays(scene())
.filter((o) => o.hq)
.map((o) => o.id);
expect(hqs).toEqual(["earth"]);
});
it("shows two idle ships as one badge reading 2, and no single ship sprites", () => {
const s = scene();
const moon = locationOverlays(s).find((o) => o.id === "moon")!;
expect(moon.idleBadge).toBe(2);
expect(locationOverlays(s).find((o) => o.id === "earth")!.idleBadge).toBeNull();
// Ships are only drawn for flights; idle ships have none.
expect(s.flights).toEqual([]);
});
});