aboutsummaryrefslogtreecommitdiff
path: root/scripts/theme-studio/test-app-core.mjs
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/theme-studio/test-app-core.mjs')
-rw-r--r--scripts/theme-studio/test-app-core.mjs69
1 files changed, 44 insertions, 25 deletions
diff --git a/scripts/theme-studio/test-app-core.mjs b/scripts/theme-studio/test-app-core.mjs
index 8b2df6849..217ea0e6b 100644
--- a/scripts/theme-studio/test-app-core.mjs
+++ b/scripts/theme-studio/test-app-core.mjs
@@ -7,10 +7,11 @@ import assert from 'node:assert/strict';
import { readFileSync } from 'node:fs';
import { fileURLToPath } from 'node:url';
import {
- nameToHex, migrateLegacyFace, normalizePkgFace, buildPkgmap, packagesForExport, mergePackagesInto, effResolve, resolveSyntaxFg, resolveUiAttr, dropdownRowTextColor, paletteOptionList, spanNeighborHex, slugify,
+ nameToHex, migrateLegacyFace, normalizePkgFace, buildPkgmap, packagesForExport, mergePackagesInto, effResolve, resolveSyntaxFg, resolveUiAttr, paletteOptionList, spanNeighborHex, slugify,
clearPalettePlan, deletePaletteColumnPlan, groundColumnMembersFromPalette, areAllLocked, lockToggleLabel, toggleLockSet,
galleryModel, appViewKeysSorted, faceBoxNonDefaults, overflowNonDefault, stepViewIndex,
cssWeight, faceDecoration, boxCss, faceCss, composeHoverTitle,
+ clampHeight, HEIGHT_MIN, HEIGHT_MAX,
} from './app-core.js';
import { planPaletteGenerator, entriesForGeneratedColumn } from './palette-generator-core.js';
import { oklch2hex, deltaE } from './colormath.js';
@@ -818,35 +819,34 @@ test('slugify: Error — an all-disallowed name falls back to "theme"', () => {
// Guards the one-source-of-truth contract, same as the colormath integrity test:
// the page must carry app-core.js's body (sans exports) verbatim. Requires
// `python3 generate.py` to have run first.
-const stripExports = (s) =>
- s.split('\n').filter((l) => !(l.startsWith('export') || l.startsWith('import'))).join('\n').replace(/\s+$/, '');
+import { stripInlinedBody } from './inline-strip.mjs';
test('inline-integrity: theme-studio.html contains the app-core.js body verbatim', () => {
- const body = stripExports(readFileSync(here + 'app-core.js', 'utf8'));
+ const body = stripInlinedBody(readFileSync(here + 'app-core.js', 'utf8'));
const html = readFileSync(here + 'theme-studio.html', 'utf8');
assert.ok(html.includes(body), 'generated page is missing the app-core.js body verbatim');
});
test('inline-integrity: theme-studio.html contains palette-generator-core.js verbatim', () => {
- const body = stripExports(readFileSync(here + 'palette-generator-core.js', 'utf8'));
+ const body = stripInlinedBody(readFileSync(here + 'palette-generator-core.js', 'utf8'));
const html = readFileSync(here + 'theme-studio.html', 'utf8');
assert.ok(html.includes(body), 'generated page is missing palette-generator-core.js verbatim');
});
test('inline-integrity: theme-studio.html contains palette-generator-ui.js verbatim', () => {
- const body = stripExports(readFileSync(here + 'palette-generator-ui.js', 'utf8'));
+ const body = stripInlinedBody(readFileSync(here + 'palette-generator-ui.js', 'utf8'));
const html = readFileSync(here + 'theme-studio.html', 'utf8');
assert.ok(html.includes(body), 'generated page is missing palette-generator-ui.js verbatim');
});
test('inline-integrity: theme-studio.html contains palette-actions.js verbatim', () => {
- const body = stripExports(readFileSync(here + 'palette-actions.js', 'utf8'));
+ const body = stripInlinedBody(readFileSync(here + 'palette-actions.js', 'utf8'));
const html = readFileSync(here + 'theme-studio.html', 'utf8');
assert.ok(html.includes(body), 'generated page is missing palette-actions.js verbatim');
});
test('inline-integrity: theme-studio.html contains browser-gates.js verbatim', () => {
- const body = stripExports(readFileSync(here + 'browser-gates.js', 'utf8'));
+ const body = stripInlinedBody(readFileSync(here + 'browser-gates.js', 'utf8'));
const html = readFileSync(here + 'theme-studio.html', 'utf8');
assert.ok(html.includes(body), 'generated page is missing browser-gates.js verbatim');
});
@@ -900,23 +900,6 @@ test('resolveUiAttr: a face with no inherit and an unset attribute returns null'
assert.equal(resolveUiAttr('region', 'bg', { 'region': { bg: null } }), null);
});
-// dropdownRowTextColor: a popup row showing a real palette color inherits the
-// popup foreground (legible on the fixed dark popup); only the filled default
-// row uses a contrast color against its own background. textOn is stubbed so the
-// test asserts the decision, not the contrast math.
-const stubTextOn = (h) => (h === '#000000' ? '#fff' : '#000');
-test('dropdownRowTextColor: a real palette color inherits the popup fg (empty)', () => {
- assert.equal(dropdownRowTextColor('#2a3a5a', '#2a3a5a', stubTextOn), '');
-});
-test('dropdownRowTextColor: a dark swatch still inherits (regression: blues were unreadable)', () => {
- assert.equal(dropdownRowTextColor('#000000', '#000000', stubTextOn), '');
-});
-test('dropdownRowTextColor: the filled default row contrasts against its fill', () => {
- assert.equal(dropdownRowTextColor('', '#cdced1', stubTextOn), '#000');
-});
-test('dropdownRowTextColor: a default row with no fill inherits (empty)', () => {
- assert.equal(dropdownRowTextColor('', '', stubTextOn), '');
-});
// appViewKeysSorted: the assignment-view dropdown lists package apps
// alphabetically by display label, independent of the APPS build order
@@ -1152,3 +1135,39 @@ test('composeHoverTitle: Error — neither doc nor base returns empty string', (
assert.equal(composeHoverTitle(null, null), '');
assert.equal(composeHoverTitle(undefined, ''), '');
});
+
+// --- clampHeight: coerce a height-field value to null (unset) or an in-range number ---
+test('clampHeight: bounds are the agreed Emacs-floor / studio-ceiling pair', () => {
+ assert.equal(HEIGHT_MIN, 0.1);
+ assert.equal(HEIGHT_MAX, 2.0);
+});
+test('clampHeight: Normal — an in-range value passes through unchanged', () => {
+ assert.equal(clampHeight('1.2'), 1.2);
+ assert.equal(clampHeight('0.5'), 0.5);
+ assert.equal(clampHeight(1.0), 1.0);
+});
+test('clampHeight: Boundary — the exact min and max are kept', () => {
+ assert.equal(clampHeight('0.1'), 0.1);
+ assert.equal(clampHeight('2.0'), 2.0);
+ assert.equal(clampHeight(0.1), 0.1);
+});
+test('clampHeight: Boundary — out-of-range snaps to the nearer bound', () => {
+ assert.equal(clampHeight('5'), 2.0); // above max
+ assert.equal(clampHeight('0.05'), 0.1); // below the Emacs floor
+ assert.equal(clampHeight('0'), 0.1); // zero is not unset; it clamps up
+ assert.equal(clampHeight('-3'), 0.1); // negative clamps up
+});
+test('clampHeight: Boundary — blank or whitespace is unset (null)', () => {
+ assert.equal(clampHeight(''), null);
+ assert.equal(clampHeight(' '), null);
+ assert.equal(clampHeight(null), null);
+ assert.equal(clampHeight(undefined), null);
+});
+test('clampHeight: Error — non-numeric text is unset (null), not NaN', () => {
+ assert.equal(clampHeight('abc'), null);
+ assert.equal(clampHeight('1.2x'), 1.2); // parseFloat reads the leading number
+});
+test('clampHeight: caller may override the bounds', () => {
+ assert.equal(clampHeight('5', 0.1, 3.0), 3.0);
+ assert.equal(clampHeight('0.2', 0.5, 3.0), 0.5);
+});