shell.test.tsx 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. import { cleanup, render, screen } from "@testing-library/react";
  2. import { afterEach, expect, test, vi } from "vitest";
  3. import Page from "@/app/page";
  4. afterEach(() => {
  5. cleanup();
  6. vi.unstubAllGlobals();
  7. });
  8. test("展示来自 Host 投影的创作目标", async () => {
  9. vi.stubGlobal(
  10. "fetch",
  11. vi.fn(async (input: RequestInfo | URL) => {
  12. const url = String(input);
  13. const payload = url.endsWith("/api/runs")
  14. ? [
  15. {
  16. script_build_id: 42,
  17. status: "running",
  18. summary: "正在生成脚本",
  19. started_at: null,
  20. completed_at: null,
  21. },
  22. ]
  23. : {
  24. schema_version: "script-build-journey/v1",
  25. generated_at: "2026-07-21T00:00:00Z",
  26. script_build_id: 42,
  27. root_trace_id: "root-42",
  28. status: "running",
  29. objective: "为选题生成一份可发布的脚本",
  30. input_summary: {
  31. topic: "一次反转如何改变信念",
  32. account_name: "每天心理学",
  33. persona_point_count: 3,
  34. strategy_names: ["先冲突后解法"],
  35. snapshot_id: "11",
  36. digest: "sha256:input",
  37. },
  38. steps: [],
  39. edges: [],
  40. warnings: [],
  41. };
  42. return { ok: true, json: async () => payload } as Response;
  43. }),
  44. );
  45. render(<Page />);
  46. expect(
  47. await screen.findByRole("heading", { name: "为选题生成一份可发布的脚本" }),
  48. ).toBeTruthy();
  49. });