taskRowActionButton.test.ts 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. import { createElement, type ReactNode } from "react";
  2. import { renderToStaticMarkup } from "react-dom/server";
  3. import { describe, expect, it, vi } from "vitest";
  4. vi.mock("@/ControlHintTooltip.js", () => ({
  5. ControlHintTooltip: ({
  6. children,
  7. title,
  8. side,
  9. sideOffset,
  10. }: {
  11. children: ReactNode;
  12. title: ReactNode;
  13. side?: string;
  14. sideOffset?: number;
  15. }) =>
  16. createElement(
  17. "span",
  18. {
  19. "data-control-hint-tooltip": "true",
  20. "data-side": side,
  21. "data-side-offset": sideOffset,
  22. "data-title": title,
  23. },
  24. children,
  25. ),
  26. }));
  27. import { TaskRowActionButton } from "@/workspace-grouped-tasks/task-row-action-button.js";
  28. describe("TaskRowActionButton", () => {
  29. it("renders the shared portal tooltip above the button", () => {
  30. const html = renderToStaticMarkup(
  31. createElement(
  32. TaskRowActionButton,
  33. {
  34. label: "Move to top",
  35. onClick: () => {},
  36. showTooltip: true,
  37. },
  38. "↑",
  39. ),
  40. );
  41. expect(html).toContain('data-control-hint-tooltip="true"');
  42. expect(html).toContain('data-side="top"');
  43. expect(html).toContain('data-side-offset="2"');
  44. expect(html).toContain('data-title="Move to top"');
  45. });
  46. it("uses the disabled reason as the tooltip title", () => {
  47. const html = renderToStaticMarkup(
  48. createElement(
  49. TaskRowActionButton,
  50. {
  51. label: "Move to top",
  52. disabledReason: "Already at the top",
  53. onClick: () => {},
  54. showTooltip: true,
  55. },
  56. "↑",
  57. ),
  58. );
  59. expect(html).toContain('data-title="Already at the top"');
  60. expect(html).not.toContain('data-title="Move to top"');
  61. });
  62. it("keeps draft actions tooltip-free by default", () => {
  63. const html = renderToStaticMarkup(
  64. createElement(TaskRowActionButton, { label: "Close", onClick: () => {} }, "×"),
  65. );
  66. expect(html).not.toContain("data-control-hint-tooltip");
  67. });
  68. });