75 lines
2.9 KiB
TypeScript
75 lines
2.9 KiB
TypeScript
import { expect, test } from "@playwright/test";
|
||
import { content } from "@deadhead/content";
|
||
import type { Contract, Dispatch } from "@deadhead/schema";
|
||
import {
|
||
acknowledgeAll,
|
||
addCredits,
|
||
advance,
|
||
advanceTo,
|
||
board,
|
||
dismissLogbook,
|
||
expectNews,
|
||
goAway,
|
||
playToDeal,
|
||
run,
|
||
state,
|
||
tryDispatch,
|
||
} from "./support";
|
||
|
||
const BOARD_PERIOD_MS = content.config.contractBoardPeriodRealMinutes * 60_000;
|
||
|
||
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)!;
|
||
|
||
// Long Haul for the trip, and fuel money (Mars is always in a Clipper's reach, CR-015).
|
||
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);
|
||
|
||
// Each board offers a first contact the Clipper can fly (decision 0.5.85); since
|
||
// CR-016 it may be Venus rather than Mars, so wait for a board offering Mars.
|
||
let offer: Contract | undefined;
|
||
for (let period = 0; period < 12 && !offer; period++) {
|
||
if (period > 0) await advance(page, BOARD_PERIOD_MS);
|
||
offer = (await board(page, "earth")).contracts.find(
|
||
(c) => c.firstContact && c.destinationId === "mars",
|
||
);
|
||
}
|
||
expect(offer, "a first contact to Mars on an 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 goAway(page);
|
||
await advanceTo(page, flight!.arrivalAt);
|
||
await page.goto("/");
|
||
await expectNews(page, "opened a new market: 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"]);
|
||
});
|
||
});
|