mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-20 02:02:21 +00:00
Merge remote-tracking branch 'origin/main' into samehkhamis/kit-sweep-cockpit
# Conflicts: # scripts/format-scope.json
This commit is contained in:
commit
ecb01eff2d
35 files changed
+612
-193
No files matched your search
@@ -0,0 +1,127 @@
|
||||
// The command dock's and the Context panel's buttons and Material glyphs are
|
||||
// the kit's: neither the dock, the Context view nor the view context it
|
||||
// shows while nothing is picked hand-writes a <button> or a Material Symbols
|
||||
// span. The dock's style buttons are pressed toggles with `active`, its
|
||||
// glyphs (◯ ▦ 🌙 🌡️ ✦ ◐, the search 🔎 and the collapse +) are text
|
||||
// characters, not Material symbols, and stay plain text. Context's tabs and
|
||||
// its Contacts mode button are `role="tab"` controls: they say they are
|
||||
// chosen with `aria-selected` and keep their own `active` class, never
|
||||
// `aria-pressed`.
|
||||
import { test } from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { readFileSync } from 'node:fs';
|
||||
|
||||
/** A view's template block: everything outside script, style and comments. */
|
||||
function template(file) {
|
||||
const source = readFileSync(
|
||||
new URL(`../views/${file}`, import.meta.url),
|
||||
'utf8',
|
||||
);
|
||||
return source
|
||||
.replace(/<(script|style)\b[\s\S]*?<\/\1\s*>/g, '')
|
||||
.replace(/<!--[\s\S]*?-->/g, '');
|
||||
}
|
||||
// A tag's attributes, read past quoted values so a handler's `=>` does not
|
||||
// end the tag early.
|
||||
const ATTRS = String.raw`(?:[^>"']|"[^"]*"|'[^']*')*`;
|
||||
const tag = (pattern, flags = '') =>
|
||||
new RegExp(pattern.replaceAll('ATTRS', ATTRS), flags);
|
||||
const tags = (markup, name) =>
|
||||
markup.match(tag(String.raw`<${name}\bATTRS>`, 'g')) ?? [];
|
||||
|
||||
const dock = template('CommandDockView.vue');
|
||||
const context = template('ContextView.vue');
|
||||
const inView = template('panels/ViewContext.vue');
|
||||
const views = {
|
||||
// The six style buttons, the two tray toggles and their pins, the map
|
||||
// source chips, Location's collapse, its landmark and city pills and the
|
||||
// search toggle.
|
||||
'CommandDockView.vue': { markup: dock, buttons: 15, icons: 0, closes: 0 },
|
||||
// Search and Expand in the header, the two tabs, Contacts, the cockpit
|
||||
// entry, SEARCH NEARBY SITES and the TR-3B chip.
|
||||
'ContextView.vue': { markup: context, buttons: 8, icons: 7, closes: 0 },
|
||||
// An off layer's worldwide tile, an item's row, the place and layer chips
|
||||
// and Ask GEV; a layer's Turn off is a UiCloseButton. The glyphs: the
|
||||
// header's eye, a worldwide tile's (on and off), a layer group's, an
|
||||
// item's motion and the layer chips' add.
|
||||
'panels/ViewContext.vue': { markup: inView, buttons: 5, icons: 6, closes: 1 },
|
||||
};
|
||||
|
||||
test('the dock and Context hand-write no button; each is a UiButton', () => {
|
||||
for (const [file, { markup, buttons, closes }] of Object.entries(views)) {
|
||||
assert.deepEqual(markup.match(/<button\b/gi) ?? [], [], file);
|
||||
assert.deepEqual(markup.match(/<component\b/gi) ?? [], [], file);
|
||||
assert.equal(tags(markup, 'UiButton').length, buttons, file);
|
||||
assert.equal(tags(markup, 'UiCloseButton').length, closes, file);
|
||||
}
|
||||
});
|
||||
|
||||
test('the style buttons are pressed toggles with active', () => {
|
||||
assert.doesNotMatch(dock, /v-class-toggle="\{[^"]*\bactive\b/);
|
||||
const styles = tags(dock, 'UiButton').filter((b) =>
|
||||
/class="style-btn"/.test(b),
|
||||
);
|
||||
assert.deepEqual(
|
||||
styles.map((b) => b.match(/data-style="(\w+)"/)[1]),
|
||||
['normal', 'retro', 'surveillance', 'thermal', 'anime', 'noir'],
|
||||
);
|
||||
for (const button of styles) {
|
||||
const name = button.match(/data-style="(\w+)"/)[1];
|
||||
assert.match(button, /\spressed-class="active"/, name);
|
||||
// Normal stays the pressed one until a style is published.
|
||||
assert.match(
|
||||
button,
|
||||
name === 'normal'
|
||||
? /\s:pressed="!style \|\| style\.name === 'normal'"/
|
||||
: new RegExp(String.raw`\s:pressed="style\?\.name === '${name}'"`),
|
||||
name,
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
test('no tag hand-writes aria-pressed; the pressed toggles take :pressed', () => {
|
||||
for (const [file, { markup }] of Object.entries(views))
|
||||
assert.doesNotMatch(
|
||||
markup,
|
||||
tag(String.raw`<\w+\bATTRS\s:?aria-pressed`),
|
||||
file,
|
||||
);
|
||||
const pressed = (markup) =>
|
||||
tags(markup, 'UiButton').filter((b) => /\s:pressed=/.test(b)).length;
|
||||
// The six styles, two pins, map sources, landmarks and cities.
|
||||
assert.equal(pressed(dock), 11);
|
||||
// Search, Expand and TR-3B.
|
||||
assert.equal(pressed(context), 3);
|
||||
assert.equal(pressed(inView), 0);
|
||||
});
|
||||
|
||||
test("Context's tabs say they are chosen, not pressed", () => {
|
||||
const tabs = tags(context, 'UiButton').filter((b) => /\srole="tab"/.test(b));
|
||||
assert.equal(tabs.length, 3);
|
||||
for (const button of tabs) {
|
||||
assert.match(button, /\s:aria-selected=/);
|
||||
assert.doesNotMatch(button, /\s:pressed=/);
|
||||
assert.match(button, /\s(?::class|v-class-toggle)="\{ active: /);
|
||||
}
|
||||
});
|
||||
|
||||
test('they hand-write no Material glyph; each is a UiIcon', () => {
|
||||
for (const [file, { markup, icons }] of Object.entries(views)) {
|
||||
assert.deepEqual(
|
||||
markup.match(/material-symbols-outlined/g) ?? [],
|
||||
[],
|
||||
file,
|
||||
);
|
||||
const found = tags(markup, 'UiIcon');
|
||||
assert.equal(found.length, icons, file);
|
||||
// Without it the kit writes an 18px size that beats the site rules.
|
||||
for (const icon of found) assert.match(icon, /\s:size="null"/, file);
|
||||
}
|
||||
// An item's motion glyph is an image with its own name, not decoration.
|
||||
const [motion] = tags(inView, 'UiIcon').filter((i) =>
|
||||
/view-context__row-motion/.test(i),
|
||||
);
|
||||
assert.match(motion, /\srole="img"/);
|
||||
assert.match(motion, /\s:aria-label=/);
|
||||
assert.match(motion, /\s:aria-hidden="null"/);
|
||||
});
|
||||
@@ -0,0 +1,135 @@
|
||||
// The small surfaces' buttons and Material glyphs are the kit's: the locale
|
||||
// picker, the phone tab bar, the globe actions and compass, the imagery
|
||||
// divider, the scene sharing dialog, the layer group index, the celestial
|
||||
// ring, the title logo, Exit clean view, the HUD's cockpit entry, the News
|
||||
// cards, the rail cards, the layer rows' toggles, the credits line and the
|
||||
// camera calibration chips hand-write no <button> and no Material Symbols
|
||||
// span. The Omnibar guide's extra rings are its template's, not built in
|
||||
// script. The locale picker's globe, caret and check and a News card's
|
||||
// category icon stay inline SVG: none is a Material symbol the page loads.
|
||||
import { test } from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { readFileSync } from 'node:fs';
|
||||
|
||||
const read = (file) =>
|
||||
readFileSync(new URL(`../${file}`, import.meta.url), 'utf8');
|
||||
/** The template block: everything outside script, style and comments. */
|
||||
const template = (file) =>
|
||||
read(file)
|
||||
.replace(/<(script|style)\b[\s\S]*?<\/\1\s*>/g, '')
|
||||
.replace(/<!--[\s\S]*?-->/g, '');
|
||||
// An opening tag's attributes, quoted values may hold `>` (`() => x`).
|
||||
const ATTRS = String.raw`(?:[^>"']|"[^"]*"|'[^']*')*`;
|
||||
const tags = (markup, name) =>
|
||||
markup.match(new RegExp(String.raw`<${name}\b${ATTRS}>`, 'g')) ?? [];
|
||||
|
||||
// Per file: its UiButtons, UiCloseButtons and UiIcons.
|
||||
const SURFACES = {
|
||||
'views/panels/LocalePicker.vue': [1, 0, 0],
|
||||
'views/panels/PhoneTabBar.vue': [1, 0, 1],
|
||||
'views/panels/GlobeCompass.vue': [1, 0, 1],
|
||||
// Clear, share, tilt and reset; the clear, tilt and reset glyphs.
|
||||
'views/panels/GlobeActions.vue': [4, 0, 3],
|
||||
'views/panels/ImagerySplitView.vue': [1, 0, 0],
|
||||
// The body's buttons and the footer's.
|
||||
'views/panels/SceneDialog.vue': [2, 0, 0],
|
||||
'views/panels/LayerSectionIndex.vue': [1, 0, 0],
|
||||
// The sun and moon markers.
|
||||
'views/panels/CelestialRing.vue': [0, 0, 2],
|
||||
'views/panels/OmnibarGuide.vue': [3, 1, 0],
|
||||
// The overlay targets' buttons and the title logo.
|
||||
'views/SceneChromeView.vue': [2, 0, 0],
|
||||
'views/DisplayControlsView.vue': [1, 0, 0],
|
||||
'views/IntelHudView.vue': [1, 0, 1],
|
||||
// The card's face and the selected card's clear chip.
|
||||
'news/NewsCard.vue': [2, 0, 0],
|
||||
'rail/RailCard.vue': [1, 0, 0],
|
||||
'layerPanel/LayerRows.vue': [1, 0, 0],
|
||||
'credits/CreditsView.vue': [1, 1, 0],
|
||||
'cctv/CctvCalValue.vue': [1, 0, 0],
|
||||
};
|
||||
|
||||
test('the small surfaces hand-write no button; each is a kit button', () => {
|
||||
for (const [file, [buttons, closes]] of Object.entries(SURFACES)) {
|
||||
const markup = template(file);
|
||||
assert.deepEqual(markup.match(/<button\b/gi) ?? [], [], file);
|
||||
assert.equal(tags(markup, 'UiButton').length, buttons, file);
|
||||
assert.equal(tags(markup, 'UiCloseButton').length, closes, file);
|
||||
}
|
||||
});
|
||||
|
||||
test('the small surfaces hand-write no Material glyph; each is a UiIcon', () => {
|
||||
for (const [file, [, , count]] of Object.entries(SURFACES)) {
|
||||
const markup = template(file);
|
||||
assert.deepEqual(
|
||||
markup.match(/material-symbols-outlined/g) ?? [],
|
||||
[],
|
||||
file,
|
||||
);
|
||||
const icons = tags(markup, 'UiIcon');
|
||||
assert.equal(icons.length, count, file);
|
||||
// Without it the kit writes an 18px size that beats the sites' own rules.
|
||||
for (const icon of icons) assert.match(icon, /\s:size="null"/, file);
|
||||
}
|
||||
});
|
||||
|
||||
test('the only inline SVG glyphs are the locale picker’s and a News category’s', () => {
|
||||
for (const file of Object.keys(SURFACES)) {
|
||||
const expected =
|
||||
file === 'views/panels/LocalePicker.vue'
|
||||
? 3
|
||||
: file === 'news/NewsCard.vue'
|
||||
? 1
|
||||
: 0;
|
||||
assert.equal(template(file).match(/<svg\b/g)?.length ?? 0, expected, file);
|
||||
}
|
||||
});
|
||||
|
||||
test('buttons whose owner patches synchronously redraw their contents with it', () => {
|
||||
// A UiButton's slot renders inside the button, a tick after a change the
|
||||
// button's own attributes do not carry; a conditional slot is redrawn with
|
||||
// its view.
|
||||
// How many of each file's first buttons the owner redraws and reads.
|
||||
for (const [file, count] of [
|
||||
['news/NewsCard.vue', 1],
|
||||
['rail/RailCard.vue', 1],
|
||||
['credits/CreditsView.vue', 1],
|
||||
['views/panels/OmnibarGuide.vue', 3],
|
||||
]) {
|
||||
const markup = template(file);
|
||||
const buttons = tags(markup, 'UiButton').slice(0, count);
|
||||
assert.equal(buttons.length, count, file);
|
||||
let from = 0;
|
||||
for (const button of buttons) {
|
||||
from = markup.indexOf(button, from) + button.length;
|
||||
assert.match(
|
||||
markup.slice(from),
|
||||
/^\s*<template v-if="redrawWithView" #default\s*>/,
|
||||
file,
|
||||
);
|
||||
}
|
||||
assert.match(read(file), /const redrawWithView = true;/, file);
|
||||
}
|
||||
});
|
||||
|
||||
test('the Omnibar guide draws its extra rings in its template', () => {
|
||||
const guide = template('views/panels/OmnibarGuide.vue');
|
||||
assert.match(
|
||||
guide,
|
||||
/<div\s+v-for="i in view\.subRings"\s+:key="i"\s+class="gev-guide-ring gev-guide-ring--sub"\s*><\/div\s*>\s*<\/div\s*>\s*<\/Teleport/,
|
||||
);
|
||||
const owner = read('omnibarGuide.js');
|
||||
assert.deepEqual(owner.match(/createElement\(/g), ['createElement(']);
|
||||
assert.doesNotMatch(owner, /\.className\s*=|\.append\(/);
|
||||
assert.match(owner, /view\.subRings = rest\.length;\s*paint\(\);/);
|
||||
});
|
||||
|
||||
test('the layer disclosure builds no control', () => {
|
||||
// Its one `<button` is a comment's word for the element Chromium focuses.
|
||||
const disclosure = read('panelDisclosure.js');
|
||||
assert.doesNotMatch(disclosure, /createElement|innerHTML|insertAdjacentHTML/);
|
||||
const code = disclosure
|
||||
.replace(/\/\/.*$/gm, '')
|
||||
.replace(/\/\*[\s\S]*?\*\//g, '');
|
||||
assert.doesNotMatch(code, /<button/);
|
||||
});
|
||||
Reference in new issue
Block a user