aboutsummaryrefslogtreecommitdiff
path: root/scripts/theme-studio/test-app-util.mjs
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/theme-studio/test-app-util.mjs')
-rw-r--r--scripts/theme-studio/test-app-util.mjs33
1 files changed, 28 insertions, 5 deletions
diff --git a/scripts/theme-studio/test-app-util.mjs b/scripts/theme-studio/test-app-util.mjs
index 2cb08e0e6..057f55f8d 100644
--- a/scripts/theme-studio/test-app-util.mjs
+++ b/scripts/theme-studio/test-app-util.mjs
@@ -5,10 +5,35 @@ import { test } from 'node:test';
import assert from 'node:assert/strict';
import { readFileSync } from 'node:fs';
import { fileURLToPath } from 'node:url';
-import { normHex, ratingColor, textOn } from './app-util.js';
+import { normHex, ratingColor, textOn, contrastTitle } from './app-util.js';
const here = fileURLToPath(new URL('.', import.meta.url));
+// contrastTitle: the hover text for a contrast number, naming the color tier
+// (green AAA / grey AA / red fail) so the verdict word can be dropped from the cell.
+test('contrastTitle: green tier (>=7) names AAA', () => {
+ const t = contrastTitle(8.2);
+ assert.match(t, /green/i);
+ assert.match(t, /AAA/);
+ assert.match(t, /^8\.2:1/);
+});
+test('contrastTitle: grey tier (4.5..7) passes AA, not AAA', () => {
+ const t = contrastTitle(5.4);
+ assert.match(t, /grey|gray/i);
+ assert.match(t, /AA/);
+ assert.match(t, /not AAA|below AAA/i);
+});
+test('contrastTitle: red tier (<4.5) fails AA', () => {
+ const t = contrastTitle(3.1);
+ assert.match(t, /red/i);
+ assert.match(t, /fail/i);
+});
+test('contrastTitle: boundaries — 7 is green, 4.5 is grey, just under is red', () => {
+ assert.match(contrastTitle(7), /green/i);
+ assert.match(contrastTitle(4.5), /grey|gray/i);
+ assert.match(contrastTitle(4.49), /red/i);
+});
+
test('normHex: Normal — adds the #, lowercases, accepts an existing #', () => {
assert.equal(normHex('67809C'), '#67809c');
assert.equal(normHex('#E8BD30'), '#e8bd30');
@@ -59,12 +84,10 @@ test('textOn: Boundary — straddles the ~0.179 luminance crossover', () => {
// Inline-integrity: the page must carry app-util.js's body (sans import/export)
// verbatim — the same strip generate.py applies. Requires `python3 generate.py`.
-const stripModule = (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-util.js body verbatim', () => {
- const body = stripModule(readFileSync(here + 'app-util.js', 'utf8'));
+ const body = stripInlinedBody(readFileSync(here + 'app-util.js', 'utf8'));
const html = readFileSync(here + 'theme-studio.html', 'utf8');
assert.ok(html.includes(body), 'generated page is missing the app-util.js body verbatim');
});