deadhead-space-freight-tycoon/apps/web/e2e/12-6-pilot-progression.e2e.ts

95 lines
3.4 KiB
TypeScript

import { content } from "@deadhead/content";
import { expect, test } from "@playwright/test";
import {
acknowledgeAll,
addCredits,
advance,
advanceTo,
assignPilot,
board,
buyShip,
flyUntil,
hirePilot,
playToDeal,
state,
} from "./support";
test.describe("end to end (Phase 12)", () => {
test("12.6: a pilot levels up, learns Heavy Cargo and can take a Heavy job; Long Haul lengthens duty", async ({
page,
}) => {
const owner = await playToDeal(page);
const bay = owner.bays[0]!;
await addCredits(page, 100_000);
const { ship } = await buyShip(page, "lighter", bay.id);
const { pilot } = await hirePilot(page, "earth");
await assignPilot(page, pilot.id, ship.id);
// Deliveries until the new pilot reaches level 1 (two skill points).
await flyUntil(
page,
ship.id,
pilot.id,
(s) => s.pilots.find((p) => p.id === pilot.id)!.level >= 1,
);
// Get the Lighter to the Moon, and wait for a Heavy Cargo 1 job it can carry there.
await flyUntil(
page,
ship.id,
pilot.id,
(s) => s.ships.find((x) => x.id === ship.id)!.locationId === "moon",
);
const heavyJobs = async () =>
(await board(page, "moon")).contracts.filter(
(c) =>
c.requiredSkill?.skillId === "heavy-cargo" &&
c.requiredSkill.level === 1 &&
c.massTonnes <= 80 &&
c.requiredLongHaulLevel === 0,
);
// Boards show only jobs the fleet can complete (CR-019): no one has Heavy Cargo yet.
for (const contract of (await board(page, "moon")).contracts) {
expect(contract.requiredSkill?.skillId).not.toBe("heavy-cargo");
}
// The pilot spends a point in Heavy Cargo...
await page.goto("/pilots");
await page.getByRole("button", { name: `Raise Heavy Cargo for ${pilot.name}` }).click();
await expect
.poll(
async () =>
(await state(page)).pilots.find((p) => p.id === pilot.id)!.skills["heavy-cargo"],
)
.toBe(1);
// ...and from a later board period, Heavy Cargo 1 jobs are offered at the Moon.
let job = (await heavyJobs())[0];
for (let k = 0; !job && k < 60; k++) {
await advance(page, content.config.contractBoardPeriodRealMinutes * 60_000);
job = (await heavyJobs())[0];
}
expect(job, "a Heavy Cargo 1 job at the Moon").toBeDefined();
await acknowledgeAll(page);
const resting = (await state(page)).pilots.find((p) => p.id === pilot.id)!.restEndsAt;
if (resting !== null) await advanceTo(page, resting);
// The Lighter's pair can take it in the dispatch sheet.
await page.goto("/contracts?location=moon");
const card = page
.getByRole("row")
.filter({ hasText: content.good(job!.goodId)!.name })
.filter({ hasText: `${job!.massTonnes} t` });
await card.getByRole("button", { name: "Dispatch" }).first().click();
await expect(page.locator(`input[name="pair"][value="${ship.id}"]`)).toBeEnabled();
// CR-004: Long Haul raises the duty limit.
const limitBefore = (await state(page)).pilots.find((p) => p.id === pilot.id)!.dutyLimit;
await page.goto("/pilots");
await page.getByRole("button", { name: `Raise Long Haul for ${pilot.name}` }).click();
await expect
.poll(async () => (await state(page)).pilots.find((p) => p.id === pilot.id)!.dutyLimit)
.toBe(limitBefore + content.config.longHaulDutyBonusGameHours);
});
});