|
| 1 | +import { test } from 'node:test'; |
| 2 | +import assert from 'node:assert/strict'; |
| 3 | +import { readFile } from 'node:fs/promises'; |
| 4 | + |
| 5 | +const startupShellPath = new URL('../../ui/index.html', import.meta.url); |
| 6 | +const startupCopyConfigPath = new URL('../../ui/startup-copy.js', import.meta.url); |
| 7 | + |
| 8 | +test('startup shell loads shared copy config, reuses applyStartupMode, and exposes a focused live region', async () => { |
| 9 | + const source = await readFile(startupShellPath, 'utf8'); |
| 10 | + const configSource = await readFile(startupCopyConfigPath, 'utf8').catch(() => ''); |
| 11 | + |
| 12 | + assert.match( |
| 13 | + source, |
| 14 | + /<script src="\.\/startup-copy\.js"><\/script>/, |
| 15 | + 'expected startup shell to load a dedicated startup copy config', |
| 16 | + ); |
| 17 | + |
| 18 | + assert.match( |
| 19 | + source, |
| 20 | + /<span id="startup-status"[^>]*role="status"[^>]*aria-live="polite"[^>]*><\/span>/, |
| 21 | + 'expected the status text element to be the polite live region', |
| 22 | + ); |
| 23 | + assert.doesNotMatch( |
| 24 | + source, |
| 25 | + /aria-atomic="true"/, |
| 26 | + 'expected startup shell to avoid verbose atomic live region announcements', |
| 27 | + ); |
| 28 | + |
| 29 | + assert.doesNotMatch( |
| 30 | + source, |
| 31 | + /<h1 id="startup-title" class="title">[^<]+<\/h1>/, |
| 32 | + 'expected startup title to be populated from STARTUP_COPY instead of duplicated static copy', |
| 33 | + ); |
| 34 | + assert.doesNotMatch( |
| 35 | + source, |
| 36 | + /<p id="startup-desc" class="desc">[^<]+<\/p>/, |
| 37 | + 'expected startup description to be populated from STARTUP_COPY instead of duplicated static copy', |
| 38 | + ); |
| 39 | + assert.doesNotMatch( |
| 40 | + source, |
| 41 | + /<span id="startup-status">[^<]+<\/span>/, |
| 42 | + 'expected startup status to be populated from STARTUP_COPY instead of duplicated static copy', |
| 43 | + ); |
| 44 | + |
| 45 | + assert.doesNotMatch( |
| 46 | + source, |
| 47 | + /const\s+STARTUP_COPY\s*=/, |
| 48 | + 'expected startup copy to be defined in a dedicated config instead of inline', |
| 49 | + ); |
| 50 | + assert.match( |
| 51 | + source, |
| 52 | + /const\s+startupShell\s*=\s*window\.astrbot\.startupShell;/, |
| 53 | + 'expected startup shell to read its shared config from a named astrbot namespace', |
| 54 | + ); |
| 55 | + assert.match( |
| 56 | + source, |
| 57 | + /const\s+\{\s*STARTUP_MODES,\s*STARTUP_COPY\s*\}\s*=\s*startupShell;/, |
| 58 | + 'expected startup shell to destructure startup config from the namespaced object', |
| 59 | + ); |
| 60 | + assert.doesNotMatch( |
| 61 | + source, |
| 62 | + /const\s+initialCopy\s*=/, |
| 63 | + 'expected initial render to reuse applyStartupMode instead of duplicating copy application', |
| 64 | + ); |
| 65 | + assert.match( |
| 66 | + source, |
| 67 | + /applyStartupMode\(STARTUP_MODES\.LOADING\);/, |
| 68 | + 'expected startup shell to initialize through applyStartupMode', |
| 69 | + ); |
| 70 | + assert.match( |
| 71 | + source, |
| 72 | + /if\s*\(status\.textContent\s*===\s*next\.status\)\s*return;/, |
| 73 | + 'expected startup shell to skip duplicate status announcements', |
| 74 | + ); |
| 75 | + |
| 76 | + assert.match( |
| 77 | + configSource, |
| 78 | + /const\s+deepFreeze\s*=\s*\(obj\)\s*=>/, |
| 79 | + 'expected shared startup copy config to use a deepFreeze helper', |
| 80 | + ); |
| 81 | + assert.match( |
| 82 | + configSource, |
| 83 | + /const\s+STARTUP_MODES\s*=\s*\{/, |
| 84 | + 'expected shared startup copy config to define startup modes', |
| 85 | + ); |
| 86 | + assert.match( |
| 87 | + configSource, |
| 88 | + /window\.astrbot\s*=\s*window\.astrbot\s*\|\|\s*\{\};/, |
| 89 | + 'expected shared startup copy config to allocate the astrbot namespace', |
| 90 | + ); |
| 91 | + assert.match( |
| 92 | + configSource, |
| 93 | + /window\.astrbot\.startupShell\s*=\s*deepFreeze\(/, |
| 94 | + 'expected shared startup copy config to expose startup shell under the astrbot namespace', |
| 95 | + ); |
| 96 | + assert.match( |
| 97 | + configSource, |
| 98 | + /STARTUP_COPY:\s*\{/, |
| 99 | + 'expected shared startup copy config to define localized startup copy', |
| 100 | + ); |
| 101 | + assert.match( |
| 102 | + configSource, |
| 103 | + /en:\s*\{/, |
| 104 | + 'expected shared startup copy config to include English startup copy', |
| 105 | + ); |
| 106 | + assert.match( |
| 107 | + configSource, |
| 108 | + /zh:\s*\{/, |
| 109 | + 'expected shared startup copy config to include Chinese startup copy', |
| 110 | + ); |
| 111 | +}); |
0 commit comments