test: 重构测试体系 — 建立组件测试层、补充后端测试、清理低质量测试
- 新增 jsdom + @testing-library/react 组件测试环境 - 新增 12 个组件测试,覆盖所有前端组件 - 补充后端 middleware 和 helpers 单元测试 - 删除伪测试 use-target-detail-logic.test.ts - 精简过度枚举的 color-threshold.test.ts - 新增 bunfig.toml 配置测试 preload - 更新 DEVELOPMENT.md 测试章节 - 安装 @types/jsdom 修复类型声明
This commit is contained in:
31
tests/web/components/StatusBar.test.tsx
Normal file
31
tests/web/components/StatusBar.test.tsx
Normal file
@@ -0,0 +1,31 @@
|
||||
import "../../../tests/web/test-utils";
|
||||
import { render } from "@testing-library/react";
|
||||
import { describe, expect, test } from "bun:test";
|
||||
|
||||
import type { RecentSample } from "../../../src/shared/api";
|
||||
|
||||
import { StatusBar } from "../../../src/web/components/StatusBar";
|
||||
|
||||
describe("StatusBar", () => {
|
||||
const now = new Date().toISOString();
|
||||
|
||||
const samples: RecentSample[] = [
|
||||
{ durationMs: 100, timestamp: now, up: true },
|
||||
{ durationMs: 150, timestamp: new Date(Date.now() - 60000).toISOString(), up: false },
|
||||
];
|
||||
|
||||
test("渲染不崩溃", () => {
|
||||
const { container } = render(<StatusBar maxSlots={5} samples={samples} />);
|
||||
expect(container.firstChild).not.toBeNull();
|
||||
});
|
||||
|
||||
test("默认 maxSlots 不崩溃", () => {
|
||||
const { container } = render(<StatusBar samples={samples} />);
|
||||
expect(container.firstChild).not.toBeNull();
|
||||
});
|
||||
|
||||
test("空 samples 不崩溃", () => {
|
||||
const { container } = render(<StatusBar maxSlots={3} samples={[]} />);
|
||||
expect(container.firstChild).not.toBeNull();
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user