import { expect, test } from "@playwright/test"; import { dispatchFromEarthBoard, logbook, playToDeal, serverNow, state } from "./support"; test.describe("end to end (Phase 12)", () => { test("12.4: a delivery that lands while the app is closed shows on return", async ({ page, context, }) => { await playToDeal(page); const dispatchId = await dispatchFromEarthBoard(page); const before = await state(page); const flight = before.activeDispatches.find((d) => d.id === dispatchId)!; // Close the app; it opens again after the arrival time (the developer clock // offset is moved on before the new page loads, as if time had passed). const skip = flight.arrivalAt - (await serverNow(page)) + 1_000; const offset = await page.evaluate(() => Number(localStorage.getItem("deadhead:dev-clock-offset") ?? 0), ); await page.close(); const later = await context.newPage(); await later.addInitScript( (value) => localStorage.setItem("deadhead:dev-clock-offset", String(value)), offset + skip, ); await later.goto("/"); const summary = (await state(later)).summaries.find((s) => s.dispatchId === dispatchId)!; await expect(logbook(later)).toContainText(`Delivered ${summary.massTonnes} t`); const after = await state(later); // Credits went up by the delivery's net payout, less any Auto top-up on landing // (CR-015); the ship is at the destination. expect(after.company.credits).toBe( before.company.credits + summary.credits - (summary.topUp?.cost ?? 0), ); expect(after.ships.find((s) => s.id === flight.shipId)!.locationId).toBe(flight.destinationId); }); });