mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 08:12:24 +00:00
feat(ui): render rail cards and card blocks as components behind their builders
The rail cards, card blocks, settings, chips and row lists are Vue components in src/ui/rail/. createRailCards() and createRailCardBlocks() keep their update and destroy API and patch the components synchronously with render(), so Weather and Recent imagery are unchanged. Controls of a removed block dispatch nothing, a released range keeps its value until the owner's next update, and range values are written only when they differ. Weather's remount state is keyed by its panel. Tests of rendered parts run on happy-dom.
This commit is contained in:
1 parent
d9fdcfc641
commit
dcecf5c34c
20 files changed
+754
-766
No files matched your search
@@ -1,8 +1,9 @@
|
||||
import '../testSupport/registerDom.mjs';
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { setLocale } from '../i18n/index.js';
|
||||
import { createWeatherPanel } from './weatherPanel.js';
|
||||
import { railFixture } from './railTestFixture.mjs';
|
||||
import { railDocumentFixture as railFixture } from './railTestFixture.mjs';
|
||||
import { createAirQualityLayer } from '../layers/airQuality/index.js';
|
||||
const ticks = ['2026-09-22T01:00:00Z', '2026-09-22T01:05:00Z'];
|
||||
const wind = {
|
||||
@@ -20,14 +21,16 @@ const radar = {
|
||||
icon: '◉',
|
||||
summary: { label: 'Rain radar', coverage: 'CONUS' },
|
||||
};
|
||||
function fixture(onWrite) {
|
||||
const f = railFixture(onWrite);
|
||||
function fixture() {
|
||||
const f = railFixture();
|
||||
const panel = f.document.createElement('div');
|
||||
const count = f.document.createElement('span');
|
||||
let collapsed = true;
|
||||
let clicks = 0;
|
||||
panel.hidden = true;
|
||||
panel.classList = { contains: () => collapsed };
|
||||
Object.defineProperty(panel, 'classList', {
|
||||
value: { contains: () => collapsed },
|
||||
});
|
||||
const collapse = {
|
||||
click() {
|
||||
collapsed = !collapsed;
|
||||
@@ -112,7 +115,7 @@ test('ordered articles omit Controls and retain history labels, forecast dates a
|
||||
view.update([radar, wind]);
|
||||
const windCard = card(f, 'wind');
|
||||
assert.equal(windCard.tagName, 'ARTICLE');
|
||||
assert.equal(windCard.parent.children[0], windCard);
|
||||
assert.equal(windCard.parentElement.children[0], windCard);
|
||||
assert.equal(
|
||||
f.find((n) => n.dataset.weatherOpen),
|
||||
null,
|
||||
@@ -186,7 +189,9 @@ test('cyclone readout retains advisory, position, intensity, geometry, coverage,
|
||||
line(f, cyclone.id, 'geometry').textContent,
|
||||
/awaiting advisory 10/,
|
||||
);
|
||||
const link = f.find((n) => n.textContent === 'Official advisory ↗');
|
||||
const link = f.find(
|
||||
(n) => n.tagName === 'A' && n.textContent === 'Official advisory ↗',
|
||||
);
|
||||
assert.equal(link.href, cyclone.summary.actions[0].href);
|
||||
assert.equal(link.tagName, 'A');
|
||||
assert.equal(link.rel, 'noopener');
|
||||
@@ -198,8 +203,7 @@ test('cyclone readout retains advisory, position, intensity, geometry, coverage,
|
||||
view.destroy();
|
||||
});
|
||||
test('identical updates write nothing and status keeps its line through loading and empty text', () => {
|
||||
let writes = 0;
|
||||
const f = fixture(() => writes++);
|
||||
const f = fixture();
|
||||
const view = createWeatherPanel(f);
|
||||
for (const entries of [
|
||||
[wind, radar],
|
||||
@@ -209,9 +213,9 @@ test('identical updates write nothing and status keeps its line through loading
|
||||
]) {
|
||||
view.update(entries);
|
||||
const status = entries.length ? line(f, 'wind', 'status') : null;
|
||||
writes = 0;
|
||||
f.writes();
|
||||
view.update(entries);
|
||||
assert.equal(writes, 0);
|
||||
assert.equal(f.writes(), 0);
|
||||
if (status) {
|
||||
assert.equal(status.hidden, false);
|
||||
assert.equal(line(f, 'wind', 'status'), status);
|
||||
@@ -256,7 +260,7 @@ test('count, hidden-empty and first-appearance expansion survive remount and own
|
||||
test('a stored or shared collapse choice is not overridden on first appearance', () => {
|
||||
for (const preference of ['stored', 'share']) {
|
||||
const f = fixture();
|
||||
f.panel.dataset = { collapsedPreference: preference };
|
||||
f.panel.dataset.collapsedPreference = preference;
|
||||
const view = createWeatherPanel(f);
|
||||
view.update([radar]);
|
||||
assert.equal(f.panel.hidden, false);
|
||||
@@ -268,7 +272,7 @@ test('a stored or shared collapse choice is not overridden on first appearance',
|
||||
view.destroy();
|
||||
}
|
||||
const f = fixture();
|
||||
f.panel.dataset = { collapsedPreference: 'default' };
|
||||
f.panel.dataset.collapsedPreference = 'default';
|
||||
const view = createWeatherPanel(f);
|
||||
view.update([radar]);
|
||||
assert.equal(f.clicks(), 1, 'a default state still expands once');
|
||||
@@ -326,7 +330,7 @@ test('settings, reading and footer actions pass the layer id, params and user or
|
||||
assert.equal(header.children[1].textContent, '×');
|
||||
assert.equal(header.children[1].getAttribute('aria-label'), 'Clear reading');
|
||||
assert.deepEqual(
|
||||
result.children[1].children[0].children.map((n) => [
|
||||
[...result.children[1].children[0].children].map((n) => [
|
||||
n.dataset.lineId,
|
||||
n.textContent,
|
||||
]),
|
||||
@@ -348,7 +352,7 @@ test('settings, reading and footer actions pass the layer id, params and user or
|
||||
layer.destroy();
|
||||
const body = card(f, 'wind').children[1];
|
||||
assert.deepEqual(
|
||||
body.children.map((n) => n.dataset.blockId),
|
||||
[...body.children].map((n) => n.dataset.blockId),
|
||||
['details', 'settings', 'actions', 'reading'],
|
||||
);
|
||||
view.destroy();
|
||||
@@ -395,7 +399,7 @@ test('cyclones lead, and observed history owns one bordered group with only acti
|
||||
view.update([lightning, radar, wind, cyclone, satellite]);
|
||||
const root = f.container.children[0];
|
||||
assert.deepEqual(
|
||||
root.children[0].children.map((n) => n.dataset.cardId),
|
||||
[...root.children[0].children].map((n) => n.dataset.cardId),
|
||||
['weather-cyclones', 'wind'],
|
||||
);
|
||||
const group = f.find((n) => n.className === 'weather-observed-group');
|
||||
@@ -407,7 +411,7 @@ test('cyclones lead, and observed history owns one bordered group with only acti
|
||||
);
|
||||
assert.equal(group.children[2], timelineHost(f));
|
||||
assert.deepEqual(
|
||||
group.children[3].children.map((n) => n.dataset.cardId),
|
||||
[...group.children[3].children].map((n) => n.dataset.cardId),
|
||||
['weather-radar', 'weather-satellite', 'weather-lightning'],
|
||||
);
|
||||
assert.deepEqual(opened(f), ['weather-cyclones']);
|
||||
@@ -579,7 +583,7 @@ test('all five headers retain descriptor icons and disclosure state when opened
|
||||
view.destroy();
|
||||
});
|
||||
|
||||
test('a change of open card scrolls its header into view once; refreshes never move the body', () => {
|
||||
test('a change of open card scrolls its header into view once; refreshes never move the body', (t) => {
|
||||
const f = fixture();
|
||||
const body = f.container;
|
||||
const writes = [];
|
||||
@@ -594,11 +598,14 @@ test('a change of open card scrolls its header into view once; refreshes never m
|
||||
scrollTop = value;
|
||||
},
|
||||
});
|
||||
body.clientHeight = 200;
|
||||
Object.defineProperty(body, 'clientHeight', { value: 200 });
|
||||
body.getBoundingClientRect = () => ({ top: 100, height: 200 });
|
||||
const create = f.document.createElement;
|
||||
t.after(() => {
|
||||
f.document.createElement = create;
|
||||
});
|
||||
f.document.createElement = (tag) => {
|
||||
const node = create(tag);
|
||||
const node = create.call(f.document, tag);
|
||||
node.getBoundingClientRect = function () {
|
||||
return rects.get(this.dataset.cardId) || { top: 0, height: 0 };
|
||||
};
|
||||
@@ -666,7 +673,7 @@ test('history time keeps the hour whatever the length of the localized date', ()
|
||||
view.update([wind, radar]);
|
||||
const ends = f.find((n) => n.className === 'rail-timeline-endpoints');
|
||||
assert.deepEqual(
|
||||
ends.children.map((n) => n.textContent),
|
||||
[...ends.children].map((n) => n.textContent),
|
||||
['01:00 UTC', '01:05 UTC'],
|
||||
locale,
|
||||
);
|
||||
@@ -734,7 +741,7 @@ test('air-quality readout renders its band legend, Canada coverage and worst-fir
|
||||
const entries = f.find((n) => n.className === 'rail-card-legend-entries', aq);
|
||||
assert.equal(entries.hidden, false);
|
||||
assert.deepEqual(
|
||||
entries.children.map((entry) => entry.children[1].textContent),
|
||||
[...entries.children].map((entry) => entry.children[1].textContent),
|
||||
['Low', 'Moderate', 'High', 'Very High'],
|
||||
);
|
||||
assert.equal(
|
||||
@@ -744,8 +751,8 @@ test('air-quality readout renders its band legend, Canada coverage and worst-fir
|
||||
const list = f.find((n) => n.dataset.blockId === 'list', aq);
|
||||
assert.equal(list.hidden, false);
|
||||
assert.deepEqual(
|
||||
list.children.map((item) =>
|
||||
item.children[0].children.map((part) => part.textContent).join(' '),
|
||||
[...list.children].map((item) =>
|
||||
[...item.children[0].children].map((part) => part.textContent).join(' '),
|
||||
),
|
||||
['AQHI 8 Hamilton · high risk', 'AQHI 2 Toronto · low risk'],
|
||||
);
|
||||
|
||||
Reference in new issue
Block a user