test: avoid duplicate chart and legacy UI fixture runs

This commit is contained in:
coyotte508 2026-11-15 22:33:54 +00:00
commit dc59294a89
4 changed files with 54 additions and 34 deletions

View file

@ -280,6 +280,41 @@ terrans booster booster3`)
});
}
// Chat forwarding and the Beta-2 federation fixture are invariant across scenarios.
// Keep one real base -> federation update to cover replacing an already-rendered map.
it("forwards platform chat and renders federation paths after a state replacement", async () => {
const host = document.createElement("div");
host.id = "old-test";
document.body.append(host);
const viewer = launch("#old-test");
try {
const engine = new Engine(["init 3 old-test", "p1 faction terrans", "p2 faction nevlas", "p3 faction firaks"]);
viewer.emit("state", JSON.parse(JSON.stringify(engine)));
viewer.emit("preferences", { platformChat: true });
viewer.emit("chat:state", { canSend: true });
viewer.emit("chat:messages", [{ type: "text", author: "Teammate", text: "Ready to explore" }]);
await vi.waitFor(() => expect(viewer.app.$el.querySelector(".old-map-canvas")).not.toBeNull());
expect(document.querySelector(".bgs-game-chat, .chat-shortcut")).toBeNull();
const openChat = vi.fn();
viewer.on("chat:open", openChat);
const chatButton = document.querySelector<HTMLButtonElement>(".game-chat-button")!;
expect(chatButton.hidden).toBe(false);
chatButton.click();
expect(openChat).toHaveBeenCalledOnce();
const fedFixture = federationFixture();
viewer.emit("state", fedFixture);
await vi.waitFor(() => {
expect(viewer.app.$el.querySelectorAll("path.federation-path--color").length).toBeGreaterThan(0);
});
// No dangling <use> references to the removed global federation defs
expect(viewer.app.$el.querySelectorAll("use[xlink\\:href^='#federation']").length).toBe(0);
} finally {
viewer.app.$destroy();
document.body.replaceChildren();
}
});
for (const id of ["base", ...selfContainedScenarios.map((s) => s.id)]) {
it(`renders the actual old player/map components and current controls for ${id}`, async () => {
const host = document.createElement("div");
@ -292,9 +327,6 @@ terrans booster booster3`)
? new Engine(["init 3 old-test", "p1 faction terrans", "p2 faction nevlas", "p3 faction firaks"])
: loadScenarioEngine(id);
viewer.emit("state", JSON.parse(JSON.stringify(engine)));
viewer.emit("preferences", { platformChat: true });
viewer.emit("chat:state", { canSend: true });
viewer.emit("chat:messages", [{ type: "text", author: "Teammate", text: "Ready to explore" }]);
await vi.waitFor(() => expect(viewer.app.$el.querySelector(".old-map-canvas")).not.toBeNull());
expect(viewer.app.$el.querySelector(".old-ui-game")).not.toBeNull();
expect(viewer.app.$el.querySelector(".old-map-canvas")).not.toBeNull();
@ -316,21 +348,6 @@ terrans booster booster3`)
for (const action of viewer.app.$el.querySelectorAll(".old-board-action")) {
expect(action.getAttribute("transform")).toMatch(/^translate\(/);
}
expect(document.querySelector(".bgs-game-chat, .chat-shortcut")).toBeNull();
const openChat = vi.fn();
viewer.on("chat:open", openChat);
const chatButton = document.querySelector<HTMLButtonElement>(".game-chat-button")!;
expect(chatButton.hidden).toBe(false);
chatButton.click();
expect(openChat).toHaveBeenCalledOnce();
const fedFixture = federationFixture();
viewer.emit("state", fedFixture);
await vi.waitFor(() => {
expect(viewer.app.$el.querySelectorAll("path.federation-path--color").length).toBeGreaterThan(0);
});
// No dangling <use> references to the removed global federation defs
expect(viewer.app.$el.querySelectorAll("use[xlink\\:href^='#federation']").length).toBe(0);
} finally {
viewer.app.$destroy();
document.body.replaceChildren();

View file

@ -0,0 +1,17 @@
import type Engine from "@gaia-project/engine";
import type { ChartSetup } from "./chart-factory";
export function createTestChartConfig(setup: ChartSetup, chartSelect: string, chartType: string, engine: Engine) {
const config = setup.newBarChart(
{
type: "table",
label: "Table",
compact: false,
},
setup.factory(chartSelect, chartType),
engine,
(c) => c
);
delete config.table.descriptions;
return config;
}

View file

@ -2,24 +2,10 @@ import Engine, { Faction, LogEntry, Player, ResearchField, Reward } from "@gaia-
import { expect } from "chai";
import { runJsonTests } from "../test-utils";
import { ChartSetup } from "./chart-factory";
import { createTestChartConfig } from "./chart-test-utils";
import type { ChartType } from "./charts";
import { countResearch, ResearchCounter } from "./research";
export function createTestChartConfig(setup: ChartSetup, chartSelect: string, chartType: string, engine: Engine) {
const config = setup.newBarChart(
{
type: "table",
label: "Table",
compact: false,
},
setup.factory(chartSelect, chartType),
engine,
(c) => c
);
delete config.table.descriptions;
return config;
}
describe("Chart", () => {
describe("initial research", () => {
it("counts income board research as starting levels", () => {

View file

@ -17,7 +17,7 @@ import { parseCommands } from "../recent";
import { createFixtureEngine, findFirstBad, runMoveHistoryTests } from "../test-utils";
import { balanceSheetResourceName, balanceSheetResources, currentAmount } from "./balance-sheet";
import { ChartSetup } from "./chart-factory";
import { createTestChartConfig } from "./chart.spec";
import { createTestChartConfig } from "./chart-test-utils";
import { ChartGroup } from "./charts";
import {
BrainstoneSimulator,