desktopWindowFrame.test.ts 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. import { createElement } from "react";
  2. import { renderToStaticMarkup } from "react-dom/server";
  3. import { describe, expect, it } from "vitest";
  4. import { DesktopWindowFrame } from "@/DesktopWindowFrame.js";
  5. describe("DesktopWindowFrame", () => {
  6. it("uses an opaque root surface on Linux desktop", () => {
  7. const html = renderToStaticMarkup(
  8. createElement(
  9. DesktopWindowFrame,
  10. {
  11. title: "ZCode",
  12. isDesktop: true,
  13. isMacDesktop: false,
  14. isWindowsDesktop: false,
  15. },
  16. createElement("div", null, "content"),
  17. ),
  18. );
  19. // Bugfix: Linux 没有系统级磨砂材质兜底,根框架不能使用带透明混色的 alt 背景。
  20. expect(html).toContain("bg-background-win-alt");
  21. expect(html).not.toContain("bg-background-alt");
  22. expect(html).toContain('data-desktop-window-frame="true"');
  23. expect(html).toContain("rounded-[16px]");
  24. expect(html).toContain("[clip-path:inset(0_round_16px)]");
  25. expect(html).toContain("platform-linux-window-maximized:[clip-path:inset(0)]");
  26. });
  27. it("uses an opaque root surface in the browser shell", () => {
  28. const html = renderToStaticMarkup(
  29. createElement(
  30. DesktopWindowFrame,
  31. {
  32. title: "ZCode",
  33. },
  34. createElement("div", null, "content"),
  35. ),
  36. );
  37. // Bugfix: Web 端没有 Electron/macOS 的 vibrancy 底层,半透明 alt 背景会直接叠到浏览器底色上。
  38. expect(html).toContain("bg-background-win-alt");
  39. expect(html).not.toContain("bg-background-alt");
  40. });
  41. });
  42. it.each([
  43. { platform: "macOS", isMacDesktop: true, isWindowsDesktop: false, opaque: false },
  44. { platform: "Windows", isMacDesktop: false, isWindowsDesktop: true, opaque: true },
  45. ])(
  46. "preserves the $platform root background contract",
  47. ({ isMacDesktop, isWindowsDesktop, opaque }) => {
  48. const html = renderToStaticMarkup(
  49. createElement(DesktopWindowFrame, {
  50. title: "ZCode",
  51. isDesktop: true,
  52. isMacDesktop,
  53. isWindowsDesktop,
  54. children: createElement("div", null, "content"),
  55. }),
  56. );
  57. expect(html.includes("bg-background-alt")).toBe(!opaque);
  58. expect(html.includes("bg-background-win-alt")).toBe(opaque);
  59. },
  60. );