Files
openidea/src/workbench/WindowControls.test.tsx
T
Bert Verhelstandbertyhell 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 <1710840+bertyhell@users.noreply.github.com>
2026-11-17 03:45:50 +08:00

72 lines
2.8 KiB
TypeScript

import { afterEach, describe, expect, it, vi } from "vitest";
vi.mock("@tauri-apps/api/window", () => ({
getCurrentWindow: () => ({ isMaximized: async () => false, onResized: async () => () => {} }),
}));
import { render, screen } from "@testing-library/react";
import type { WindowButtonLayout } from "@/platform/ipc";
import { usePlatform } from "@/platform/platformInfo";
import { WindowControls } from "./WindowControls";
import { captionButtons } from "./windowButtons";
const initialPlatform = usePlatform.getState();
afterEach(() => usePlatform.setState(initialPlatform));
const layouts = {
default: { left: [], right: ["minimize", "maximize", "close"] },
kdeLeft: { left: ["close", "maximize", "minimize"], right: [] },
closeOnly: { left: [], right: ["close"] },
split: { left: ["close"], right: ["minimize", "maximize"] },
noClose: { left: ["minimize"], right: [] },
empty: { left: [], right: [] },
} satisfies Record<string, WindowButtonLayout>;
describe("caption buttons per side", () => {
it.each([
["default", [], ["minimize", "maximize", "close"]],
["kdeLeft", ["close", "maximize", "minimize"], []],
["closeOnly", [], ["close"]],
["split", ["close"], ["minimize", "maximize"]],
] as const)("%s window", (name, left, right) => {
expect(captionButtons(layouts[name], "left")).toEqual(left);
expect(captionButtons(layouts[name], "right")).toEqual(right);
});
it.each([
["default", "right"],
["kdeLeft", "left"],
["split", "left"],
// Without close in the layout a dialog still needs one: on the side its buttons go.
["noClose", "left"],
["empty", "right"],
] as const)("%s dialog keeps close on the %s", (name, side) => {
const layout = layouts[name];
expect(captionButtons(layout, side, true)).toEqual(["close"]);
expect(captionButtons(layout, side === "left" ? "right" : "left", true)).toEqual([]);
});
});
describe("WindowControls", () => {
const labels = () => screen.queryAllByRole("button").map((b) => b.getAttribute("aria-label"));
it("renders the left buttons in the desktop's order", () => {
usePlatform.setState({ windowButtons: layouts.kdeLeft });
const { container } = render(<WindowControls side="left" />);
expect(labels()).toEqual(["Close", "Maximize", "Minimize"]);
container.remove();
render(<WindowControls side="right" />);
expect(screen.queryAllByRole("button")).toHaveLength(0);
});
it("keeps today's right-hand buttons by default", () => {
render(<WindowControls side="right" />);
expect(labels()).toEqual(["Minimize", "Maximize", "Close"]);
});
it("leaves out buttons the layout omits", () => {
usePlatform.setState({ windowButtons: layouts.closeOnly });
render(<WindowControls side="right" />);
expect(labels()).toEqual(["Close"]);
});
});