automationTemplateRemoteIcons.test.ts 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. // @vitest-environment jsdom
  2. import { createElement } from "react";
  3. import { render, waitFor } from "@testing-library/react";
  4. import { describe, expect, it } from "vitest";
  5. import { AutomationScheduledTemplateIcon } from "@/settings/AutomationScheduledTemplateIcon.js";
  6. import { OffPeakTemplateIcon } from "@/settings/OffPeakTemplateIcon.js";
  7. describe("automation template Client Scenes icons", () => {
  8. it("renders a scheduled img value as a Lucide icon name and inherits color", async () => {
  9. const view = render(
  10. createElement(
  11. "span",
  12. { className: "text-foreground" },
  13. createElement(AutomationScheduledTemplateIcon, {
  14. iconName: "calendar-clock",
  15. name: "target",
  16. }),
  17. ),
  18. );
  19. await waitFor(() => {
  20. expect(
  21. view.container.querySelector('[data-client-scene-lucide-icon="calendar-clock"]'),
  22. ).not.toBeNull();
  23. });
  24. const icon = view.container.querySelector("svg");
  25. expect(icon?.getAttribute("stroke")).toBe("currentColor");
  26. expect(icon?.className.baseVal).not.toContain("text-foreground");
  27. expect(icon?.parentElement?.classList.contains("text-foreground")).toBe(true);
  28. expect(view.container.querySelector("img")).toBeNull();
  29. expect(view.container.querySelector("svg.lucide-target")).toBeNull();
  30. });
  31. it("renders an idle img value by name and falls back for an unknown name", async () => {
  32. const view = render(
  33. createElement(OffPeakTemplateIcon, {
  34. iconName: "file-text",
  35. name: "ciFlakyReport",
  36. }),
  37. );
  38. await waitFor(() => {
  39. expect(
  40. view.container.querySelector('[data-client-scene-lucide-icon="file-text"]'),
  41. ).not.toBeNull();
  42. });
  43. expect(view.container.querySelector("img")).toBeNull();
  44. view.rerender(
  45. createElement(OffPeakTemplateIcon, {
  46. iconName: "https://cdn.example.com/off-peak-template.svg",
  47. name: "ciFlakyReport",
  48. }),
  49. );
  50. expect(view.container.querySelector("[data-client-scene-lucide-icon]")).toBeNull();
  51. expect(view.container.querySelector("svg.lucide-activity")).not.toBeNull();
  52. });
  53. });