deadhead-space-freight-tycoon/apps/web/test/fixtures.ts

101 lines
3.0 KiB
TypeScript

import { content } from "@deadhead/content";
import type { Pilot, PlayerState, Ship } from "@deadhead/schema";
import { effectiveStats } from "@deadhead/sim";
// Plain data builders shared by component tests and the Playwright tests (no Vitest imports).
/**
* The CR-009 fields of a ship with no upgrades and not in the shop: its model's
* stats as effective stats. Spread into Ship fixtures, then override as needed.
*/
export function shipExtras(
modelId: string,
upgrades: Record<string, number> = {},
): Pick<
Ship,
"upgrades" | "stats" | "inShopUntil" | "shop" | "fuelFu" | "fuelAvgPrice" | "refuelPolicy"
> {
const model = content.shipModel(modelId);
if (!model) throw new Error(`Unknown ship model ${modelId}`);
const s = effectiveStats(model, upgrades, content);
return {
upgrades,
stats: {
cruiseSpeedKmPerGameHour: s.cruiseSpeedKmPerGameHour,
cargoCapacityTonnes: s.cargoCapacityTonnes,
tankCapacityFu: s.tankCapacityFu,
burnFuPerMillionKm: s.burnFuPerMillionKm,
overheadGameHours: s.overheadGameHours,
handlingGameHoursPerTonne: s.handlingGameHoursPerTonne,
},
inShopUntil: null,
shop: null,
// A full tank bought at Earth (CR-015).
fuelFu: s.tankCapacityFu,
fuelAvgPrice: 16,
refuelPolicy: "auto",
};
}
/** CR-021 and CR-023 fields of a Manual pilot with default orders, home at Earth, not in the shop. Spread into Pilot fixtures. */
export const pilotExtras: Pick<Pilot, "mode" | "orders" | "restingInShopUntil"> = {
mode: "manual",
restingInShopUntil: null,
orders: {
destinationIds: null,
cargoClassIds: content.cargoTypes.map((c) => c.id),
takePriority: true,
minProfit: 0,
homeLocationId: "earth",
},
};
/** A brand-new tutorial player, as guest sign-up returns it. */
export function samplePlayerState(overrides: Partial<PlayerState> = {}): PlayerState {
return {
playerId: "player-1",
company: { id: "co1", name: "Deadhead Freight", credits: 0, loanBalance: 0 },
ships: [],
pilots: [
{
id: "avatar",
name: "Captain",
isAvatar: true,
isVeteran: false,
xp: 0,
level: 0,
skills: {},
skillPointsAvailable: 0,
assignedShipId: null,
status: "idle",
locationId: "earth",
dutyHours: 0,
dutyLimit: 12,
resting: false,
restEndsAt: null,
...pilotExtras,
},
],
bays: [],
locations: [
{ id: "earth", discovered: true },
{ id: "moon", discovered: true },
{ id: "mars", discovered: false },
{ id: "ceres-station", discovered: false },
{ id: "jupiter-cloud-platform", discovered: false },
],
tutorial: {
loanerLocationId: "earth",
runInFlight: false,
runsCompleted: 0,
dealAvailable: false,
},
activeDispatches: [],
summaries: [],
goals: [],
dispatchOffice: { owned: false, spendingFloor: 500 },
welcomeSeen: true,
...overrides,
};
}