Files
Battle-for-Tismo/tests/line_chart_test.js
T
adrien c2f131da5c Turned tile improvements into construction sites with their own budgets
Every road, railway and tile work now rises as an economic construction site instead of a queue entry. A site gathers its materials over days from reachable regions, refusing any supplier quoting above the price it was budgeted at (a 1% tolerance); a day that buys nothing stalls the site, raising a red mark and letting the nation raise the budget to current prices or cancel it. The upfront budget covers the build cost plus the market value of its steel and high-tech, energy stays a grid draw, and any money left over stays with the finished work as a maintenance reserve.

That reserve now pays the work's own daily steel and high-tech wear before the treasury is billed, so a well funded work spares the state until it runs dry; the spent money is paid into the nation's regions. Building upgrades run through the same gather-build-maintain machinery, sharing the site's kind flag and target level. The legacy tile-work queue and the market building are gone.

Bundles the in-progress chart sizing for the central bank panel.
2026-09-22 18:08:31 +02:00

41 lines
1.6 KiB
JavaScript

import { TestCase } from "./framework/test_case.js";
import { setupDom, teardownDom } from "./framework/dom.js";
import { lineChart } from "../client/js/ui/line_chart.js";
// The central bank sizes the chart to its panel and caps the height, so the
// chart must honour an explicit width/height instead of always drawing at its
// own default aspect ratio.
export class LineChartTest extends TestCase {
async test_chart_honours_the_requested_size() {
const env = await setupDom();
try {
const svg = lineChart(
[
{ label: "Energy", colour: "#ff0000", values: [100, 120] },
{ label: "Food", colour: "#00ff00", values: [100, 90] },
],
{ width: 800, height: 200, xLabel: (i) => `M${i}` }
);
this.assertEqual(svg.getAttribute("viewBox"), "0 0 800 200", "the viewBox uses the options");
this.assertEqual(svg.getAttribute("width"), "800", "the width attribute uses the options");
this.assertEqual(svg.getAttribute("height"), "200", "the height attribute uses the options");
this.assertSize(svg.querySelectorAll(".line-chart-line"), 2, "one line per series");
this.assertSize(
svg.querySelectorAll(".line-chart-baseline"), 1, "the baseline is drawn"
);
} finally {
teardownDom(env);
}
}
async test_chart_defaults_to_a_small_size() {
const env = await setupDom();
try {
const svg = lineChart([{ values: [100] }]);
this.assertEqual(svg.getAttribute("viewBox"), "0 0 320 150", "an unset size keeps the default");
} finally {
teardownDom(env);
}
}
}