chatPromptEditorActionOrder.test.ts 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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 order", () => {
  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. it("renders the + action menu before the permission mode selector", () => {
  60. const html = renderToStaticMarkup(
  61. createElement(ChatPromptEditor, {
  62. workspacePath: "/tmp/workspace",
  63. taskId: "session-1",
  64. submitLabel: "Send",
  65. showMentionButton: true,
  66. leadingActions: createElement("span", {
  67. "data-testid": "permission-mode-selector",
  68. }),
  69. onSubmit: vi.fn(),
  70. }),
  71. );
  72. const actionMenuIndex = html.indexOf('data-testid="composer-action-menu"');
  73. const permissionModeIndex = html.indexOf('data-testid="permission-mode-selector"');
  74. expect(actionMenuIndex).toBeGreaterThanOrEqual(0);
  75. expect(permissionModeIndex).toBeGreaterThanOrEqual(0);
  76. expect(actionMenuIndex).toBeLessThan(permissionModeIndex);
  77. });
  78. });