- feat(client): 增加裁判比赛计时、技术暂停与选手端局域网同步 - feat(armor): 红蓝共用通用固件,按客户端选队并显示网络连接状态 - feat(armor): 仅在对局进行中允许扣血,其他阶段保留受击闪烁 - feat(client): 将计时置于血条中间并增加开赛前五秒全屏动画 - fix(client): 修复连续血条、对手镜像和图传断连灰度遮罩 - fix(client): 统一界面中文字体并整理各页面文案 - fix(maintenance): 备份迁移装甲板分区,恢复 SDK 构建与固件打包 - refactor(repo): 按 armor、vt 和 client 整理工程与脚本,移除旧参考实现 - test: 补充线路、受击许可、回环 UDP、维护和 HUD 验证 - docs: 同步构建、协议、比赛控制和硬件验证边界 验证:前端构建与 19 项相关测试通过;核心 91 项单元测试与 2 项回环 UDP 集成测试通过;装甲板规则 25 项、线路 26 项、Tauri 51 项测试通过;独立探测器 5 项与目录回归 4 项通过。完成 C3 两组阈值实际编译、导出与 ZIP 校验,检查 900×600 / 1280×720 页面、倒计时和随包中文字体。 未执行烧录、板上运行、跨电脑广播或硬件稳定性验证。
144 lines
6.5 KiB
JavaScript
144 lines
6.5 KiB
JavaScript
import { readFileSync } from "node:fs";
|
|
import { createRequire } from "node:module";
|
|
import assert from "node:assert/strict";
|
|
import { test } from "node:test";
|
|
import { createElement } from "react";
|
|
import { renderToStaticMarkup } from "react-dom/server";
|
|
import ts from "typescript";
|
|
|
|
const require = createRequire(import.meta.url);
|
|
function load(path, overrides) {
|
|
const source = readFileSync(new URL(path, import.meta.url), "utf8");
|
|
const compiled = ts.transpileModule(source, {
|
|
fileName: path,
|
|
compilerOptions: { module: ts.ModuleKind.CommonJS, target: ts.ScriptTarget.ES2022, jsx: ts.JsxEmit.ReactJSX },
|
|
}).outputText;
|
|
const exports = {};
|
|
new Function("require", "exports", compiled)(id => overrides[id] ?? require(id), exports);
|
|
return exports;
|
|
}
|
|
|
|
const format = { teamColor: team => team === 0 ? "red" : "blue", teamName: team => `队伍${team}`, idText: String, firmwareLabel: () => "测试固件" };
|
|
const healthModule = load("../src/components/HealthBar.tsx", { "../lib/format": format });
|
|
const videoModule = load("../src/components/VideoSurface.tsx", { "../lib/store": {}, "../lib/reticle": {} });
|
|
let connected = true;
|
|
const matchTime = load("../src/lib/match-time.ts", {});
|
|
const matchModule = load("../src/components/MatchClock.tsx", {
|
|
"./Dialog": {}, "../lib/ipc": {},
|
|
"../lib/store": { useAppStore: () => ({ connected }) },
|
|
"../lib/match-time": matchTime,
|
|
});
|
|
const { TeamPage } = load("../src/pages/TeamPage.tsx", {
|
|
"../components/HealthBar": healthModule,
|
|
"../components/VideoSurface": videoModule,
|
|
"../components/HitFlash": { HitFlash: () => null },
|
|
"../components/MatchBanner": { MatchBanner: () => null },
|
|
"../components/MatchClock": matchModule,
|
|
"../lib/format": format,
|
|
"../lib/store": { useAppStore: () => ({ connected, lastHit: null }) },
|
|
"../lib/version": { BUILD: { protocol: 1 } },
|
|
});
|
|
|
|
const config = { visible: true, width: 0.42, pulse: false, lowThreshold: 31, showTeamName: true, showNumbers: true };
|
|
const health = { team: 0, name: "测试队伍", available: true, hp: 100, placeholder: "装甲板未接入", critical: false };
|
|
const renderHealth = (hp, align = "left", changes = {}) => renderToStaticMarkup(createElement(healthModule.HealthBar, {
|
|
health: { ...health, hp, ...changes }, config, align,
|
|
}));
|
|
|
|
test("health length follows every HP value continuously on both sides, including one HP and zero", () => {
|
|
for (const align of ["left", "right"]) {
|
|
for (const hp of [0, 1, 17, 19.5, 37, 99, 100, -3, 104]) {
|
|
const html = renderHealth(hp, align);
|
|
const expected = Math.max(0, Math.min(100, hp));
|
|
assert.match(html, new RegExp(`class="hp__fill" style="width:${expected}%`));
|
|
assert.doesNotMatch(html, /hp__cell/);
|
|
}
|
|
}
|
|
});
|
|
|
|
test("an unavailable armor board has an empty track and a missing-data label", () => {
|
|
const html = renderHealth(75, "right", { available: false });
|
|
assert.match(html, /hp__fill" style="width:0%/);
|
|
assert.match(html, /装甲板未接入/);
|
|
assert.doesNotMatch(html, /hp__value|hp__impact/);
|
|
});
|
|
|
|
test("the low-health marker uses the exact threshold in the track's mirrored coordinates", () => {
|
|
for (const align of ["left", "right"]) {
|
|
assert.match(renderHealth(37, align), /hp__threshold" style="left:31%/);
|
|
}
|
|
});
|
|
|
|
function snapshot() {
|
|
return {
|
|
config: { cameraId: 1, armorId: 2, teamNames: ["我方", "对手"] },
|
|
team: 0, mirrored: false, demo: false,
|
|
cameras: [{ id: 1, idText: "1", online: true, compatible: true }],
|
|
armorBoards: [{ id: 2, online: true, team: 0 }],
|
|
stats: [{ camera: 1, online: true, hasFrames: true, fps: 20 }],
|
|
matchClock: { phase: "running", remainingMs: 93_000, elapsedMs: 87_000, connected: true, freshForMs: 1500, source: "测试裁判" },
|
|
health: [health, { ...health, team: 1 }],
|
|
};
|
|
}
|
|
const renderTeam = value => renderToStaticMarkup(createElement(TeamPage, {
|
|
snapshot: value, hud: { health: config, hitFeedback: {}, showZoom: false }, calibrating: false, onCalibrate() {},
|
|
}));
|
|
|
|
test("health bars occupy the operator HUD's first row", () => {
|
|
const html = renderTeam(snapshot());
|
|
assert.ok(html.indexOf('class="cockpit__health"') < html.indexOf('class="cockpit__header"'));
|
|
assert.ok(html.indexOf('class="hp hp--left') < html.indexOf('class="team-match-clock'));
|
|
assert.ok(html.indexOf('class="team-match-clock') < html.indexOf('class="hp hp--right'));
|
|
assert.doesNotMatch(html, /match-readout|match-countdown__number/);
|
|
});
|
|
|
|
test("only the last five connected countdown seconds cover the operator view", () => {
|
|
const value = snapshot();
|
|
for (const [remainingMs, expected] of [[6000, null], [5000, 5], [4001, 5], [4000, 4], [1, 1], [0, null]]) {
|
|
value.matchClock = { ...value.matchClock, phase: "countdown", remainingMs };
|
|
const html = renderTeam(value);
|
|
if (expected == null) assert.doesNotMatch(html, /aria-label="开赛全屏倒计时"/);
|
|
else assert.match(html, new RegExp(`aria-atomic="true">${expected}</strong>`));
|
|
}
|
|
for (const phase of ["preparation", "ready", "running", "paused", "finished"]) {
|
|
value.matchClock.phase = phase;
|
|
value.matchClock.remainingMs = 4000;
|
|
assert.doesNotMatch(renderTeam(value), /aria-label="开赛全屏倒计时"/);
|
|
}
|
|
value.matchClock.phase = "countdown";
|
|
value.matchClock.connected = false;
|
|
assert.doesNotMatch(renderTeam(value), /aria-label="开赛全屏倒计时"/);
|
|
value.matchClock.connected = true;
|
|
connected = false;
|
|
assert.doesNotMatch(renderTeam(value), /aria-label="开赛全屏倒计时"/);
|
|
connected = true;
|
|
});
|
|
|
|
test("the last frame is masked for camera loss, backend loss, missing binding, or missing frames, and recovers", () => {
|
|
const cases = [
|
|
value => { value.cameras[0].online = false; },
|
|
value => { value.stats[0].online = false; },
|
|
value => { value.cameras[0].compatible = false; },
|
|
value => { value.stats[0].hasFrames = false; },
|
|
value => { value.config.cameraId = null; },
|
|
value => { value.cameras = []; },
|
|
() => { connected = false; },
|
|
];
|
|
for (const change of cases) {
|
|
const value = snapshot();
|
|
change(value);
|
|
const lost = renderTeam(value);
|
|
assert.match(lost, /vsurface--signal-lost/);
|
|
assert.match(lost, /vsurface__signal-mask/);
|
|
assert.match(lost, /<canvas/);
|
|
connected = true;
|
|
assert.doesNotMatch(renderTeam(snapshot()), /vsurface--signal-lost|vsurface__signal-mask/);
|
|
}
|
|
});
|
|
|
|
test("an armor outage alone does not gray the live video", () => {
|
|
const value = snapshot();
|
|
value.armorBoards[0].online = false;
|
|
assert.doesNotMatch(renderTeam(value), /vsurface--signal-lost|vsurface__signal-mask/);
|
|
});
|