commit
e092cb029c
252 files changed
+35037
No files matched your search
@@ -0,0 +1,37 @@
|
||||
// SPDX-FileCopyrightText: 2026 Scientific Computing Studio, LLC
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// A phone-width screen shows one part of a workspace at a time (styles.css, src/ui/shell.ts setNarrow); a wider one
|
||||
// must not see any of it: AGENTS.md rule 7 keeps the workspace's parts where they are on a normal screen.
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { readFileSync } from 'node:fs';
|
||||
|
||||
const css = readFileSync(new URL('../styles.css', import.meta.url), 'utf8').replace(/\/\*[\s\S]*?\*\//g, '');
|
||||
|
||||
/** The top-level blocks of a stylesheet: [prelude, body] pairs. */
|
||||
function blocks(text) {
|
||||
const out = []; let depth = 0, start = 0, prelude = '';
|
||||
for (let i = 0; i < text.length; i++) {
|
||||
if (text[i] === '{') { if (depth === 0) { prelude = text.slice(start, i).trim(); start = i + 1; } depth++; }
|
||||
else if (text[i] === '}') { depth--; if (depth === 0) { out.push([prelude, text.slice(start, i)]); start = i + 1; } }
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
test('every narrow-screen rule is inside the 700px media query, and the bar is hidden outside it', () => {
|
||||
const top = blocks(css);
|
||||
const outside = top.filter(([p]) => !p.startsWith('@media')).map(([p, b]) => `${p}{${b}}`);
|
||||
assert.ok(outside.some((r) => /^\.narrow-bar\{\s*display: none;\s*\}$/.test(r.replace(/\s*\{\s*/, '{').trim())), '.narrow-bar is display: none on a normal screen');
|
||||
for (const r of outside) assert.doesNotMatch(r, /data-narrow/, `a rule outside the media query reads data-narrow: ${r.slice(0, 80)}`);
|
||||
for (const [p, b] of top.filter(([p]) => p.startsWith('@media') && !/max-width: 700px/.test(p))) assert.doesNotMatch(b, /data-narrow|narrow-bar/, `${p} reads the narrow layout`);
|
||||
const narrow = top.filter(([p]) => /^@media \(max-width: 700px\)$/.test(p)).map(([, b]) => b).join('\n');
|
||||
for (const part of ['code', 'side', 'dock']) assert.match(narrow, new RegExp(`data-narrow="${part}"`), part);
|
||||
});
|
||||
|
||||
test('the shell offers the parts, and Run, Compile & run and a diagnostic\'s line show the part they open', () => {
|
||||
const shell = readFileSync(new URL('../src/ui/shell.ts', import.meta.url), 'utf8');
|
||||
assert.match(shell, /\[\['code', 'Code'\], \['side', 'Board'\]\] : \[\['code', 'Code'\], \['side', 'Run and views'\], \['dock', 'Setup and output'\]\]/);
|
||||
assert.match(shell, /this\.stepper\?\.goto\(this\.session\.trace\(\)\?\.count \?\? 0\); this\.setNarrow\('side'\);/, 'Run shows the Run view');
|
||||
assert.match(shell, /if \(open\) this\.setNarrow\('dock'\);/, 'opening the dock (Compile & run) shows it');
|
||||
assert.match(shell, /reveal: \(lang, line\) => \{\n\s*this\.setNarrow\('code'\);/, 'a line in the code shows the code');
|
||||
});
|
||||
Reference in new issue
Block a user