deadhead-space-freight-tycoon/apps/web/test/veteran-ui.test.tsx

65 lines
2.2 KiB
TypeScript

import { pilotExtras } from "./fixtures";
import { content } from "@deadhead/content";
import type { Pilot } from "@deadhead/schema";
import { screen, within } from "@testing-library/react";
import { describe, expect, it } from "vitest";
import { fakeApi, renderApp, samplePlayerState, sampleTutorialBoard } from "./render";
const veteran = content.veteranPilot;
describe("the veteran in the UI (Step 10J.5)", () => {
it("names the veteran with their bio in the deal modal", async () => {
renderApp(
fakeApi({
getPlayerState: () =>
samplePlayerState({
tutorial: {
loanerLocationId: "earth",
runInFlight: false,
runsCompleted: 4,
dealAvailable: true,
},
}),
getTutorialBoard: () => sampleTutorialBoard(),
}),
"/contracts",
);
const modal = await screen.findByRole("dialog", { name: "An offer from Halvorsen" });
expect(within(modal).getByLabelText("Veteran pilot")).toHaveTextContent(
`…and ${veteran.name}. ${veteran.bio}`,
);
});
it("shows the veteran's bio, level and Heavy Cargo 1 on the Pilots screen", async () => {
const rosa: Pilot = {
id: "p-vet",
name: veteran.name,
isAvatar: false,
isVeteran: true,
xp: content.config.pilotLevelXpThresholds[1]!,
level: 2,
skills: { "heavy-cargo": 1 },
skillPointsAvailable: 3,
assignedShipId: null,
status: "idle",
locationId: "earth",
dutyHours: 0,
dutyLimit: 12,
resting: false,
restEndsAt: null,
...pilotExtras,
};
const base = samplePlayerState({ tutorial: null, bays: [{ id: "b", locationId: "earth" }] });
renderApp(
fakeApi({ getPlayerState: () => ({ ...base, pilots: [...base.pilots, rosa] }) }),
"/pilots",
);
const card = (await screen.findByText(veteran.name)).closest("li")!;
expect(within(card).getByLabelText(`${veteran.name} bio`)).toHaveTextContent(veteran.bio);
expect(card).toHaveTextContent("Level 2");
expect(card).toHaveTextContent("Heavy Cargo 1/5");
// The avatar's card has no bio line.
expect(screen.queryByLabelText("Captain bio")).not.toBeInTheDocument();
});
});