Файли
openidea/src/platform/platformInfo.test.ts
T
Bert Verhelstтаbertyhell 77e6679701 feat(ui): the frameless title bar follows the desktop's window button layout (#3817)
On Linux the frameless title bar reads the desktop's button layout (GTK decoration layout / GNOME button-layout) and places close, minimize and maximize on the left or right in that order; auxiliary windows such as Settings follow it. Other platforms and the default layout are unchanged. Verified on Ubuntu GNOME (Wayland) with left and right layouts.

Closes #3794

Co-authored-by: bertyhell <[email protected]>
2026-11-17 03:45:50 +08:00

49 рядки
1.8 KiB
TypeScript

import { afterEach, expect, it, vi } from "vitest";
import { appDataDir, loadPlatformInfo, usePlatform } from "./platformInfo";
const appInfo = vi.hoisted(() => vi.fn());
vi.mock("@/platform/ipc", () => ({ isTauri: () => true, commands: { appInfo } }));
const initialPlatform = usePlatform.getState();
afterEach(() => usePlatform.setState(initialPlatform));
it.each([
["windows", 19045],
["windows", 22631],
["macos", null],
["linux", null],
] as const)("loads %s OS build %s separately from the app version", async (platform, windowsBuildNumber) => {
appInfo.mockResolvedValue({ platform, windowsBuildNumber, version: "0.1.39", wayland: false });
await loadPlatformInfo();
expect(usePlatform.getState()).toMatchObject({ os: platform, windowsBuildNumber, version: "0.1.39" });
});
it("keeps platform defaults when the query fails", async () => {
appInfo.mockRejectedValue(new Error("unavailable"));
await loadPlatformInfo();
expect(usePlatform.getState()).toEqual(initialPlatform);
});
it("takes the user data directory from the backend, which may have moved it", async () => {
appInfo.mockResolvedValue({ platform: "windows", dataDir: "E:/OpenIDEA/ai.l0ng.openidea/" });
expect(await appDataDir()).toBe("E:/OpenIDEA/ai.l0ng.openidea");
});
it.each([
[
{ left: ["close", "maximize", "minimize"], right: [] },
{ left: ["close", "maximize", "minimize"], right: [] },
],
[undefined, { left: [], right: ["minimize", "maximize", "close"] }],
])("takes the caption button layout %j from the backend", async (windowButtons, expected) => {
appInfo.mockResolvedValue({
platform: "linux",
windowsBuildNumber: null,
version: "0.1.46",
wayland: true,
windowButtons,
});
await loadPlatformInfo();
expect(usePlatform.getState().windowButtons).toEqual(expected);
});