Skip to content

Commit d555ca1

Browse files
committed
feat(knowledge): 体系徽标小组件(触点①组件)
1 parent 979cfd9 commit d555ca1

2 files changed

Lines changed: 60 additions & 0 deletions

File tree

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// @vitest-environment jsdom
2+
/**
3+
* SystemBadge.test.tsx — 体系徽标(v0.13.7 触点①)。
4+
*
5+
* @ai-context: 纯展示组件——组行小字区显示关联体系名;无引用计数时
6+
* 只显示名字,有计数时显示"名 · N 引用"。
7+
*/
8+
import { afterEach, describe, expect, it, vi } from "vitest";
9+
import { cleanup, render, screen } from "@testing-library/react";
10+
import SystemBadge from "./SystemBadge";
11+
12+
describe("SystemBadge", () => {
13+
it("显示体系名与引用计数(有计数)", () => {
14+
render(<SystemBadge name="摄影" linkCount={3} onClick={vi.fn()} />);
15+
expect(screen.getByTestId("system-badge").textContent).toContain("摄影");
16+
expect(screen.getByTestId("system-badge").textContent).toContain("3");
17+
});
18+
19+
it("无引用计数时不显示计数", () => {
20+
render(<SystemBadge name="摄影" linkCount={0} onClick={vi.fn()} />);
21+
expect(screen.getByTestId("system-badge").textContent).not.toContain("0");
22+
});
23+
24+
it("点击触发 onClick", () => {
25+
const onClick = vi.fn();
26+
render(<SystemBadge name="摄影" linkCount={0} onClick={onClick} />);
27+
screen.getByTestId("system-badge").click();
28+
expect(onClick).toHaveBeenCalledTimes(1);
29+
});
30+
});
31+
32+
afterEach(() => cleanup());

‎app/src/components/SystemBadge.tsx‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/**
2+
* SystemBadge — 体系徽标(v0.13.7 触点① 组行)。
3+
*
4+
* @ai-context: 纯展示——组行小字区显示"该组被哪个体系引用";点击跳转
5+
* 体系页(onClick 由父级接线)。linkCount>0 时显示计数,
6+
* 否则仅名字(零噪音——无引用不出现该组件本身)。
7+
*/
8+
interface Props {
9+
name: string;
10+
linkCount: number;
11+
onClick: () => void;
12+
}
13+
14+
export default function SystemBadge({ name, linkCount, onClick }: Props) {
15+
return (
16+
<button
17+
data-testid="system-badge"
18+
onClick={(e) => { e.stopPropagation(); onClick(); }}
19+
style={{
20+
fontSize: 10, cursor: "pointer", borderRadius: 8, padding: "0 5px",
21+
background: "#f0fdfa", color: "#0f766e", border: "1px solid #99f6e4",
22+
}}
23+
title={linkCount > 0 ? `该组为体系「${name}」提供 ${linkCount} 处引用` : `体系「${name}」`}
24+
>
25+
🧭 {name}{linkCount > 0 ? ` · ${linkCount}` : ""}
26+
</button>
27+
);
28+
}

0 commit comments

Comments
 (0)