Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

headerMenu.test.ts

66 lines2.1 KB

1import { describe, expect, it } from "vite-plus/test";
2import { androidHeaderMenuActions, findHeaderMenuAction } from "./headerMenu.android";
3import type { ScreenHeaderMenuItem } from "./ScreenHeader.types";
4​
5const items: ReadonlyArray<ScreenHeaderMenuItem> = [
6 {
7 id: "sessions",
8 title: "Sessions",
9 items: [
10 {
11 id: "terminal-session:main",
12 title: "Main shell",
13 subtitle: "Running · workspace",
14 selected: true,
15 onPress: () => {},
16 },
17 { id: "closed", title: "Closed shell", disabled: true, onPress: () => {} },
18 ],
19 },
20];
21​
22describe("header menus", () => {
23 it("keeps named sections as Android submenus", () => {
24 const actions = androidHeaderMenuActions([
25 {
26 id: "text-size",
27 title: "Text size",
28 inline: true,
29 items: [{ id: "font-increase", title: "A+", onPress: () => {} }],
30 },
31 ]);
32 expect(actions[0]?.title).toBe("Text size");
33 expect(actions[0]?.subactions?.[0]?.id).toBe("font-increase");
34 });
35​
36 it("flattens inline groups while keeping their action IDs", () => {
37 const actions = androidHeaderMenuActions([
38 { id: "modes", inline: true, items: [{ id: "code", title: "Code", onPress: () => {} }] },
39 ]);
40 expect(actions.map(({ id }) => id)).toEqual(["code"]);
41 });
42​
43 it("keeps stable action IDs, selection, and disabled state inside submenus", () => {
44 const menu = androidHeaderMenuActions(items);
45 expect(menu[0]?.id).toBe("sessions");
46 expect(menu[0]?.subactions?.[0]).toMatchObject({
47 id: "terminal-session:main",
48 title: "Main shell",
49 subtitle: "Running · workspace",
50 state: "on",
51 });
52 expect(menu[0]?.subactions?.[1]).toMatchObject({
53 id: "closed",
54 attributes: { disabled: true },
55 });
56 });
57​
58 it("resolves nested action IDs without dispatching group or missing IDs", () => {
59 expect(findHeaderMenuAction(items, "terminal-session:main")).toMatchObject({
60 title: "Main shell",
61 selected: true,
62 });
63 expect(findHeaderMenuAction(items, "sessions")).toBeUndefined();
64 expect(findHeaderMenuAction(items, "removed-session")).toBeUndefined();
65 });
66});