@agent-native/toolkit 0.19.7 → 0.19.8-nightly-20260910195009
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/agent-native.eject.json +8 -1
- package/dist/app-shell/index.d.ts +1 -0
- package/dist/app-shell/index.d.ts.map +1 -1
- package/dist/app-shell/index.js +1 -0
- package/dist/app-shell/index.js.map +1 -1
- package/dist/app-shell/sidebar.d.ts +134 -0
- package/dist/app-shell/sidebar.d.ts.map +1 -0
- package/dist/app-shell/sidebar.js +183 -0
- package/dist/app-shell/sidebar.js.map +1 -0
- package/dist/app-shell/sidebar.spec.d.ts +2 -0
- package/dist/app-shell/sidebar.spec.d.ts.map +1 -0
- package/dist/app-shell/sidebar.spec.js +82 -0
- package/dist/app-shell/sidebar.spec.js.map +1 -0
- package/package.json +1 -1
- package/src/app-shell/index.ts +1 -0
- package/src/app-shell/sidebar.spec.tsx +142 -0
- package/src/app-shell/sidebar.tsx +1000 -0
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
// @vitest-environment happy-dom
|
|
2
|
+
|
|
3
|
+
import { act } from "react";
|
|
4
|
+
import { createRoot, type Root } from "react-dom/client";
|
|
5
|
+
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
6
|
+
|
|
7
|
+
import {
|
|
8
|
+
AppSidebar,
|
|
9
|
+
AppSidebarNavItem,
|
|
10
|
+
AppSidebarNavGroup,
|
|
11
|
+
AppSidebarSection,
|
|
12
|
+
AppSidebarFeedbackButton,
|
|
13
|
+
} from "./sidebar.js";
|
|
14
|
+
|
|
15
|
+
describe("AppSidebar", () => {
|
|
16
|
+
let container: HTMLDivElement;
|
|
17
|
+
let root: Root;
|
|
18
|
+
|
|
19
|
+
beforeEach(() => {
|
|
20
|
+
vi.stubGlobal("IS_REACT_ACT_ENVIRONMENT", true);
|
|
21
|
+
container = document.createElement("div");
|
|
22
|
+
document.body.appendChild(container);
|
|
23
|
+
root = createRoot(container);
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
afterEach(() => {
|
|
27
|
+
act(() => root.unmount());
|
|
28
|
+
container.remove();
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
it("renders expanded sidebar with brand, items, and utilities", () => {
|
|
32
|
+
act(() => {
|
|
33
|
+
root.render(
|
|
34
|
+
<AppSidebar
|
|
35
|
+
brandName="My App"
|
|
36
|
+
brandHref="/home"
|
|
37
|
+
badge={<span data-badge>alpha</span>}
|
|
38
|
+
items={[
|
|
39
|
+
{ label: "Inbox", to: "/inbox", count: 5, active: true },
|
|
40
|
+
{ label: "Tasks", to: "/tasks" },
|
|
41
|
+
]}
|
|
42
|
+
secondaryItems={[{ label: "Archive", to: "/archive" }]}
|
|
43
|
+
feedback={<button type="button">Feedback</button>}
|
|
44
|
+
orgSwitcher={<button type="button">Acme Org</button>}
|
|
45
|
+
/>,
|
|
46
|
+
);
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
const aside = container.querySelector("aside");
|
|
50
|
+
expect(aside).not.toBeNull();
|
|
51
|
+
expect(aside?.getAttribute("data-collapsed")).toBe("false");
|
|
52
|
+
expect(aside?.className).toContain("w-[260px]");
|
|
53
|
+
expect(container.textContent).toContain("My App");
|
|
54
|
+
expect(container.textContent).toContain("alpha");
|
|
55
|
+
expect(container.textContent).toContain("Inbox");
|
|
56
|
+
expect(container.textContent).toContain("5");
|
|
57
|
+
expect(container.textContent).toContain("Tasks");
|
|
58
|
+
expect(container.textContent).toContain("Archive");
|
|
59
|
+
expect(container.textContent).toContain("Feedback");
|
|
60
|
+
expect(container.textContent).toContain("Acme Org");
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it("renders collapsed sidebar with md:w-14 and tooltips", () => {
|
|
64
|
+
act(() => {
|
|
65
|
+
root.render(
|
|
66
|
+
<AppSidebar
|
|
67
|
+
collapsed
|
|
68
|
+
brandName="My App"
|
|
69
|
+
badge={<span data-badge>alpha</span>}
|
|
70
|
+
items={[{ label: "Inbox", to: "/inbox" }]}
|
|
71
|
+
/>,
|
|
72
|
+
);
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
const aside = container.querySelector("aside");
|
|
76
|
+
expect(aside?.getAttribute("data-collapsed")).toBe("true");
|
|
77
|
+
expect(aside?.className).toContain("md:w-14");
|
|
78
|
+
// In collapsed mode, brand name is hidden from screen, badge is present
|
|
79
|
+
expect(container.querySelector("[data-badge]")?.textContent).toBe("alpha");
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
it("toggles collapsed state via collapse button", () => {
|
|
83
|
+
const onCollapsedChange = vi.fn();
|
|
84
|
+
act(() => {
|
|
85
|
+
root.render(
|
|
86
|
+
<AppSidebar
|
|
87
|
+
collapsed={false}
|
|
88
|
+
onCollapsedChange={onCollapsedChange}
|
|
89
|
+
brandName="My App"
|
|
90
|
+
/>,
|
|
91
|
+
);
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
const collapseButton = container.querySelector(
|
|
95
|
+
'button[aria-label="Collapse sidebar"]',
|
|
96
|
+
);
|
|
97
|
+
expect(collapseButton).not.toBeNull();
|
|
98
|
+
|
|
99
|
+
act(() => {
|
|
100
|
+
collapseButton?.dispatchEvent(new MouseEvent("click", { bubbles: true }));
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
expect(onCollapsedChange).toHaveBeenCalledWith(true);
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
it("renders collapsible nav group and expands/collapses children", () => {
|
|
107
|
+
act(() => {
|
|
108
|
+
root.render(
|
|
109
|
+
<AppSidebar brandName="My App">
|
|
110
|
+
<AppSidebarNavGroup label="Projects" defaultOpen={false}>
|
|
111
|
+
<div>Project Alpha</div>
|
|
112
|
+
</AppSidebarNavGroup>
|
|
113
|
+
</AppSidebar>,
|
|
114
|
+
);
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
expect(container.textContent).toContain("Projects");
|
|
118
|
+
const toggleButton = container.querySelector('button[aria-label="Expand"]');
|
|
119
|
+
expect(toggleButton).not.toBeNull();
|
|
120
|
+
|
|
121
|
+
act(() => {
|
|
122
|
+
toggleButton?.dispatchEvent(new MouseEvent("click", { bubbles: true }));
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
expect(container.textContent).toContain("Project Alpha");
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
it("renders sections with uppercase headers and dividers", () => {
|
|
129
|
+
act(() => {
|
|
130
|
+
root.render(
|
|
131
|
+
<AppSidebar brandName="My App">
|
|
132
|
+
<AppSidebarSection title="Favorites">
|
|
133
|
+
<AppSidebarNavItem label="Starred item" />
|
|
134
|
+
</AppSidebarSection>
|
|
135
|
+
</AppSidebar>,
|
|
136
|
+
);
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
expect(container.textContent).toContain("Favorites");
|
|
140
|
+
expect(container.textContent).toContain("Starred item");
|
|
141
|
+
});
|
|
142
|
+
});
|