floatingOverlayLayering.test.ts 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import { readFile } from "node:fs/promises";
  2. import { describe, expect, it } from "vitest";
  3. const componentSources = await Promise.all(
  4. ["popover.tsx", "select.tsx", "dropdown-menu.tsx", "context-menu.tsx"].map(
  5. async (fileName) => ({
  6. fileName,
  7. source: await readFile(
  8. new URL(`../src/components/ui/${fileName}`, import.meta.url),
  9. "utf8",
  10. ),
  11. }),
  12. ),
  13. );
  14. const tooltipSource = await readFile(
  15. new URL("../src/components/ui/tooltip.tsx", import.meta.url),
  16. "utf8",
  17. );
  18. describe("floating overlay layering", () => {
  19. it("可操作浮层统一位于辅助 tooltip 之上", () => {
  20. expect(tooltipSource).toContain('"z-50 inline-flex');
  21. for (const { fileName, source } of componentSources) {
  22. expect(source, fileName).toContain("z-[60]");
  23. expect(source, fileName).not.toContain('"z-50');
  24. }
  25. });
  26. it("Dropdown 获得焦点时仍持续显示默认阴影", () => {
  27. const dropdownSource =
  28. componentSources.find(({ fileName }) => fileName === "dropdown-menu.tsx")
  29. ?.source ?? "";
  30. expect(dropdownSource).toContain(
  31. "!shadow-md focus:!shadow-md focus-visible:!shadow-md",
  32. );
  33. expect(dropdownSource).not.toContain(
  34. "text-foreground shadow-md duration-100",
  35. );
  36. });
  37. });