deadhead-space-freight-tycoon/apps/web/e2e/12-5-discovery.e2e.ts

67 lines
2.5 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { expect, test } from "@playwright/test";
import type { Dispatch } from "@deadhead/schema";
import {
acknowledgeAll,
addCredits,
advanceTo,
board,
dismissLogbook,
logbook,
nextMarsWindow,
playToDeal,
run,
serverNow,
state,
tryDispatch,
} from "./support";
test.describe("end to end (Phase 12)", () => {
test("12.5: a first contact to Mars discovers it, opens its board and lets you lease there", async ({
page,
}) => {
const owner = await playToDeal(page);
const clipper = owner.ships.find((s) => s.modelId === "clipper")!;
const veteran = owner.pilots.find((p) => p.isVeteran)!;
// A date when the Clipper can reach Mars, Long Haul for the trip, and fuel money.
await advanceTo(page, nextMarsWindow(await serverNow(page)));
await page.goto("/pilots");
const raise = page.getByRole("button", { name: `Raise Long Haul for ${veteran.name}` });
while ((await state(page)).pilots.find((p) => p.id === veteran.id)!.skillPointsAvailable > 0) {
await raise.click();
}
await addCredits(page, 100_000);
// The deal's Clipper comes with a quarter tank (CR-015): an Earth–Moon round
// trip on Auto top-up lands it back at Earth full.
for (const destinationId of ["moon", "earth"]) {
const { dispatch } = await run<{ dispatch: Dispatch }>(page, "createDispatch", {
kind: "reposition",
shipId: clipper.id,
pilotId: veteran.id,
destinationId,
});
await advanceTo(page, dispatch.arrivalAt);
}
await acknowledgeAll(page);
// The board offers a first contact the Clipper can fly (decision 0.5.85).
const offer = (await board(page, "earth")).contracts.find(
(c) => c.firstContact && c.destinationId === "mars",
);
expect(offer, "a first contact to Mars on the Earth board").toBeDefined();
const flight = await tryDispatch(page, offer!.id, clipper.id, veteran.id);
expect(flight, "the Clipper and veteran can take it").not.toBeNull();
await advanceTo(page, flight!.arrivalAt);
await page.goto("/");
await expect(logbook(page)).toContainText("Discovered Mars!");
await dismissLogbook(page);
// Mars is discovered on the Locations screen and can be leased; its board is open without a bay (CR-002).
await page.goto("/locations");
await expect(page.getByRole("button", { name: "Lease bay at Mars" })).toBeEnabled();
expect((await board(page, "mars")).contracts.length).toBeGreaterThan(0);
expect((await state(page)).bays.map((b) => b.locationId)).toEqual(["earth"]);
});
});