Tidy the Cockpit subject camera and HUD fixes after review

- A provider's look, height and speed are read once, so a getter that
  answers once is not lost; a Promise in a provider's words is refused and
  its rejection handled.
- A huge heading slew rate is capped at a half turn per step instead of
  overflowing to Infinity.
- A row changed in place keeps the time it first appeared; JSDoc,
  CURRENT-STATE and the ETA test say so.
- APPLICATION.md says the app page must load the entry icon's glyph.
- Tests check that entry succeeds, the vessel bridge is entered, a floor
  takes over from the entry height (also at 0 m), and share helpers;
  the provider unit test moves to the provider tests.
- WIDE_GLYPH uses escapes; comments, the release notes and CURRENT-STATE
  match the code.
This commit is contained in:
German Khokhlov committed 2026-11-18 15:07:20 +04:00
1 parent a72c0ba237
commit 109bb0fd4f
14 files changed
+279 -163

No files matched your search

+4 -8
View File
@@ -58,19 +58,15 @@ export function cockpitAnchorCorrectionStep(
return Math.min(distanceM, eased, correctionRateMps * dt);
}
/**
* How late past its interval a subject's camera update may come and still
* advance by all of it: a browser drawing a frame a second still keeps up.
*/
/** How late past its interval an update may come and still count in full. */
const COCKPIT_SUBJECT_LATE_SEC = 1;
/**
* The seconds an application subject's camera update advances its heading
* slew, ground lift and anchor by: the time since the last update, at most
* its update interval plus a second. A subject updated every 500 ms, or a
* browser drawing 5 frames a second, then turns, eases and moves at its
* configured rates, while a long stall (a hidden tab) still moves it no
* further than one late update would.
* its interval plus COCKPIT_SUBJECT_LATE_SEC. A subject updated every 500 ms,
* or a browser drawing 5 frames a second, then keeps up, while a long stall
* (a hidden tab) counts as one late update.
* @param {number} elapsedMs Time since the last camera update.
* @param {number} intervalMs The subject's update interval (0: every frame).
* @returns {number}
+6 -2
View File
@@ -30,9 +30,13 @@ const TONE_RANK = Object.freeze([
const stronger = (a, b) =>
TONE_RANK.indexOf(b) > TONE_RANK.indexOf(a) ? b : a;
/** Full-width glyphs (CJK, kana, Hangul, full-width forms): about 1 em each. */
/**
* Full-width glyphs in the BMP (CJK, kana, Hangul, full-width forms): about
* 1 em each. Astral ones (CJK extensions, emoji) are wide enough as any
* other two UTF-16 units (lineWidthPx).
*/
const WIDE_GLYPH =
/[ᄀ-ᅟ⺀-〾ぁ-㏿㐀-䶿一-鿿ꥠ-꥿가-힣豈-﫿︰-﹏＀-⦆¢-₩\u{20000}-\u{3fffd}]/u;
/[\u1100-\u115F\u2E80-\u303E\u3041-\u33FF\u3400-\u4DBF\u4E00-\u9FFF\uA960-\uA97F\uAC00-\uD7A3\uF900-\uFAFF\uFE30-\uFE4F\uFF00-\uFF60\uFFE0-\uFFE6]/;
/**
* One line's width (px) in `.cockpit-progress-label` type (cockpitSubject.css:
+6 -3
View File
@@ -155,9 +155,12 @@ test('a CJK stop name gets the width its full-width glyphs need', () => {
givenPx >= needPx,
`${givenPx} px given, about ${needPx} px needed`,
);
// Latin, and half-width katakana, keep the narrower estimate.
assert.equal(estimateProgressLabelPx({ text: 'CENTRAL' }), 7 * 6.4 + 8);
assert.equal(estimateProgressLabelPx({ text: 'カタカナ' }), 4 * 6.4 + 8);
// As many Latin letters are narrower; half-width katakana are as narrow.
assert.ok(givenPx > estimateProgressLabelPx({ text: 'CENTRALS' }));
assert.equal(
estimateProgressLabelPx({ text: 'カタカナ' }),
estimateProgressLabelPx({ text: 'KANA' }),
);
});
test('emoji and other astral glyphs in a progress label get at least 1 em each', () => {
+60 -39
View File
@@ -118,20 +118,31 @@ function lookOf(raw) {
}
/**
* A provider's worded member `key` as it reads now, normalized: the value,
* or what the function it is returns when called on `provider` (so it can
* follow the page's language); null when it is malformed or a read throws.
* Reading the member, and reading what it gives, runs provider code too (a
* getter), so both are guarded as the call is.
* A worded member's `value` normalized: the value, or what it returns when it
* is a function called on `provider` (so it can follow the page's language);
* null when it is malformed or a read throws. Reading what it gives runs
* provider code too (a getter), so it is guarded as the call is; a promise is
* malformed, and its rejection is caught rather than left unhandled.
*/
function worded(provider, value, normalize) {
try {
const words = typeof value === 'function' ? value.call(provider) : value;
if (typeof words?.then === 'function') {
Promise.resolve(words).catch(() => {});
return null;
}
return normalize(words) ?? null;
} catch {
return null;
}
}
/** A provider's worded member `key` as it reads now (see `worded`). */
function wordedNow(provider, key, normalize) {
try {
const value = provider[key];
return (
normalize(typeof value === 'function' ? value.call(provider) : value) ??
null
);
return worded(provider, provider[key], normalize);
} catch {
// A getter for the member threw.
return null;
}
}
@@ -146,12 +157,8 @@ function providerName(provider, order) {
return `#${order}`;
}
/**
* Why `provider` cannot be kept, or null. Its worded members, read once here,
* go into `words` (`face`, `labels`, `look`) to seed its copy, so one that
* fails when read again cannot undo this check.
*/
function refusal(provider, kinds, words) {
/** Why `provider` cannot be kept, its worded members aside, or null. */
function refusal(provider, kinds) {
if (!isObject(provider)) return 'not an object';
if (typeof provider.kind !== 'string' || !KIND_PATTERN.test(provider.kind))
return 'malformed kind';
@@ -169,17 +176,25 @@ function refusal(provider, kinds, words) {
typeof provider.isEntryAllowed !== 'function'
)
return 'isEntryAllowed is not a function';
words.face = wordedNow(provider, 'entryFace', faceOf);
if (!words.face) return 'malformed entry face';
words.labels = wordedNow(provider, 'labels', labelsOf);
if (!words.labels) return 'labels need view, exit and exitText';
if (provider.look != null) {
words.look = wordedNow(provider, 'look', lookOf);
if (!words.look) return 'look needs an aheadLabel';
}
return null;
}
/**
* A provider's worded members, each read once, to seed its copy (so one that
* fails when read again cannot undo this check), or why one is malformed.
* @returns {{face: object, labels: object, look: ?object}|string}
*/
function checkedWords(provider) {
const face = wordedNow(provider, 'entryFace', faceOf);
if (!face) return 'malformed entry face';
const labels = wordedNow(provider, 'labels', labelsOf);
if (!labels) return 'labels need view, exit and exitText';
const lookValue = provider.look;
if (lookValue == null) return { face, labels, look: null };
const look = worded(provider, lookValue, lookOf);
return look ? { face, labels, look } : 'look needs an aheadLabel';
}
/**
* The application's subject providers, checked once and frozen, in the order
* entry asks them: ascending `priority`, ties in list order. Each has
@@ -198,7 +213,8 @@ function refusal(provider, kinds, words) {
* object: it is called on the provider again whenever they are shown and
* when the page's language changes, so its words can follow it
* (`./i18n`). A read that throws or is malformed keeps the last
* good one; `look` is on or off and `restPitchDeg` fixed as first read;
* good one; `look` is on or off and `restPitchDeg` fixed as read at
* registration;
* - `cameraIntervalMs` (optional): 0..1000, null for the Cockpit's default; 0
* updates the camera every rendered frame;
* - `headingSlewDps` (optional): how fast the view turns to a new heading,
@@ -229,10 +245,13 @@ export function cockpitSubjectProviders(
(Array.isArray(list) ? list : []).forEach((provider, order) => {
let reason;
let copy = null;
const words = { face: null, labels: null, look: null };
try {
reason = refusal(provider, kinds, words);
if (!reason) copy = keptProvider(provider, order, words);
reason = refusal(provider, kinds);
if (!reason) {
const words = checkedWords(provider);
if (typeof words === 'string') reason = words;
else copy = keptProvider(provider, order, words);
}
} catch {
reason = 'a member threw when read';
}
@@ -250,14 +269,14 @@ export function cockpitSubjectProviders(
}
/**
* The frozen copy the Cockpit keeps of a provider `refusal` passed, seeded
* with the worded members it checked.
* The frozen copy the Cockpit keeps of a provider that passed `refusal`,
* seeded with the worded members `checkedWords` read.
*/
function keptProvider(provider, order, words) {
// Worded members are read again on each use (see above); the last good
// read stands in for one that is malformed or throws.
let { face, labels, look } = words;
// On or off, and its rest pitch, as first read.
// Look stays on or off, at its rest pitch, as read at registration.
const restPitchDeg = look?.restPitchDeg ?? 0;
return Object.freeze({
kind: provider.kind,
@@ -345,8 +364,8 @@ function candidateOf(raw) {
* read of it that throws (a getter runs provider code).
* A `heightM` that is not finite or lies outside
* COCKPIT_SUBJECT_MIN_HEIGHT_M..COCKPIT_SUBJECT_MAX_HEIGHT_M reads as null:
* the eye then stands on the shared floor, or where it last stood while that
* is cold. The anchor is `'inertial'` by default for a frame with a valid
* the eye then stands on the shared floor, or at the last height a frame gave,
* the entry frame's included, while that is cold. The anchor is `'inertial'` by default for a frame with a valid
* speed, and `'exact'` when asked for or with no speed. An id is compared
* with `heldId` trimmed, as `cockpitSubjectCandidate` trims it.
* @param {unknown} raw What `read()` returned.
@@ -376,18 +395,20 @@ function frameOf(raw, heldId) {
const heading = (value) =>
finite(value) ? ((value % 360) + 360) % 360 : null;
const headingDeg = heading(raw.headingDeg);
const speedMps =
finite(raw.speedMps) && raw.speedMps >= 0 ? raw.speedMps : null;
// Each read once: a getter on the frame runs provider code.
const rawSpeedMps = raw.speedMps;
const speedMps = finite(rawSpeedMps) && rawSpeedMps >= 0 ? rawSpeedMps : null;
const rawHeightM = raw.heightM;
return {
id: heldId,
name: cockpitSubjectText(raw.name, 64) || cockpitSubjectText(heldId, 64),
latitude,
longitude: ((((longitude + 180) % 360) + 360) % 360) - 180,
heightM:
finite(raw.heightM) &&
raw.heightM >= COCKPIT_SUBJECT_MIN_HEIGHT_M &&
raw.heightM <= COCKPIT_SUBJECT_MAX_HEIGHT_M
? raw.heightM
finite(rawHeightM) &&
rawHeightM >= COCKPIT_SUBJECT_MIN_HEIGHT_M &&
rawHeightM <= COCKPIT_SUBJECT_MAX_HEIGHT_M
? rawHeightM
: null,
headingDeg,
courseDeg: heading(raw.courseDeg) ?? headingDeg,
+58
View File
@@ -670,6 +670,64 @@ test('a worded getter that starts throwing keeps the last good words', () => {
assert.equal(ride.labels.view, 'Ride view');
});
for (const form of ['function', 'getter']) {
test(`worded members (as a ${form}) that throw from their second read keep the words checked at registration`, () => {
const definition = provider();
for (const [key, value] of Object.entries({
labels: { view: 'Ride view', exit: 'Exit ride view', exitText: 'EXIT' },
entryFace: { icon: 'commute', label: 'RIDE' },
look: { restPitchDeg: 10, aheadLabel: 'Look ahead' },
})) {
let read = false;
const once = () => {
if (read) throw new Error('word bundle unloaded');
read = true;
return value;
};
if (form === 'function') definition[key] = once;
else Object.defineProperty(definition, key, { get: once });
}
const { kept, warnings } = keep([definition]);
assert.deepEqual(warnings, []);
const [ride] = kept;
assert.equal(ride.labels.view, 'Ride view');
assert.equal(ride.entryFace.label, 'RIDE');
assert.deepEqual(ride.look, { restPitchDeg: 10, aheadLabel: 'Look ahead' });
});
}
test('a worded member that returns a rejected promise keeps the last good words, the rejection caught', async () => {
const definition = provider();
const words = definition.labels;
let reads = 0;
definition.labels = () => {
reads += 1;
return reads === 1 ? words : Promise.reject(new Error('late words'));
};
const { kept, warnings } = keep([definition]);
assert.deepEqual(warnings, []);
assert.equal(kept[0].labels.view, words.view);
// An unhandled rejection would fail this test once it surfaces.
await new Promise((resolve) => setTimeout(resolve, 10));
});
test('a frame field read through a getter is read once', () => {
const frame = { id: 'a1', latitude: 1, longitude: 2, eye: { upM: 3 } };
const once = (value) => {
let read = false;
return () => {
const answer = read ? undefined : value;
read = true;
return answer;
};
};
Object.defineProperty(frame, 'heightM', { get: once(420) });
Object.defineProperty(frame, 'speedMps', { get: once(12) });
const normalized = cockpitSubjectFrame(frame, 'a1');
assert.equal(normalized.heightM, 420);
assert.equal(normalized.speedMps, 12);
});
test('a candidate, frame or HUD view whose getter throws reads as null', () => {
assert.equal(
cockpitSubjectCandidate(throwingGetter({ name: 'Example' }, 'id')),
+5 -3
View File
@@ -411,7 +411,9 @@ function updateSubject(nowMs) {
: slewHeading(
this.heading ?? frame.headingDeg,
frame.headingDeg,
rate * dtSec,
// At most half a turn, which reaches any heading: a huge rate times
// the step must not overflow to Infinity and stop the turn.
Math.min(rate * dtSec, 180),
);
}
let look = null;
@@ -506,8 +508,8 @@ function placeCamera(target, info, nowMs, dtSec, profile, look = null) {
);
const correction = sub(target, this.cockpitAnchor);
const correctionDistanceM = magnitude(correction);
// An application subject's step is already bounded by its own update
// interval (cockpitSubjectStepSec); the built-in views keep the 0.1 s.
// An application subject's step is already bounded (cockpitSubjectStepSec);
// the built-in views keep the 0.1 s.
const correctionStepM = cockpitAnchorCorrectionStep(
correctionDistanceM,
speedMps,
+4 -1
View File
@@ -194,7 +194,10 @@ export class CockpitViewController {
this.surfaceWaitStartedMs = 0;
this.surfaceAcquiring = false;
this.surfaceFallback = false;
/** The height an application subject's frame last stood at (m). */
/**
* The last height an application subject's frame gave, the entry frame's
* included (m).
*/
this.subjectHeightM = null;
/** The ground clamp's eased lift under that subject's eye (m). */
this.subjectLiftM = null;
+1 -2
View File
@@ -262,8 +262,7 @@ function updateSubjectHud(info, nowMs, forceContext) {
for (const key of this.subjectSignalKeys ?? [])
if (!keys.has(key)) this.dropCockpitSignal(key);
this.subjectSignalKeys = keys;
// The view's rows are its current signals: each changes where it stands,
// so a changing one (an ETA) never pushes a steady one off the list.
// The view's rows are its current signals, each changed in place.
for (const signal of hud.signals)
this.pushCockpitSignal(
`subject:${signal.id}`,
+3 -2
View File
@@ -42,8 +42,9 @@ export function publishCockpitSignals() {
/**
* Log a signal as the newest row, unless its key last said the same.
* @param {{inPlace?: boolean}} [options] `inPlace`: a status row, such as a
* provider's, that changes where it stands rather than log a new row, and
* comes back if newer rows pushed it off the list.
* provider's, that changes where it stands rather than log a new row, so a
* changing ETA never pushes a steady warning off the list; it keeps the
* time it first appeared, and comes back if newer rows pushed it off.
*/
export function pushCockpitSignal(
key,
+104 -76
View File
@@ -27,6 +27,10 @@ import { fakeScenePorts } from '../testSupport/fakeCesiumScene.mjs';
const LAT = 47;
const LON = 8;
const FLOOR_M = 400;
/** Metres in a degree of longitude at LAT. */
const M_PER_DEG_LON = 111_320 * Math.cos(Cesium.Math.toRadians(LAT));
/** The longitude `m` metres east of LON. */
const eastM = (m) => LON + m / M_PER_DEG_LON;
/** A HUD view model as a provider words it. */
const HUD = Object.freeze({
@@ -560,7 +564,7 @@ test('a subject updated every 500 ms turns, eases and closes on its target at it
ride.subject.frame = {
...ride.subject.frame,
headingDeg: 180,
longitude: LON + 100 / (111_320 * Math.cos(Cesium.Math.toRadians(LAT))),
longitude: eastM(100),
};
setFloor(FLOOR_M + 3.5);
clock.advance(500);
@@ -588,20 +592,35 @@ test('a subject updated every 500 ms turns, eases and closes on its target at it
assert.ok(Math.abs(cockpit.heading - 110) < 1e-6, 'at most 1.5 s');
});
test('an inertial subject drawn at 5 frames a second stays near its target', async (t) => {
test('a subject turning at the largest finite rate reaches its heading after a late update', async (t) => {
const clock = manualClock(t, 10_000);
const ride = subjectProvider({
cameraIntervalMs: 500,
headingSlewDps: Number.MAX_VALUE,
});
const { cockpit } = fixture(t, { providers: [ride] });
cockpit.syncEntry();
assert.equal(cockpit.enter(), true);
clock.advance(500);
cockpit.update();
ride.subject.frame = { ...ride.subject.frame, headingDeg: 180 };
// A 1.5 s step: the rate times it overflows to Infinity.
clock.advance(1500);
cockpit.update();
assert.equal(cockpit.heading, 180);
});
test('an inertial subject drawn at 5 frames a second stays near its target', async (t) => {
const startMs = 10_000;
const clock = manualClock(t, startMs);
const ride = subjectProvider();
const SPEED_MPS = 30;
const startMs = 10_000;
const eastOf = (ms) =>
LON +
(SPEED_MPS * (ms - startMs)) /
1000 /
(111_320 * Math.cos((LAT * Math.PI) / 180));
let nowMs = startMs;
const eastNow = () =>
eastM((SPEED_MPS * (performance.now() - startMs)) / 1000);
const base = ride.subject.frame;
ride.subject.frame = () => ({
...subjectProvider().subject.frame,
longitude: eastOf(nowMs),
...base,
longitude: eastNow(),
speedMps: SPEED_MPS,
anchor: 'inertial',
});
@@ -610,14 +629,9 @@ test('an inertial subject drawn at 5 frames a second stays near its target', asy
assert.equal(cockpit.enter(), true);
for (let i = 0; i < 300; i += 1) {
clock.advance(200);
nowMs += 200;
cockpit.update();
}
const target = Cesium.Cartesian3.fromDegrees(
eastOf(nowMs),
LAT,
FLOOR_M + 3.5,
);
const target = Cesium.Cartesian3.fromDegrees(eastNow(), LAT, FLOOR_M + 3.5);
const gapM = Cesium.Cartesian3.distance(shots.at(-1).destination, target);
assert.ok(
gapM < 50,
@@ -633,15 +647,14 @@ for (const [intervalMs, waitMs] of [
const startMs = 10_000;
const clock = manualClock(t, startMs);
const SPEED_MPS = 30;
const mPerDegLon = 111_320 * Math.cos(Cesium.Math.toRadians(LAT));
const eastOf = () =>
LON + (SPEED_MPS * (performance.now() - startMs)) / 1000 / mPerDegLon;
const eastNow = () =>
eastM((SPEED_MPS * (performance.now() - startMs)) / 1000);
const ride = subjectProvider({ cameraIntervalMs: intervalMs });
const base = ride.subject.frame;
ride.subject.frame = () => ({
...base,
heightM: null,
longitude: eastOf(),
longitude: eastNow(),
speedMps: SPEED_MPS,
anchor: 'inertial',
eye: { ...base.eye, forwardM: 0 },
@@ -666,7 +679,7 @@ for (const [intervalMs, waitMs] of [
cockpit.update();
const shot = Cesium.Cartographic.fromCartesian(shots[before].destination);
const leadM =
(Cesium.Math.toDegrees(shot.longitude) - eastOf()) * mPerDegLon;
(Cesium.Math.toDegrees(shot.longitude) - eastNow()) * M_PER_DEG_LON;
assert.ok(
Math.abs(leadM) < 1,
`the first camera update leads the subject by ${leadM.toFixed(2)} m`,
@@ -949,31 +962,46 @@ test('a floor that never comes ends the view after the bounded wait, releasing t
assert.deepEqual(lastRelease(ride.calls), ['release', 'a1', false]);
});
test('a height the entry frame gave holds while later frames give none and the floor is cold', async (t) => {
const clock = manualClock(t, 10_000);
const ride = subjectProvider();
const { cockpit, shots, setFloor } = fixture(t, { providers: [ride] });
setFloor(undefined);
cockpit.syncEntry();
// The entry frame stands at FLOOR_M (heightM 400).
assert.equal(cockpit.enter(), true);
ride.subject.frame = { ...ride.subject.frame, heightM: null };
for (
let elapsed = 0;
elapsed < COCKPIT_GROUND_WAIT_TIMEOUT_MS + 1000;
elapsed += 100
) {
for (const entryHeightM of [0, FLOOR_M]) {
test(`a height the entry frame gave (${entryHeightM} m) holds while later frames give none and the floor is cold`, async (t) => {
const clock = manualClock(t, 10_000);
const ride = subjectProvider();
ride.subject.frame = { ...ride.subject.frame, heightM: entryHeightM };
const { cockpit, shots, setFloor } = fixture(t, { providers: [ride] });
setFloor(undefined);
cockpit.syncEntry();
assert.equal(cockpit.enter(), true);
ride.subject.frame = { ...ride.subject.frame, heightM: null };
const waitPastTimeout = () => {
for (
let elapsed = 0;
elapsed < COCKPIT_GROUND_WAIT_TIMEOUT_MS + 1000;
elapsed += 100
) {
clock.advance(100);
cockpit.update();
}
};
waitPastTimeout();
assert.equal(
cockpit.active,
true,
'the view keeps the height its entry frame gave',
);
assert.ok(shots.length > 0, 'the camera is placed');
assert.ok(Math.abs(shotHeight(shots) - (entryHeightM + 3.5)) < 0.01);
// A floor that comes takes over, and is kept once it is cold again.
const floorM = FLOOR_M - 100;
setFloor(floorM);
clock.advance(100);
cockpit.update();
}
assert.equal(
cockpit.active,
true,
'the view keeps the height its entry frame gave',
);
assert.ok(shots.length > 0, 'the camera is placed');
assert.ok(Math.abs(shotHeight(shots) - (FLOOR_M + 3.5)) < 0.01);
});
assert.ok(Math.abs(shotHeight(shots) - (floorM + 3.5)) < 0.01);
setFloor(undefined);
waitPastTimeout();
assert.equal(cockpit.active, true);
assert.ok(Math.abs(shotHeight(shots) - (floorM + 3.5)) < 0.01);
});
}
test('an asynchronous hold that lands after entry was refused is released again', async (t) => {
let heldId = null;
@@ -1054,39 +1082,28 @@ test('a provider’s labels, entry face and look follow a change of language', a
);
});
/** Labels that read well once, when the provider is checked, then throw. */
const GOOD_LABELS = Object.freeze({
view: 'Ride view',
exit: 'Exit ride view',
exitText: 'EXIT RIDE',
kicker: 'RIDE',
});
const labelsOnce = () => {
let reads = 0;
return function labels() {
reads += 1;
if (reads > 1) throw new Error('word bundle unloaded');
return GOOD_LABELS;
};
};
test('labels that start throwing after the first read keep the first good words', () => {
const warned = [];
const [kept] = cockpitSubjectProviders(
[{ ...subjectProvider().definition, labels: labelsOnce() }],
{ warn: (message) => warned.push(message) },
);
assert.ok(kept, 'the provider is kept');
assert.deepEqual({ ...kept.labels }, GOOD_LABELS);
});
test('entering such a provider with no HUD kicker does not throw', async (t) => {
test('a provider whose labels throw after registration enters with no HUD kicker', async (t) => {
manualClock(t, 10_000);
const ride = subjectProvider({ labels: labelsOnce() });
let read = false;
const ride = subjectProvider({
labels() {
if (read) throw new Error('word bundle unloaded');
read = true;
return {
view: 'Tram view',
exit: 'Exit tram view',
exitText: 'EXIT TRAM',
kicker: 'TRAM 4',
};
},
});
ride.subject.hud = { title: 'Example 12' };
const { cockpit } = fixture(t, { providers: [ride] });
const { $, cockpit } = fixture(t, { providers: [ride] });
cockpit.syncEntry();
assert.doesNotThrow(() => cockpit.enter());
assert.equal(cockpit.enter(), true);
await settle();
// The kicker checked at registration stands in for the HUD view's.
assert.equal($('.cockpit-kicker').textContent, 'TRAM 4');
});
test('a read that throws ends the view once; a hud that throws keeps the last', async (t) => {
@@ -1320,6 +1337,9 @@ test('the same double-click on the vessel alone enters its bridge', async (t) =>
cockpit.syncEntry();
assert.equal(store.presence.entryKind, 'vessel');
assert.equal(cockpit.onSceneDoubleClick({ x: 100, y: 100 }), true);
await settle();
assert.equal(store.presence.active, true, 'the bridge is entered');
assert.equal(cockpit.subjectKind, 'vessel');
});
test('a provider view with look turns with the arrow keys and words its readout', async (t) => {
@@ -1374,27 +1394,35 @@ test('a signal still listed stays in Live Signals while another one changes', as
// The real Live Signals rows, not the fixture's recorder.
delete cockpit.pushCockpitSignal;
delete cockpit.dropCockpitSignal;
// The ETA is logged first, so it stands below the warning.
const hudWith = (minutes) => ({
...HUD,
signals: [
{ id: 'eta', title: 'NEXT', detail: `Central in ${minutes} min` },
{
id: 'doors',
tone: 'warning',
title: 'DOORS',
detail: 'door fault, car 2',
},
{ id: 'eta', title: 'NEXT', detail: `Central in ${minutes} min` },
],
});
const etaRow = () =>
cockpit.signalItems.find((row) => row.key === 'subject:eta');
ride.subject.hud = hudWith(10);
cockpit.syncEntry();
assert.equal(cockpit.enter(), true);
const keysAtEntry = cockpit.signalItems.map((row) => row.key);
const etaFirstSeen = etaRow().timestamp;
for (let minutes = 9; minutes >= 2; minutes -= 1) {
ride.subject.hud = hudWith(minutes);
clock.advance(1000);
cockpit.update();
}
const keys = cockpit.signalItems.map((row) => row.key);
// Each row keeps its place, and the ETA the time it first appeared.
assert.deepEqual(keys, keysAtEntry);
assert.equal(etaRow().timestamp, etaFirstSeen);
assert.ok(
keys.includes('subject:doors'),
`the warning the HUD still lists is shown (rows: ${keys.join(', ')})`,