-
Notifications
You must be signed in to change notification settings - Fork 10.7k
Expand file tree
/
Copy pathhome-reveal-progressive-enhancement.test.ts
More file actions
51 lines (46 loc) · 2.01 KB
/
Copy pathhome-reveal-progressive-enhancement.test.ts
File metadata and controls
51 lines (46 loc) · 2.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import assert from 'node:assert/strict';
import { readFileSync } from 'node:fs';
import { test } from 'node:test';
const stylesSource = readFileSync(new URL('../app/globals.css', import.meta.url), 'utf8');
const homepageSource = readFileSync(new URL('../app/pages/index.astro', import.meta.url), 'utf8');
const sharedEnhancerSource = readFileSync(
new URL('../app/_components/home-enhancer.astro', import.meta.url),
'utf8',
);
test('keeps reveal content visible until the animation observer is ready', () => {
assert.match(
stylesSource,
/\[data-reveal\]\s*\{[\s\S]*?opacity:\s*1;[\s\S]*?translate:\s*0 0;[\s\S]*?\}/,
);
assert.match(
stylesSource,
/\.reveal-ready \[data-reveal\]:not\(\[data-revealed='true'\]\)\s*\{[\s\S]*?opacity:\s*0;/,
);
assert.match(
stylesSource,
/\.blur-word\s*\{[\s\S]*?opacity:\s*1;[\s\S]*?filter:\s*none;[\s\S]*?transform:\s*none;/,
);
assert.match(stylesSource, /\.reveal-ready \.blur-word\s*\{[\s\S]*?opacity:\s*0;/);
});
test('preserves the hero and mobile CTA reveal exceptions after readiness', () => {
assert.match(
stylesSource,
/\.reveal-ready \.hero h1\.hero-title\[data-reveal\]\s*\{[\s\S]*?opacity:\s*1;[\s\S]*?translate:\s*0 0;/,
);
assert.match(
stylesSource,
/@media \(max-width:\s*720px\)[\s\S]*?\.reveal-ready \.cta-window\[data-reveal\]:not\(\[data-revealed='true'\]\)\s*\{\s*translate:\s*0 0;/,
);
});
for (const [name, source] of [
['canonical homepage', homepageSource],
['shared homepage enhancer', sharedEnhancerSource],
] as const) {
test(`${name} enables reveal styles only after observer binding succeeds`, () => {
const observeIndex = source.indexOf('observer.observe(el)');
const readyIndex = source.indexOf("classList.add('reveal-ready')");
assert.notEqual(observeIndex, -1, `${name} does not bind reveal elements`);
assert.ok(readyIndex > observeIndex, `${name} enables hidden states before observer binding`);
assert.match(source, /catch \(error\)[\s\S]*?classList\.remove\('reveal-ready'\)/);
});
}