mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 16:22:20 +00:00
Fold duplicate coverage tests into their neighbours
This commit is contained in:
1 parent
5c4918affb
commit
ea76fc4bc0
9 files changed
+94
-328
No files matched your search
@@ -1,121 +0,0 @@
|
||||
// BIKESHARE COVERAGE STATUS — a view with no system says so.
|
||||
//
|
||||
// With no system in range (London, Tokyo) the layer says why instead of
|
||||
// "never", and keeps no date for data it no longer draws.
|
||||
//
|
||||
// Run with: npm test
|
||||
import { test } from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { createState } from './state.js';
|
||||
import { createControls } from './controls.js';
|
||||
import { createModel } from './model.js';
|
||||
import { createViewport } from './viewport.js';
|
||||
import { GBFS_CITY_REGISTRY } from './registry.js';
|
||||
|
||||
const LONDON = { lat: 51.5072, lon: -0.1276 };
|
||||
|
||||
function makeLayer() {
|
||||
const services = {
|
||||
overlays: {
|
||||
setOverlayEntries() {},
|
||||
setOverlaySourceVisible() {},
|
||||
clearOverlaySource() {},
|
||||
},
|
||||
render: { governorRequestRender() {} },
|
||||
};
|
||||
const state = createState({ services });
|
||||
const parts = {
|
||||
queries: { collectDetectableStations: () => [] },
|
||||
model: createModel({ state, services, parts: {}, source: null }),
|
||||
ingestion: { abortInFlight() {} },
|
||||
rendering: { removeCityPoints() {} },
|
||||
};
|
||||
parts.viewport = createViewport({ state, services, parts, source: null });
|
||||
const { methods } = createControls({ state, services, parts, source: {} });
|
||||
state._enabled = true;
|
||||
return { state, methods, viewport: parts.viewport };
|
||||
}
|
||||
|
||||
/** A viewer looking straight down at `at` from `height` metres. */
|
||||
function viewerAt(at, height) {
|
||||
const rad = Math.PI / 180;
|
||||
return {
|
||||
camera: {
|
||||
positionCartographic: {
|
||||
height,
|
||||
latitude: at.lat * rad,
|
||||
longitude: at.lon * rad,
|
||||
},
|
||||
computeViewRectangle: () => undefined,
|
||||
},
|
||||
scene: { globe: {} },
|
||||
};
|
||||
}
|
||||
|
||||
test('above the altitude gate the row says how low to fly', async () => {
|
||||
const { state, methods, viewport } = makeLayer();
|
||||
state._viewer = viewerAt(LONDON, 2_000_000);
|
||||
await viewport.runProximityCheck();
|
||||
|
||||
const stats = methods.getStats();
|
||||
assert.equal(stats.status, 'zoom-in');
|
||||
assert.equal(stats.statusMessage, 'Fly below 48 km to a covered city');
|
||||
assert.equal(stats.error, undefined);
|
||||
});
|
||||
|
||||
test('a city with no system says so and counts the ones there are', async () => {
|
||||
const { state, methods, viewport } = makeLayer();
|
||||
state._viewer = viewerAt(LONDON, 8_000);
|
||||
await viewport.runProximityCheck();
|
||||
|
||||
const stats = methods.getStats();
|
||||
assert.equal(stats.status, 'zoom-in');
|
||||
assert.equal(
|
||||
stats.statusMessage,
|
||||
`No bike share here yet · ${GBFS_CITY_REGISTRY.length} systems available`,
|
||||
);
|
||||
assert.equal(stats.count, 0);
|
||||
});
|
||||
|
||||
test('a city with a system in range is not given the prompt', () => {
|
||||
const { state, methods } = makeLayer();
|
||||
state._altitudeGateEnabled = true;
|
||||
state._activeCityIds.add('boston-bluebikes');
|
||||
|
||||
assert.equal(methods.getStats().status, undefined);
|
||||
});
|
||||
|
||||
test('a loading or failed city reports itself, not the prompt', () => {
|
||||
const { state, methods } = makeLayer();
|
||||
state._altitudeGateEnabled = true;
|
||||
state._loading = true;
|
||||
assert.equal(methods.getStats().status, undefined);
|
||||
|
||||
// A city that failed is dropped from range, and still owns the row.
|
||||
state._loading = false;
|
||||
state._failedCityIds.add('boston-bluebikes');
|
||||
const stats = methods.getStats();
|
||||
assert.equal(stats.status, undefined);
|
||||
assert.equal(stats.error, 'GBFS fetch error');
|
||||
});
|
||||
|
||||
test('a disabled layer reports no prompt', () => {
|
||||
const { state, methods } = makeLayer();
|
||||
state._enabled = false;
|
||||
assert.equal(methods.getStats().status, undefined);
|
||||
});
|
||||
|
||||
test('leaving every system behind drops the date of the data it drew', async () => {
|
||||
for (const height of [8_000, 2_000_000]) {
|
||||
const { state, methods, viewport } = makeLayer();
|
||||
state._lastUpdate = Date.now();
|
||||
// Boston's stations were drawn and dated; the camera moves to London.
|
||||
state._activeCityIds.add('boston-bluebikes');
|
||||
state._cityRuntime.set('boston-bluebikes', {});
|
||||
state._viewer = viewerAt(LONDON, height);
|
||||
await viewport.runProximityCheck();
|
||||
|
||||
assert.equal(state._activeCityIds.size, 0);
|
||||
assert.equal(methods.getStats().lastUpdate, null, `at ${height} m`);
|
||||
}
|
||||
});
|
||||
@@ -1,11 +1,13 @@
|
||||
// Bike Share: after the camera settles, the last row the panel painted must
|
||||
// match what the layer reports now. Each case drives the real viewport,
|
||||
// Bike Share's Layers row. With no system in range it says why instead of
|
||||
// "never" and keeps no date for data it no longer draws. After the camera
|
||||
// settles, the last row the panel painted must match what the layer reports
|
||||
// now. Each case drives the real viewport,
|
||||
// ingestion, rendering and controls; the manager is a spy that records the
|
||||
// row text (LayerPanel._buildMetaText) at every refreshLayerStats() call.
|
||||
import { test } from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import * as Cesium from 'cesium';
|
||||
import { CITY_BY_ID } from './registry.js';
|
||||
import { CITY_BY_ID, GBFS_CITY_REGISTRY } from './registry.js';
|
||||
import { createState } from './state.js';
|
||||
import { createControls } from './controls.js';
|
||||
import { createIngestion } from './ingestion.js';
|
||||
@@ -175,6 +177,7 @@ function makeLiveLayer() {
|
||||
source,
|
||||
painted,
|
||||
lastPainted: () => painted.at(-1),
|
||||
stats: () => controls.getStats(),
|
||||
live: () => rowText(controls.getStats()),
|
||||
moveTo(place, height = LOW_M) {
|
||||
Object.assign(camera, place, { height });
|
||||
@@ -291,3 +294,73 @@ test('leaving the failed city of two repaints DEGRADED away', async () => {
|
||||
assert.doesNotMatch(layer.live(), /^degraded/);
|
||||
assert.equal(layer.lastPainted(), layer.live());
|
||||
});
|
||||
|
||||
test('above the altitude gate the row says how low to fly', async () => {
|
||||
const layer = makeLiveLayer();
|
||||
await layer.enable();
|
||||
await layer.moveTo(LONDON, 2_000_000);
|
||||
const stats = layer.stats();
|
||||
assert.equal(stats.status, 'zoom-in');
|
||||
assert.equal(stats.statusMessage, 'Fly below 48 km to a covered city');
|
||||
assert.equal(stats.error, undefined);
|
||||
});
|
||||
|
||||
test('a city with no system says so and counts the ones there are', async () => {
|
||||
const layer = makeLiveLayer();
|
||||
await layer.enable();
|
||||
const stats = layer.stats();
|
||||
assert.equal(stats.status, 'zoom-in');
|
||||
assert.equal(
|
||||
stats.statusMessage,
|
||||
`No bike share here yet · ${GBFS_CITY_REGISTRY.length} systems available`,
|
||||
);
|
||||
assert.equal(stats.count, 0);
|
||||
});
|
||||
|
||||
test('a city in range, loading, failed or a disabled layer gets no prompt', async () => {
|
||||
const layer = makeLiveLayer();
|
||||
assert.equal(layer.stats().status, undefined, 'disabled');
|
||||
|
||||
const info = deferred();
|
||||
layer.source.gates.set(`${BOSTON_ID}:info`, info);
|
||||
await layer.enable();
|
||||
const entering = layer.moveTo(BOSTON);
|
||||
assert.equal(layer.stats().status, undefined, 'loading');
|
||||
info.resolve();
|
||||
await entering;
|
||||
await settle();
|
||||
assert.equal(layer.stats().status, undefined, 'loaded');
|
||||
|
||||
// Left mid-load: range is empty, but the aborted load still owns the row.
|
||||
const leaving = makeLiveLayer();
|
||||
leaving.source.gates.set(`${BOSTON_ID}:info`, deferred());
|
||||
await leaving.enable();
|
||||
const loading = leaving.moveTo(BOSTON);
|
||||
await settle();
|
||||
const left = leaving.moveTo(LONDON);
|
||||
assert.equal(leaving.state._activeCityIds.size, 0);
|
||||
assert.equal(leaving.stats().loading, true);
|
||||
assert.equal(leaving.stats().status, undefined, 'leaving mid-load');
|
||||
await Promise.all([loading, left]);
|
||||
|
||||
const failed = makeLiveLayer();
|
||||
failed.source.dead.add(BOSTON_ID);
|
||||
await failed.enable();
|
||||
await failed.moveTo(BOSTON);
|
||||
await settle();
|
||||
assert.equal(failed.stats().status, undefined, 'failed');
|
||||
assert.equal(failed.stats().error, 'GBFS fetch error');
|
||||
});
|
||||
|
||||
test('leaving every system behind drops the date of the data it drew', async () => {
|
||||
for (const height of [LOW_M, 2_000_000]) {
|
||||
const layer = makeLiveLayer();
|
||||
await layer.enable();
|
||||
await layer.moveTo(BOSTON);
|
||||
await settle();
|
||||
assert.ok(layer.stats().lastUpdate, 'Boston is dated');
|
||||
|
||||
await layer.moveTo(LONDON, height);
|
||||
assert.equal(layer.stats().lastUpdate, null, `at ${height} m`);
|
||||
}
|
||||
});
|
||||
@@ -243,11 +243,9 @@ export function createViewport({ state: layerState, services, parts, source }) {
|
||||
nextActive.size !== layerState._activeCityIds.size ||
|
||||
[...nextActive].some((cityId) => !layerState._activeCityIds.has(cityId));
|
||||
layerState._activeCityIds = nextActive;
|
||||
if (layerState._activeCityIds.size === 0) {
|
||||
if (nextActive.size === 0) {
|
||||
layerState._count = 0;
|
||||
layerState._lastUpdate = null;
|
||||
if (changed) refreshRow();
|
||||
return;
|
||||
}
|
||||
if (changed) refreshRow();
|
||||
|
||||
|
||||
Reference in new issue
Block a user