Open History to see the last commit
1import { describe, expect, it } from "vite-plus/test";
2import {
3 NAVIGATION_TAB_ORDER,
4 navigationCustomizationAvailable,
5 moveNavigationTab,
6 overflowNavigationTabs,
7 enabledNavigationTabs,
8 sharedSlotAbsentee,
9 toggleNavigationTabVisibility,
10 resolveSelectedNavigationTab,
11 resolveNavigationTabOrder,
12 selectedNavigationTab,
13 visibleNavigationTabs,
14} from "./navigation-tab-order";
15
16describe("navigation tab order", () => {
17 it("enables customization only above four registered sections, excluding Settings", () => {
18 expect(navigationCustomizationAvailable()).toBe(false);
19 expect(navigationCustomizationAvailable(3)).toBe(false);
20 expect(navigationCustomizationAvailable(4)).toBe(false);
21 expect(navigationCustomizationAvailable(5)).toBe(true);
22 expect(navigationCustomizationAvailable(6)).toBe(true);
23 });
24
25 it("fills missing sections and drops removed placeholders, duplicates, and Settings", () => {
26 expect(
27 resolveNavigationTabOrder(["usage", "home", "inbox", "settings", "usage", null]),
28 ).toEqual(["usage", "threads", "pullRequests", "issues"]);
29 expect(resolveNavigationTabOrder()).toEqual(NAVIGATION_TAB_ORDER);
30 });
31
32 it("gives the shared slot to the open list, or else the one opened last", () => {
33 expect(sharedSlotAbsentee("issues", "pullRequests")).toBe("pullRequests");
34 expect(sharedSlotAbsentee("pullRequests", "issues")).toBe("issues");
35 expect(sharedSlotAbsentee("threads", "issues")).toBe("pullRequests");
36 expect(sharedSlotAbsentee("usage", undefined)).toBe("issues");
37 });
38
39 it("moves a section without changing the relative order of the others", () => {
40 for (const tab of NAVIGATION_TAB_ORDER) {
41 for (let position = 0; position < NAVIGATION_TAB_ORDER.length; position++) {
42 const order = moveNavigationTab(NAVIGATION_TAB_ORDER, tab, position);
43 expect(order[position]).toBe(tab);
44 expect(order.filter((other) => other !== tab)).toEqual(
45 NAVIGATION_TAB_ORDER.filter((other) => other !== tab),
46 );
47 }
48 }
49 });
50
51 it("shows every real section without overflow and keeps Settings selected during editing", () => {
52 expect(visibleNavigationTabs()).toEqual(NAVIGATION_TAB_ORDER);
53 expect(overflowNavigationTabs()).toEqual([]);
54 expect(selectedNavigationTab(undefined, "threads", true)).toBe("settings");
55 expect(selectedNavigationTab(undefined, "usage", false)).toBe("usage");
56 expect(selectedNavigationTab(undefined, "usage", false, [], 2)).toBe("settings");
57 });
58
59 it("removes hidden sections from navigation and restores their saved positions", () => {
60 const order = moveNavigationTab(undefined, "usage", 0);
61 const hidden = toggleNavigationTabVisibility([], "usage");
62 expect(enabledNavigationTabs(order, hidden)).toEqual(["threads", "pullRequests", "issues"]);
63 expect(toggleNavigationTabVisibility(hidden, "usage")).toEqual([]);
64 expect(visibleNavigationTabs(order, [], 5)).toEqual(order);
65 expect(enabledNavigationTabs(undefined, ["home", "inbox", "settings"])).toEqual(
66 NAVIGATION_TAB_ORDER,
67 );
68 });
69
70 it("falls back when the selected section is hidden, including when all are hidden", () => {
71 expect(resolveSelectedNavigationTab(undefined, ["threads"], "threads")).toBe("pullRequests");
72 expect(resolveSelectedNavigationTab(undefined, ["threads"], "usage")).toBe("usage");
73 expect(
74 resolveSelectedNavigationTab(undefined, NAVIGATION_TAB_ORDER, "threads"),
75 ).toBeUndefined();
76 });
77});