mirror of
https://github.com/bitbaum/substrata.git
synced 2026-12-06 04:18:16 +01:00
Material page (/resources/[slug]), one anatomy for every resource: at-a-glance tiles (world production and year, top producer and share, HHI with its method, exporters restricting it), production by country as a chartkit BarChart over the ranking table, reserves vs production as two ShareBars, year-over-year, the bottlenecks it holds up, export restrictions grouped by measure kind with counts, then each country as a <details> row (count and newest date in the summary; the top five open on desktop, all closed on a phone), events, sources. Country page (/world/[iso2]) through EntityProfile with country modules: header with roles as one scrolling row, at-a-glance tiles, what it produces as bars of world share (drawn against the whole world, so 1.6% looks like 1.6%), companies, rules, restrictions, events, related, discussion. /world?country=xx redirects there; the country entity links there. The Niger rule: a headline or a produces chart never leads with a share under 1% or a rank past 10th; those go under "Also produces, small shares". A measured uranium table (World Nuclear Association, fetched by scripts/research/wna-uranium.py into research/wna-uranium.json, joined like EIA) makes Niger read uranium first, 8th in the world. chartkit BarChart gains `max`, the value a full bar stands for. check:places-layout measures the four pages at 320/390/1440, light and dark, with chatkit's broken-word audit and chartkit's chart audit. Claude-Session: https://claude.ai/code/session_018WZnBnaLP6RhwFkLxRTKgE Co-authored-by: Claude <noreply@anthropic.com>
52 lines
2.4 KiB
TypeScript
52 lines
2.4 KiB
TypeScript
import assert from 'node:assert/strict';
|
||
import test from 'node:test';
|
||
|
||
import { MAP_ISOS } from '../app/atlas/countries';
|
||
import { NOT_A_NUMBER } from '../app/atlas/map-layer';
|
||
import { SHADINGS, shadedLayer, shadingOf } from '../app/atlas/map-shading';
|
||
import { restrictionsOn } from '../lib/resources/restrictions';
|
||
|
||
const ids = (layer: ReturnType<typeof shadedLayer>) =>
|
||
(layer.legend.measures ?? []).map((m) => m.id);
|
||
|
||
test('a URL picks a shading, and anything else falls back to production', () => {
|
||
assert.equal(shadingOf('trend'), 'trend');
|
||
assert.equal(shadingOf('reserves'), 'reserves');
|
||
assert.equal(shadingOf(undefined), 'production');
|
||
assert.equal(shadingOf('trade'), 'production', 'an unsourced shading is never drawn');
|
||
assert.equal(SHADINGS[0].id, 'production');
|
||
});
|
||
|
||
test('nickel offers every sourced shading, and the current one is marked', () => {
|
||
const layer = shadedLayer('nickel', 'reserves', MAP_ISOS);
|
||
assert.deepEqual(ids(layer), ['production', 'reserves', 'trend', 'risk']);
|
||
assert.equal(layer.legend.measures?.find((m) => m.current)?.id, 'reserves');
|
||
});
|
||
|
||
test('the trend is a one-year change from the same USGS table, on the five-step ramp', () => {
|
||
const layer = shadedLayer('nickel', 'trend', MAP_ISOS);
|
||
assert.match(layer.legend.title, /change \d{4}–\d{4}/);
|
||
assert.equal(layer.legend.scale?.length, 5);
|
||
const bins = Object.values(layer.bins);
|
||
assert.ok(bins.length > 0);
|
||
assert.ok(bins.every((b) => (b >= 1 && b <= 5) || b === NOT_A_NUMBER));
|
||
for (const [iso, b] of Object.entries(layer.bins))
|
||
if (b !== NOT_A_NUMBER) assert.match(layer.labels[iso], /^[+−]?\d/, `${iso} reads as a change`);
|
||
});
|
||
|
||
test('the risk layer counts OECD export restrictions and never calls absence safe', () => {
|
||
const resource = 'nickel';
|
||
const layer = shadedLayer(resource, 'risk', MAP_ISOS);
|
||
const countries = new Set(restrictionsOn(resource).map((r) => r.iso2));
|
||
assert.ok(countries.size > 0, 'the inventory records nickel measures');
|
||
assert.equal(Object.keys(layer.bins).length, countries.size);
|
||
assert.match(layer.otherwise ?? '', /None recorded/);
|
||
assert.match(layer.legend.note ?? '', /not the same as unrestricted/);
|
||
});
|
||
|
||
test('a resource without a country table offers no trend, and a missing shading falls back', () => {
|
||
const neon = shadedLayer('neon', 'trend', MAP_ISOS);
|
||
assert.ok(!ids(neon).includes('trend'));
|
||
assert.deepEqual(neon.bins, {}, 'no quantity, no shade');
|
||
});
|