v4ConversationDraftEmptyStateLogo.test.ts 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. // @vitest-environment jsdom
  2. import { createElement } from "react";
  3. import { cleanup, render } from "@testing-library/react";
  4. import { afterEach, describe, expect, it } from "vitest";
  5. import darkEmptyStateLogoUrl from "@/assets/Z.svg";
  6. import { ZCodeIntlProvider } from "@/i18n/IntlProvider.js";
  7. import { ConversationDraftEmptyState } from "@/v4/ConversationDraftEmptyState.js";
  8. afterEach(() => {
  9. cleanup();
  10. });
  11. describe("ConversationDraftEmptyState logo", () => {
  12. it("uses the supplied Z.svg asset only in dark mode", () => {
  13. const { container } = render(
  14. createElement(
  15. ZCodeIntlProvider,
  16. { initialLocale: "zh-CN" },
  17. createElement(ConversationDraftEmptyState),
  18. ),
  19. );
  20. const lightLogo = container.querySelector("svg");
  21. const darkLogo = container.querySelector('[data-v4-draft-logo="dark"]');
  22. const logoContainer = darkLogo?.parentElement;
  23. const lightLogoClassName = lightLogo?.getAttribute("class") ?? "";
  24. const darkLogoClassName = darkLogo?.getAttribute("class") ?? "";
  25. const logoContainerClassName = logoContainer?.getAttribute("class") ?? "";
  26. expect(lightLogo).not.toBeNull();
  27. expect(lightLogoClassName).toContain("dark:hidden");
  28. expect(lightLogoClassName).toContain("opacity-70");
  29. expect(lightLogoClassName).toContain("mask-image:linear-gradient");
  30. expect(darkLogo).not.toBeNull();
  31. expect(darkLogo?.getAttribute("src")).toBe(darkEmptyStateLogoUrl);
  32. expect(darkLogoClassName).toContain("hidden");
  33. expect(darkLogoClassName).toContain("dark:block");
  34. expect(darkLogoClassName).not.toContain("opacity-70");
  35. expect(darkLogoClassName).not.toContain("mask-image:linear-gradient");
  36. expect(logoContainerClassName).not.toContain("opacity-70");
  37. expect(logoContainerClassName).not.toContain("mask-image:linear-gradient");
  38. });
  39. });