taskRowActionButton.test.ts 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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. it("forwards an optional semantic color class to the button", () => {
  69. const html = renderToStaticMarkup(
  70. createElement(
  71. TaskRowActionButton,
  72. {
  73. className: "text-foreground-subtle hover:text-foreground",
  74. label: "Show file tree",
  75. onClick: () => {},
  76. },
  77. "tree",
  78. ),
  79. );
  80. expect(html).toContain("text-foreground-subtle");
  81. expect(html).toContain("hover:text-foreground");
  82. });
  83. });