forked from code/member-dashboard
dashboard: the co-op charts come from the shared definitions (Money included)
The dashboard kept its own TREND_CONF with its own titles ("The co-op over time",
"What the co-op spent (members + the co-op's own accounts)") and its own toggles —
the other half of the drift the panel just lost. The metric list is now
CoOpChart.CHART_METRICS, the chart is drawn by the shared renderChart(), and the
buttons are built from the shared list, so members and stewards read the same
charts with the same names.
Money arrives as a metric here too, fed by a new /api/money-series proxy to the
portal's /broker/money-series — the co-op's cumulative revenue, cumulative token
spend and OC balance (a gap before snapshots began, never a zero). Deleting the
local TREND_CONF/trendVal/trendLabel also removes the second set of formatters.
Two page-blanking bugs caught by check-page-js.sh before they could ship: a
destructured fmtMoney colliding with this page's own (duplicate const), and `esc`
(which the panel defines and this page does not — it uses escapeHtml).
Harness extended: the money metric draws 2 lines + a single-point balance marker,
the tooltip lists every series and reports the unmeasured balance as not
measured, the metric row equals the shared list filtered by METRIC_SOURCE, and a
metric with no source says so. Geometry proof: 15 captured renders (5 metrics x 3
ranges) byte-identical to the predecessor with aria stripped.
This commit is contained in:
1 parent
c5d4677ec3
commit
d10b817fdc
2 files changed
+169
-71
No files matched your search
@@ -124,5 +124,52 @@ function mkDaily() {
|
||||
assert(box.style.display === "none", "tooltip hides off-chart");
|
||||
}
|
||||
|
||||
// ---- the money metric: the SHARED definition, the same chart the panel draws ----
|
||||
{
|
||||
moneyData = { series: [
|
||||
{ day: "2026-11-01", revenue_cum: 100, spend_cum: 20, oc_balance: null },
|
||||
{ day: "2026-11-02", revenue_cum: 220, spend_cum: 45, oc_balance: null },
|
||||
{ day: "2026-11-03", revenue_cum: 260, spend_cum: 51, oc_balance: 1160.25 },
|
||||
] };
|
||||
setTrendMetric("money");
|
||||
const body = document.getElementById("trend-body").innerHTML;
|
||||
const def = metricDef("money");
|
||||
assert(def.series.length === 3, "the shared money definition carries 3 series");
|
||||
assert((body.match(/<polyline /g) || []).length === 2,
|
||||
"money chart draws revenue + spend as lines");
|
||||
assert(/<circle cx="[^"]+" cy="[^"]+" r="3"/.test(body),
|
||||
"the balance (one measured day) renders as a marker, not a line through gaps");
|
||||
const legend = document.getElementById("trend-legend").innerHTML;
|
||||
for (const sr of def.series) {
|
||||
assert(legend.indexOf(sr.name) !== -1, "legend is the definition's series: " + sr.name);
|
||||
}
|
||||
const pts = chartTipData["trend-body"];
|
||||
assert(pts[0].series.length === 3, "the tooltip lists EVERY series at that x");
|
||||
assert(pts[0].series[2][1] === "not measured",
|
||||
"the balance before snapshots began reads not measured, never $0.00");
|
||||
assert(pts[2].series[2][1] === "$1,160.25" || pts[2].series[2][1] === "$1160.25",
|
||||
"the balance value is exact (got " + pts[2].series[2][1] + ")");
|
||||
|
||||
// The metric row comes from the shared list, filtered to what this page can fetch.
|
||||
buildMetricButtons();
|
||||
let expected = 0;
|
||||
for (const m of CHART_METRICS) if (METRIC_SOURCE[m.id]) expected++;
|
||||
let rendered = 0;
|
||||
for (const m of CHART_METRICS) if (document.getElementById("tm-" + m.id)) rendered++;
|
||||
assert(rendered === expected && expected === 6,
|
||||
"every shared metric this page can fetch has a button (got " + rendered + "/" + expected + ")");
|
||||
assert(document.getElementById("tm-money") !== null,
|
||||
"Money is a metric here too, not an admin-only tab");
|
||||
|
||||
// A metric in the shared list with no source here must SAY so.
|
||||
const savedIntro = METRIC_SOURCE.energy;
|
||||
delete METRIC_SOURCE.energy;
|
||||
setTrendMetric("energy");
|
||||
assert(document.getElementById("trend-body").innerHTML.indexOf("Not available here") !== -1,
|
||||
"a metric this page cannot fetch says so instead of drawing another chart");
|
||||
METRIC_SOURCE.energy = savedIntro;
|
||||
buildMetricButtons();
|
||||
}
|
||||
|
||||
console.log("DASHBOARD CHART HARNESS OK: shared module tooltips, exact values, gaps, toggles");
|
||||
})().catch((e) => { console.error("FAIL: " + (e && e.stack || e)); process.exit(1); });
|
||||
Reference in new issue
Block a user