import assert from "node:assert/strict"; import { readFile } from "node:fs/promises"; import test from "node:test"; const settingsUrl = new URL("../app/static/views/settings.js", import.meta.url); test("settings brightness explains an active temporary display-test override", async () => { const source = await readFile(settingsUrl, "utf8"); assert.match(source, /displayTestActive = state\?\.display_test\?\.active === true/); assert.match(source, /用户亮度 \$\{user\}% 已保存,但当前由\$\{suffix\}覆盖/); assert.match(source, /state\?\.display_test\?\.brightness/); }); test("settings exposes full OTA upload progress and service recovery polling", async () => { const [source, html, css] = await Promise.all([ readFile(settingsUrl, "utf8"), readFile(new URL("../app/static/index.html", import.meta.url), "utf8"), readFile(new URL("../app/static/style.css", import.meta.url), "utf8"), ]); assert.match(html, /

软件版本<\/h3>/); assert.match(html, /最新功能更新时间/); assert.match(html, /id="ota-feature-updated-at"/); assert.match(html, />导入 OTA 更新<\/button>/); assert.match(html, /class="ota-power-warning">不要在更新期间断电。<\/span>/); assert.doesNotMatch(html, /软件更新|从本机选择完整 OTA 更新包|最近一次 OTA 更新/); assert.doesNotMatch(html, /ota-last-update|ota-selected-file/); assert.match(css, /\.ota-power-warning\s*{[^}]*color:\s*var\(--text\)/s); assert.match(source, /new XMLHttpRequest\(\)/); assert.match(source, /\/api\/ota\/update\?filename=/); assert.match(source, /request\.upload\.addEventListener\("progress"/); assert.match(source, /fetch\("\/api\/ota\/status"/); assert.match(source, /status\?\.feature_updated_at/); assert.match(source, /timeZone: "Asia\/Shanghai"/); assert.match(source, /(北京时间)/); assert.match(source, /设备正在切换软件版本,等待服务恢复/); assert.doesNotMatch(source, /otaLastUpdate|otaLastVersion|otaLastPackagedAt|otaLastInstalledAt|otaLastResult/); assert.match(source, /job\?\.phase === "complete"/); assert.match(source, /otaProgressGroup\.hidden = true/); assert.doesNotMatch(source, /showOtaProgress\(100, "更新完成"\)/); assert.doesNotMatch(source, /更新完成,正在载入新版本页面/); }); test("settings automatically opens and safely copies a detailed OTA failure log", async () => { const [source, html, css] = await Promise.all([ readFile(settingsUrl, "utf8"), readFile(new URL("../app/static/index.html", import.meta.url), "utf8"), readFile(new URL("../app/static/style.css", import.meta.url), "utf8"), ]); assert.match(html, /id="ota-failure-log-dialog"[\s\S]*OTA 更新失败日志/); assert.match(html, /id="ota-failure-log-content"[^>]*tabindex="0"/); assert.match(html, /复制全部日志/); assert.match(html, /查看失败日志/); assert.match(source, /fetch\("\/api\/ota\/failure-log", \{ cache: "no-store" \}\)/); assert.match(source, /otaFailureLogContent\.textContent = text/); assert.match(source, /otaFailureLogDialog\.showModal\(\)/); assert.match(source, /navigator\.clipboard\?\.writeText/); assert.match(source, /document\.createElement\("textarea"\)/); assert.match(source, /document\.execCommand\("copy"\)/); assert.match(source, /status\.failure_log_available/); assert.match(css, /\.ota-failure-log-dialog pre\s*{[^}]*overflow:\s*auto/s); assert.doesNotMatch(source, /otaFailureLogContent\.innerHTML/); }); test("settings exposes a transactional performance-mode switch with the fixed warning", async () => { const [source, index] = await Promise.all([ readFile(settingsUrl, "utf8"), readFile(new URL("../app/static/index.html", import.meta.url), "utf8"), ]); assert.match(index, /id="performance-mode-enabled"/); assert.match(index, /如果使用出现卡顿,可以打开此选项,但会降低续航。/); assert.match(source, /JSON\.stringify\(\{ performance_mode_enabled: requested \}\)/); assert.match(source, /syncPerformanceModeStatus\(detail\.system\?\.performance_mode\)/); assert.match(source, /status\.requested === true && status\.effective === true/); assert.match(source, /CPU 调频策略不可用/); }); test("settings exposes persisted animation preview concurrency below performance mode", async () => { const [source, app, index] = await Promise.all([ readFile(settingsUrl, "utf8"), readFile(new URL("../app/static/app.js", import.meta.url), "utf8"), readFile(new URL("../app/static/index.html", import.meta.url), "utf8"), ]); const performanceAt = index.indexOf('

性能模式

'); const concurrencyAt = index.indexOf('

模板界面同时播放的动图数量

'); assert.ok(performanceAt >= 0 && concurrencyAt > performanceAt); assert.match(index, /id="animation-preview-max-concurrent"[\s\S]*min="1"[\s\S]*max="50"[\s\S]*step="1"/); assert.match(index, /不建议开启太多,否则会出现严重的性能问题。/); assert.match(source, /JSON\.stringify\(\{ animation_preview_max_concurrent: requested \}\)/); assert.match(source, /setAnimationPreviewMaxConcurrent\(saved\)/); assert.match(source, /showAnimationPreviewMaxConcurrent\(previous\)/); assert.match(app, /config\.animation_preview_max_concurrent/); assert.match(app, /ANIMATION_PREVIEW_DEFAULT_MAX_CONCURRENT/); });