Files
openidea/src/workbench/MainMenu.test.ts
T
lleviathe 8dd29bad41 feat(workbench): toggle the toolbar, status bar and tool window bars from View › Appearance (#2206)
The main toolbar and status bar could not be hidden, Tool Window Bars was a Settings row only, and widgets could be switched only from the status bar's context menu. View > Appearance now has Toolbar, Tool Window Bars, Status Bar and Status Bar Widgets, with check marks in the macOS and in-app menus, plus Settings toggles. Both new settings default to shown. With the toolbar hidden, the window keeps a compact header with the title, which Distraction Free now shares.

Controls stay reachable with a bar hidden: the Git branches popup and background tasks have their own hosts, and background tasks has an action.

Co-authored-by: lleviathe <95321986+lleviathe@users.noreply.github.com>
2026-11-09 07:20:54 +08:00

109 lines
3.6 KiB
TypeScript

import { describe, expect, it } from "vitest";
import { registerAction } from "@/platform/actions";
import { resolveMenuItems } from "@/ui/Menu";
import { menuItems, onLoneAlt } from "./MainMenu";
describe("lone Alt opens the main menu", () => {
const key = (type: string, k: string, init: KeyboardEventInit = {}) =>
window.dispatchEvent(new KeyboardEvent(type, { key: k, bubbles: true, cancelable: true, ...init }));
it.each<[string, () => void, number]>([
["Alt alone", () => (key("keydown", "Alt", { altKey: true }), key("keyup", "Alt")), 1],
[
"Alt+1",
() => (
key("keydown", "Alt", { altKey: true }),
key("keydown", "1", { altKey: true }),
key("keyup", "1"),
key("keyup", "Alt")
),
0,
],
[
"Ctrl+Alt",
() => (
key("keydown", "Control", { ctrlKey: true }),
key("keydown", "Alt", { ctrlKey: true, altKey: true }),
key("keyup", "Alt")
),
0,
],
[
"Alt+click",
() => (
key("keydown", "Alt", { altKey: true }),
window.dispatchEvent(new Event("pointerdown")),
key("keyup", "Alt")
),
0,
],
[
"held Alt (repeat)",
() => (
key("keydown", "Alt", { altKey: true }),
key("keydown", "Alt", { altKey: true, repeat: true }),
key("keyup", "Alt")
),
0,
],
])("%s", (_, press, expected) => {
let opened = 0;
const off = onLoneAlt(window, () => void opened++);
press();
off();
expect(opened).toBe(expected);
});
});
describe("main menu model", () => {
it("maps menu nodes to menu items, localising spec labels only", () => {
const items = menuItems([
{ kind: "action", id: "file.save", label: "Save All", hint: null, arg: null, checked: null },
{ kind: "separator" },
{
kind: "submenu",
id: "openRecent",
label: "Open Recent",
children: [
{
kind: "action",
id: "file.openRecentProject",
label: "openidea — ~/openidea",
hint: null,
arg: "/p/openidea",
checked: null,
},
{ kind: "placeholder", id: "recent.none", label: "No Recent Projects" },
],
},
]);
expect(items[0]).toEqual({ kind: "action", action: "file.save", arg: undefined, label: "Save All" });
expect(items[1]).toEqual({ kind: "separator" });
expect(items[2]).toMatchObject({ id: "openRecent", label: "Open Recent" });
const sub = (items[2] as { submenu: unknown[] }).submenu;
expect(sub[0]).toEqual({
kind: "action",
action: "file.openRecentProject",
arg: "/p/openidea",
label: "openidea — ~/openidea",
});
expect(sub[1]).toMatchObject({ label: "No Recent Projects", disabled: true });
});
});
describe("check marks in the main menu", () => {
it("shows a frontend-listed item's own state, one row per argument", () => {
const off = registerAction({ id: "test.mainMenu.widget", title: "Widget", run: () => {} });
const node = (arg: string, checked: boolean) =>
({ kind: "action", id: "test.mainMenu.widget", label: arg, hint: null, arg, checked }) as const;
const items = menuItems([node("memory", true), node("caret", false)]);
expect(items[0]).toMatchObject({ action: "test.mainMenu.widget", arg: "memory", checked: true });
const rows = resolveMenuItems(items);
expect(rows.map((r) => [r.label, r.checked])).toEqual([
["memory", true],
["caret", false],
]);
expect(new Set(rows.map((r) => r.key)).size).toBe(2);
off();
});
});