script-table.test.tsx 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. import { fireEvent, render, screen } from "@testing-library/react";
  2. import { describe, expect, it, vi } from "vitest";
  3. import { ScriptTable } from "@/components/artifact/ScriptTable";
  4. import { ScriptElementTable } from "@/components/artifact/ScriptElementTable";
  5. import type { ScriptElementRow, ScriptParagraphRow } from "@/lib/types";
  6. const paragraph: ScriptParagraphRow = {
  7. id: 1,
  8. rowId: 1,
  9. index: 1,
  10. level: 1,
  11. depth: 0,
  12. name: "机制拆解",
  13. contentRange: ["图1-2", "标题", "正文: 第二段"],
  14. sections: {
  15. theme: { label: "主题", description: "解释份额换订单", descriptionParts: [{ type: "text", text: "解释" }, { type: "element", id: 10, name: "份额换订单", resolved: true, text: "[元素:10]" }], dimensions: [{ type: "主维度", name: "核心竞争力", value: "份额换订单" }] },
  16. form: { label: "形式", description: "案例拆解", descriptionParts: [{ type: "text", text: "案例拆解" }], dimensions: [] },
  17. function: { label: "作用", description: "承接上文", descriptionParts: [{ type: "text", text: "承接上文" }], dimensions: [] },
  18. feeling: { label: "感受", description: "建立可信度", descriptionParts: [{ type: "text", text: "建立可信度" }], dimensions: [] },
  19. },
  20. fullDescription: "通过元素解释机制。",
  21. fullDescriptionParts: [
  22. { type: "text", text: "通过" },
  23. { type: "element", id: 10, name: "份额换订单", resolved: true, text: "[元素:10]" },
  24. { type: "text", text: "解释机制。" },
  25. ],
  26. };
  27. const element: ScriptElementRow = {
  28. id: 10,
  29. rowId: 10,
  30. name: "份额换订单",
  31. primaryDimension: "核心竞争力",
  32. secondaryDimension: "商业模式",
  33. paragraphs: [{ id: 1, index: 1, name: "机制拆解" }],
  34. };
  35. describe("full script table", () => {
  36. it("matches the original complete table fields and element references", () => {
  37. const openElement = vi.fn();
  38. render(<ScriptTable paragraphs={[paragraph]} elements={[element]} onOpenElement={openElement} />);
  39. expect(screen.getAllByText("维度类型")).toHaveLength(4);
  40. expect(screen.getByText("核心竞争力")).toBeInTheDocument();
  41. expect(screen.getByText("图1-2")).toBeInTheDocument();
  42. expect(screen.getByText("正文: 第二段")).toBeInTheDocument();
  43. fireEvent.click(screen.getAllByRole("button", { name: "份额换订单" })[0]);
  44. expect(openElement).toHaveBeenCalledWith(10);
  45. expect(screen.getByText("创作目录大纲(段本身)")).toBeInTheDocument();
  46. });
  47. it("shows element dimensions and linked paragraphs", () => {
  48. render(<ScriptElementTable elements={[element]} selectedId={10} />);
  49. expect(screen.getByRole("row", { name: /份额换订单/ })).toHaveClass("isSelected");
  50. expect(screen.getByText("商业模式")).toBeInTheDocument();
  51. expect(screen.getByText("第 1 段")).toBeInTheDocument();
  52. expect(screen.getByText("机制拆解")).toBeInTheDocument();
  53. });
  54. });