feat(cockpit): the owner flags load at startup from one generated 15 KB sheet; the loading status names the place packs while they load on first lookup

This commit is contained in:
Sameh Khamis committed 2026-11-08 19:35:30 -08:00
1 parent 63aa45c520
commit 5a6cf22be1
35 files changed
+643 -216

No files matched your search

+55 -4
View File
@@ -7,6 +7,13 @@ import { createPinia } from 'pinia';
import { createApp, nextTick } from 'vue';
import { useCockpitStore } from './stores/cockpit.js';
import CockpitOrbital from './views/panels/CockpitOrbital.vue';
import { ownerFlagStyle } from './ownerFlag.js';
/** Let a settled promise reach the view. */
async function settle() {
await new Promise((resolve) => setTimeout(resolve, 0));
await nextTick();
}
const VIEW = Object.freeze({
name: 'ISS (ZARYA)',
@@ -191,6 +198,49 @@ test('the place below shows at the top once known', async (t) => {
assert.equal(document.querySelector('#cockpit-orbital-over'), null);
});
test('an owner country shows its flag from the sheet, or its code if the sheet will not load', async (t) => {
// The sheet loads through an Image; this one answers when told.
const images = [];
const RealImage = globalThis.Image;
globalThis.Image = class {
constructor() {
images.push(this);
}
};
t.after(() => {
globalThis.Image = RealImage;
});
const f = fixture(t);
f.store.publishOrbital({
...VIEW,
owner: { countryCode: 'US', label: 'USA' },
});
await nextTick();
assert.equal(f.section().querySelector('.cockpit-orbital-flag'), null);
assert.equal(images.length, 1, 'the sheet is asked for');
images[0].onerror();
await settle();
// No sheet: the code, so the owner never disappears.
assert.equal(f.text('.cockpit-orbital-owner-badge'), 'US');
// The next flag asks again; this time the sheet comes.
f.store.publishOrbital({
...f.store.orbital,
owner: { countryCode: 'FR', label: 'France' },
});
await nextTick();
assert.equal(images.length, 2);
images[1].onload();
await settle();
const flag = f.section().querySelector('.cockpit-orbital-flag');
assert.equal(flag.getAttribute('role'), 'img');
assert.equal(flag.getAttribute('aria-label'), 'France');
assert.equal(
flag.style.backgroundPosition,
ownerFlagStyle('FR').backgroundPosition,
);
assert.equal(f.section().querySelector('.cockpit-orbital-owner-badge'), null);
});
test('the readout names the owner, operator and element set', async (t) => {
const f = fixture(t);
f.store.publishOrbital({
@@ -198,16 +248,17 @@ test('the readout names the owner, operator and element set', async (t) => {
noradId: 25544,
cosparId: '1998-067A',
tle: ISS_TLE,
// Under node there is no flag glob, so a country shows as a badge.
owner: { countryCode: 'US', label: 'USA' },
// A country with no flag on the sheet shows as a badge, named in the
// reader's language.
owner: { countryCode: 'IS', label: 'Ísland' },
operator: 'NASA',
});
await nextTick();
assert.equal(f.text('.cockpit-orbital-name'), 'ISS (ZARYA)');
assert.equal(f.text('.cockpit-orbital-owner-badge'), 'USA');
assert.equal(f.text('.cockpit-orbital-owner-badge'), 'Ísland');
assert.equal(
f.section().querySelector('.cockpit-orbital-owner-badge').title,
'United States',
'Iceland',
);
assert.equal(f.text('.cockpit-orbital-operator'), 'NASA');
assert.equal(