v0.28.0 (#46): per-region stats — area×population-weighted-median Nation.stats (PR 1 of 2)
CI / build + unit + e2e (pull_request) Successful in 2m34s
CI / build + unit + e2e (pull_request) Successful in 2m34s
This commit is contained in:
@@ -7,8 +7,10 @@ import {
|
||||
allTerritoryKeys,
|
||||
centroidOf,
|
||||
expandCountriesToKeys,
|
||||
geoOf,
|
||||
hasAdjacency,
|
||||
hasCentroids,
|
||||
hasGeo,
|
||||
hasRegionData,
|
||||
loadRegions,
|
||||
neighboursOf,
|
||||
@@ -106,6 +108,8 @@ describe('regions (region-key loader, v0.19 #16 P1)', () => {
|
||||
unowned: [],
|
||||
pendingNationOps: [],
|
||||
markers: [],
|
||||
// (v0.28, #46) unused here (allTerritoryKeys is ownership-only).
|
||||
regionStats: {},
|
||||
};
|
||||
// 16 GBR sub-regions + 42 FRA sub-regions, no overlap between the two.
|
||||
expect(allTerritoryKeys(state).size).toBe(58);
|
||||
@@ -149,6 +153,21 @@ describe('regions (region-key loader, v0.19 #16 P1)', () => {
|
||||
expect(centroidOf('not-a-real-key-xyz')).toBeUndefined();
|
||||
});
|
||||
|
||||
it('(v0.28 #46) hasGeo() is true and geoOf resolves a real key to area + population', () => {
|
||||
expect(hasGeo()).toBe(true);
|
||||
const ain = geoOf('ain-lqtt');
|
||||
expect(ain).toBeDefined();
|
||||
expect(ain!.area).toBeGreaterThanOrEqual(0); // km²
|
||||
expect(ain!.population).toBeGreaterThanOrEqual(0);
|
||||
// exact spot-check values pinned from the committed manifest (Ain, FRA)
|
||||
expect(ain!.area).toBeCloseTo(22557.77, 1); // km²
|
||||
expect(ain!.population).toBe(2304126);
|
||||
});
|
||||
|
||||
it('(v0.28 #46) geoOf returns undefined for an unknown key', () => {
|
||||
expect(geoOf('not-a-real-key-xyz')).toBeUndefined();
|
||||
});
|
||||
|
||||
describe('graceful degradation with no region data', () => {
|
||||
beforeEach(() => resetRegions());
|
||||
|
||||
@@ -165,6 +184,9 @@ describe('regions (region-key loader, v0.19 #16 P1)', () => {
|
||||
// and no centroids: the marker-placement path degrades to a no-op
|
||||
expect(hasCentroids()).toBe(false);
|
||||
expect(centroidOf('ain-lqtt')).toBeUndefined();
|
||||
// and no region-geo: the per-region stats weighting degrades to uniform
|
||||
expect(hasGeo()).toBe(false);
|
||||
expect(geoOf('ain-lqtt')).toBeUndefined();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -219,6 +241,9 @@ describe('loadRegions resolves the manifest per environment (dev public/ vs prod
|
||||
// and no centroids (not copied into this dist/) -> marker placement degrades
|
||||
expect(hasCentroids()).toBe(false);
|
||||
expect(centroidOf('ain-lqtt')).toBeUndefined();
|
||||
// and no region-geo (not copied into this dist/) -> stats weighting is uniform
|
||||
expect(hasGeo()).toBe(false);
|
||||
expect(geoOf('ain-lqtt')).toBeUndefined();
|
||||
});
|
||||
|
||||
it('(v0.27 #44) a dist/ WITH the centroids manifest loads them (prod layout)', () => {
|
||||
@@ -233,6 +258,19 @@ describe('loadRegions resolves the manifest per environment (dev public/ vs prod
|
||||
expect(ain!.lat).toBeCloseTo(46.16, 1);
|
||||
});
|
||||
|
||||
it('(v0.28 #46) a dist/ WITH the region-geo manifest loads it (prod layout)', () => {
|
||||
copyFileSync(
|
||||
path.join(realRoot, 'public', 'region-geo.json'),
|
||||
path.join(prodRoot, 'dist', 'region-geo.json'),
|
||||
);
|
||||
expect(loadRegions(prodRoot)).toBe(true);
|
||||
expect(hasGeo()).toBe(true);
|
||||
const ain = geoOf('ain-lqtt');
|
||||
expect(ain).toBeDefined();
|
||||
expect(ain!.area).toBeCloseTo(22557.77, 1);
|
||||
expect(ain!.population).toBe(2304126);
|
||||
});
|
||||
|
||||
it('returns false and no data when neither public/ nor dist/ holds the files', () => {
|
||||
const emptyRoot = path.join(base, 'empty');
|
||||
mkdirSync(emptyRoot, { recursive: true });
|
||||
|
||||
Reference in New Issue
Block a user