prompt-drawer.test.tsx 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. import { fireEvent, render, screen } from "@testing-library/react";
  2. import { describe, expect, it, vi } from "vitest";
  3. import { PromptDrawer } from "@/components/decision/PromptDrawer";
  4. describe("PromptDrawer truth labels", () => {
  5. const prompt = {
  6. promptRef: "prompt:event:50",
  7. actor: { role: "implementer" as const, label: "实现 Agent" },
  8. exactTask: { content: "补齐烹饪步骤", accuracy: "run-exact" as const },
  9. systemPrompt: {
  10. content: "按当前实现 Agent 规则完成任务。",
  11. source: "current-db" as const,
  12. version: 8,
  13. accuracy: "current-not-run-snapshot" as const,
  14. truncated: false,
  15. },
  16. notices: [{
  17. code: "PROMPT_NOT_SNAPSHOTTED",
  18. message: "系统没有保存这次运行所用提示词的历史快照;下方展示当前提示词。",
  19. }],
  20. };
  21. it("separates the exact run task from the current rule version", () => {
  22. render(<PromptDrawer prompt={prompt} loading={false} onClose={vi.fn()} />);
  23. expect(screen.getByRole("heading", { name: "本次真实任务" })).toBeInTheDocument();
  24. expect(screen.getByText("补齐烹饪步骤")).toBeInTheDocument();
  25. expect(screen.getByRole("heading", { name: "当前提示词" })).toBeInTheDocument();
  26. expect(screen.getByText("当前数据库版本 · v8")).toBeInTheDocument();
  27. expect(screen.getByText(/没有保存这次运行所用提示词的历史快照/)).toBeInTheDocument();
  28. expect(screen.queryByText("当次运行完整 Prompt")).not.toBeInTheDocument();
  29. });
  30. it("closes with Escape and starts focus on the close button", () => {
  31. const onClose = vi.fn();
  32. render(<PromptDrawer prompt={prompt} loading={false} onClose={onClose} />);
  33. expect(screen.getByRole("button", { name: "关闭提示词" })).toHaveFocus();
  34. fireEvent.keyDown(window, { key: "Escape" });
  35. expect(onClose).toHaveBeenCalledTimes(1);
  36. });
  37. });