automationTemplateRemoteIcons.test.ts 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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. expect(view.container.querySelector("img")).toBeNull();
  25. expect(view.container.querySelector("svg.lucide-target")).toBeNull();
  26. });
  27. it("renders an idle img value by name and falls back for an unknown name", async () => {
  28. const view = render(
  29. createElement(OffPeakTemplateIcon, {
  30. iconName: "file-text",
  31. name: "ciFlakyReport",
  32. }),
  33. );
  34. await waitFor(() => {
  35. expect(
  36. view.container.querySelector('[data-client-scene-lucide-icon="file-text"]'),
  37. ).not.toBeNull();
  38. });
  39. expect(view.container.querySelector("img")).toBeNull();
  40. view.rerender(
  41. createElement(OffPeakTemplateIcon, {
  42. iconName: "https://cdn.example.com/off-peak-template.svg",
  43. name: "ciFlakyReport",
  44. }),
  45. );
  46. expect(view.container.querySelector("[data-client-scene-lucide-icon]")).toBeNull();
  47. expect(view.container.querySelector("svg.lucide-activity")).not.toBeNull();
  48. });
  49. });