v4ConversationHeader.test.ts 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. import { createElement } from "react";
  2. import { renderToStaticMarkup } from "react-dom/server";
  3. import { describe, expect, it, vi } from "vitest";
  4. import {
  5. TID_V4_DELETE_SESSION,
  6. TID_V4_PANE_WORKSPACE_BADGE,
  7. TID_V4_RENAME_INPUT,
  8. TID_V4_RENAME_SUBMIT,
  9. TID_V4_SPLIT_CLOSE,
  10. TID_V4_SPLIT_DOWN,
  11. TID_V4_SPLIT_OPEN,
  12. } from "@zcode/shared";
  13. import { ZCodeIntlProvider } from "@/i18n/IntlProvider.js";
  14. import { ConversationHeader } from "@/v4/ConversationHeader.js";
  15. function renderHeader(overrides: Record<string, unknown> = {}): string {
  16. return renderToStaticMarkup(
  17. createElement(
  18. ZCodeIntlProvider,
  19. { initialLocale: "zh-CN" },
  20. createElement(ConversationHeader, {
  21. title: "这是个啥项目",
  22. onSplitRight: vi.fn(),
  23. onSplitDown: vi.fn(),
  24. onClosePane: vi.fn(),
  25. workspaceBadge: {
  26. label: "workspace",
  27. workspacePath: "/tmp/workspace",
  28. remote: false,
  29. },
  30. ...overrides,
  31. }),
  32. ),
  33. );
  34. }
  35. describe("ConversationHeader split chrome", () => {
  36. it("temporarily hides split controls while keeping the other floating pane actions", () => {
  37. const html = renderHeader();
  38. expect(html).toContain('data-v4-pane-actions="floating"');
  39. expect(html).not.toContain(`data-testid="${TID_V4_SPLIT_OPEN}"`);
  40. expect(html).not.toContain(`data-testid="${TID_V4_SPLIT_DOWN}"`);
  41. expect(html).toContain(`data-testid="${TID_V4_SPLIT_CLOSE}"`);
  42. expect(html).toContain(`data-testid="${TID_V4_PANE_WORKSPACE_BADGE}"`);
  43. expect(html).toContain("absolute");
  44. expect(html).toContain("left-2");
  45. expect(html).toContain("top-2");
  46. expect(html).not.toContain("justify-between border-b");
  47. });
  48. it("does not render an empty floating action group when only split callbacks are provided", () => {
  49. const html = renderHeader({ workspaceBadge: undefined, onClosePane: undefined });
  50. expect(html).not.toContain('data-v4-pane-actions="floating"');
  51. expect(html).not.toContain(`data-testid="${TID_V4_SPLIT_OPEN}"`);
  52. expect(html).not.toContain(`data-testid="${TID_V4_SPLIT_DOWN}"`);
  53. });
  54. it("keeps task rename and delete out of conversation pane chrome", () => {
  55. const html = renderHeader({ onDelete: vi.fn(), onRename: vi.fn() });
  56. expect(html).not.toContain(`data-testid="${TID_V4_RENAME_INPUT}"`);
  57. expect(html).not.toContain(`data-testid="${TID_V4_RENAME_SUBMIT}"`);
  58. expect(html).not.toContain(`data-testid="${TID_V4_DELETE_SESSION}"`);
  59. });
  60. });