chatPromptEditorActionOrder.test.ts 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. import { createElement, type ReactNode } from "react";
  2. import { renderToStaticMarkup } from "react-dom/server";
  3. import { describe, expect, it, vi } from "vitest";
  4. import { ChatPromptEditor } from "@/prompt-editor/ChatPromptEditor.js";
  5. vi.mock("@/ControlHintTooltip.js", () => ({
  6. ControlHintTooltip: ({ children }: { children: ReactNode }) => children,
  7. }));
  8. vi.mock("@/LexicalChatInput.js", async () => {
  9. const React = await import("react");
  10. return {
  11. LexicalChatInput: () => React.createElement("div", { "data-testid": "lexical-input" }),
  12. };
  13. });
  14. vi.mock("@/i18n/IntlProvider.js", () => ({
  15. useZCodeIntl: () => ({
  16. intl: {
  17. formatMessage: ({ id }: { id: string }) => id,
  18. },
  19. }),
  20. }));
  21. vi.mock("@/prompt-editor/ChatPromptActionMenu.js", async () => {
  22. const React = await import("react");
  23. return {
  24. ChatPromptActionMenu: ({
  25. excludedSlashCommandNames,
  26. }: {
  27. excludedSlashCommandNames?: readonly string[];
  28. }) =>
  29. React.createElement("div", {
  30. "data-testid": "composer-action-menu",
  31. "data-excluded": excludedSlashCommandNames?.join(","),
  32. }),
  33. };
  34. });
  35. vi.mock("@/prompt-editor/usePromptEditorDragState.js", () => ({
  36. usePromptEditorDragState: () => ({
  37. externalFileDragging: false,
  38. internalDragging: false,
  39. setExternalFileDragging: vi.fn(),
  40. setInternalDragging: vi.fn(),
  41. setWorkspaceFileDragging: vi.fn(),
  42. workspaceFileDragging: false,
  43. }),
  44. }));
  45. describe("ChatPromptEditor action menu", () => {
  46. it("passes side chat command exclusions to the action menu", () => {
  47. const html = renderToStaticMarkup(
  48. createElement(ChatPromptEditor, {
  49. workspacePath: "/tmp/workspace",
  50. taskId: null,
  51. submitLabel: "Send",
  52. showMentionButton: true,
  53. excludedSlashCommandNames: ["goal"],
  54. onSubmit: vi.fn(),
  55. }),
  56. );
  57. expect(html).toContain('data-excluded="goal"');
  58. });
  59. // Side Pane 完整视图浮窗:[+] 输入区 [控件][发送] 排成一行(docs/ui/side-pane-full-view.md)。
  60. it("moves the action menu before the editor only in the inline layout", () => {
  61. const render = (layout: "stacked" | "inline") =>
  62. renderToStaticMarkup(
  63. createElement(ChatPromptEditor, {
  64. workspacePath: "/tmp/workspace",
  65. taskId: null,
  66. submitLabel: "Send",
  67. showMentionButton: true,
  68. layout,
  69. onSubmit: vi.fn(),
  70. }),
  71. );
  72. const order = (html: string) =>
  73. ["composer-action-menu", "lexical-input", "data-composer-leading-content"].map((marker) =>
  74. html.indexOf(marker),
  75. );
  76. const inline = render("inline");
  77. expect(inline).toContain('data-composer-layout="inline"');
  78. const [inlineMenu, inlineEditor, inlineToolbar] = order(inline);
  79. expect(inlineMenu).toBeLessThan(inlineEditor);
  80. expect(inlineEditor).toBeLessThan(inlineToolbar);
  81. const stacked = render("stacked");
  82. expect(stacked).toContain('data-composer-layout="stacked"');
  83. const [stackedMenu, stackedEditor, stackedToolbar] = order(stacked);
  84. expect(stackedEditor).toBeLessThan(stackedToolbar);
  85. expect(stackedToolbar).toBeLessThan(stackedMenu);
  86. });
  87. });