@sentropic/design-system-svelte 0.34.71 → 0.34.73

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.
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=AppShell.panelResize.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AppShell.panelResize.test.d.ts","sourceRoot":"","sources":["../src/lib/AppShell.panelResize.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,338 @@
1
+ import { fireEvent, render } from "@testing-library/svelte";
2
+ import { createRawSnippet } from "svelte";
3
+ import { describe, expect, it, vi } from "vitest";
4
+ import AppShell from "./AppShell.svelte";
5
+ const snippet = (html) => createRawSnippet(() => ({ render: () => `<div>${html}</div>` }));
6
+ const panelProps = {
7
+ primaryRail: snippet("rail-content"),
8
+ navigationPanel: snippet("nav-content"),
9
+ main: snippet("main-content"),
10
+ contextPanel: snippet("context-content"),
11
+ utilityPanel: snippet("utility-content"),
12
+ };
13
+ describe("AppShell — panelResize default (false)", () => {
14
+ it("renders no resize handles", () => {
15
+ const { container } = render(AppShell, { props: { variant: "workspace", ...panelProps } });
16
+ expect(container.querySelectorAll(".st-appShell__resizeHandle").length).toBe(0);
17
+ });
18
+ it("does not set an inline style on the shell root (byte-identical to today)", () => {
19
+ const { container } = render(AppShell, {
20
+ props: { variant: "workspace", ...panelProps, defaultPanelWidths: { navigationPanel: 400 } },
21
+ });
22
+ const root = container.querySelector(".st-appShell");
23
+ // No `style` attribute at all — panelResize=false never touches width vars,
24
+ // even if defaultPanelWidths is (pointlessly) supplied.
25
+ expect(root.getAttribute("style")).toBeFalsy();
26
+ });
27
+ });
28
+ describe("AppShell — panelResize=true", () => {
29
+ it("renders exactly one resize handle per RESIZABLE present panel (navigation/context/utility)", () => {
30
+ const { container } = render(AppShell, { props: { variant: "workspace", panelResize: true, ...panelProps } });
31
+ const handles = container.querySelectorAll(".st-appShell__resizeHandle");
32
+ expect(handles.length).toBe(3);
33
+ handles.forEach((handle) => {
34
+ expect(handle.getAttribute("role")).toBe("separator");
35
+ expect(handle.getAttribute("aria-orientation")).toBe("vertical");
36
+ expect(handle.getAttribute("tabindex")).toBe("0");
37
+ });
38
+ });
39
+ it("renders NO handle on primaryRail, even with panelResize=true and the primaryRail slot present", () => {
40
+ const { container } = render(AppShell, { props: { variant: "workspace", panelResize: true, ...panelProps } });
41
+ // `primaryRail` is a fixed-width icon rail (à la VS Code's activity bar),
42
+ // not a resizable panel — it is not part of `AppShellPanelKey` and must
43
+ // never receive a handle, regardless of panelResize/panelWidths.
44
+ expect(container.querySelector(".st-appShell__primaryRail .st-appShell__resizeHandle")).toBeNull();
45
+ expect(container.querySelector(".st-appShell__primaryRail")).not.toBeNull(); // the rail itself still renders
46
+ });
47
+ it("labels each handle 'Resize {panel label}', falling back to the existing aria-label props", () => {
48
+ const { container } = render(AppShell, {
49
+ props: { variant: "workspace", panelResize: true, ...panelProps },
50
+ });
51
+ expect(container.querySelector('.st-appShell__navigationPanel .st-appShell__resizeHandle')?.getAttribute("aria-label")).toBe("Resize Workspace navigation");
52
+ expect(container.querySelector('.st-appShell__contextPanel .st-appShell__resizeHandle')?.getAttribute("aria-label")).toBe("Resize Context panel");
53
+ expect(container.querySelector('.st-appShell__utilityPanel .st-appShell__resizeHandle')?.getAttribute("aria-label")).toBe("Resize Utility panel");
54
+ });
55
+ it("defaults aria-valuemin/aria-valuemax to 180/640 and reports a clamped aria-valuenow", () => {
56
+ const { container } = render(AppShell, { props: { variant: "workspace", panelResize: true, ...panelProps } });
57
+ const handle = container.querySelector('.st-appShell__navigationPanel .st-appShell__resizeHandle');
58
+ expect(handle.getAttribute("aria-valuemin")).toBe("180");
59
+ expect(handle.getAttribute("aria-valuemax")).toBe("640");
60
+ // No explicit/default width supplied — nominal 320px default is inside [180,640].
61
+ expect(handle.getAttribute("aria-valuenow")).toBe("320");
62
+ });
63
+ it("honors custom panelMinWidth/panelMaxWidth on every handle", () => {
64
+ const { container } = render(AppShell, {
65
+ props: { variant: "workspace", panelResize: true, ...panelProps, panelMinWidth: 200, panelMaxWidth: 300 },
66
+ });
67
+ const handles = container.querySelectorAll(".st-appShell__resizeHandle");
68
+ expect(handles.length).toBe(3);
69
+ handles.forEach((handle) => {
70
+ expect(handle.getAttribute("aria-valuemin")).toBe("200");
71
+ expect(handle.getAttribute("aria-valuemax")).toBe("300");
72
+ });
73
+ });
74
+ it("renders no handle for a panel that is not provided", () => {
75
+ const { container } = render(AppShell, {
76
+ props: { variant: "workspace", panelResize: true, navigationPanel: panelProps.navigationPanel, main: panelProps.main },
77
+ });
78
+ expect(container.querySelectorAll(".st-appShell__resizeHandle").length).toBe(1);
79
+ });
80
+ it("renders NO handle for utilityPanel when utilitySide='bottom', but keeps handles for the other resizable panels", () => {
81
+ const { container } = render(AppShell, {
82
+ props: { variant: "workspace", panelResize: true, utilitySide: "bottom", ...panelProps },
83
+ });
84
+ expect(container.querySelector(".st-appShell__utilityPanel .st-appShell__resizeHandle")).toBeNull();
85
+ expect(container.querySelector(".st-appShell__navigationPanel .st-appShell__resizeHandle")).not.toBeNull();
86
+ expect(container.querySelector(".st-appShell__contextPanel .st-appShell__resizeHandle")).not.toBeNull();
87
+ });
88
+ it("applies the width CSS custom properties to the shell root, one per explicitly-widthed panel", () => {
89
+ const { container } = render(AppShell, {
90
+ props: {
91
+ variant: "workspace",
92
+ panelResize: true,
93
+ ...panelProps,
94
+ defaultPanelWidths: { navigationPanel: 300, contextPanel: 260, utilityPanel: 420 },
95
+ },
96
+ });
97
+ const root = container.querySelector(".st-appShell");
98
+ expect(root.style.getPropertyValue("--st-appShell-navigation-width")).toBe("300px");
99
+ expect(root.style.getPropertyValue("--st-appShell-context-width")).toBe("260px");
100
+ expect(root.style.getPropertyValue("--st-appShell-utility-width")).toBe("420px");
101
+ // primaryRail is not resizable — no rail-width var is ever emitted, regardless of panelResize.
102
+ expect(root.style.getPropertyValue("--st-appShell-rail-width")).toBe("");
103
+ });
104
+ it("does not set a width var for a panel with no explicit/default/controlled width (defers to the token default)", () => {
105
+ const { container } = render(AppShell, {
106
+ props: { variant: "workspace", panelResize: true, ...panelProps, defaultPanelWidths: { navigationPanel: 300 } },
107
+ });
108
+ const root = container.querySelector(".st-appShell");
109
+ expect(root.style.getPropertyValue("--st-appShell-navigation-width")).toBe("300px");
110
+ expect(root.style.getPropertyValue("--st-appShell-context-width")).toBe("");
111
+ expect(root.style.getPropertyValue("--st-appShell-utility-width")).toBe("");
112
+ });
113
+ });
114
+ describe("AppShell — panelResize keyboard interaction (uncontrolled)", () => {
115
+ it("ArrowRight grows a left-edge panel (navigationPanel) by 16px and fires onPanelResize", async () => {
116
+ const onPanelResize = vi.fn();
117
+ const { container } = render(AppShell, {
118
+ props: {
119
+ variant: "workspace",
120
+ panelResize: true,
121
+ ...panelProps,
122
+ defaultPanelWidths: { navigationPanel: 300 },
123
+ onPanelResize,
124
+ },
125
+ });
126
+ const handle = container.querySelector('.st-appShell__navigationPanel .st-appShell__resizeHandle');
127
+ await fireEvent.keyDown(handle, { key: "ArrowRight" });
128
+ expect(onPanelResize).toHaveBeenCalledWith("navigationPanel", 316);
129
+ expect(handle.getAttribute("aria-valuenow")).toBe("316");
130
+ });
131
+ it("ArrowLeft shrinks a left-edge panel (navigationPanel) by 16px", async () => {
132
+ const onPanelResize = vi.fn();
133
+ const { container } = render(AppShell, {
134
+ props: {
135
+ variant: "workspace",
136
+ panelResize: true,
137
+ ...panelProps,
138
+ defaultPanelWidths: { navigationPanel: 300 },
139
+ onPanelResize,
140
+ },
141
+ });
142
+ const handle = container.querySelector('.st-appShell__navigationPanel .st-appShell__resizeHandle');
143
+ await fireEvent.keyDown(handle, { key: "ArrowLeft" });
144
+ expect(onPanelResize).toHaveBeenCalledWith("navigationPanel", 284);
145
+ });
146
+ it("ArrowRight SHRINKS a right-edge panel (contextPanel) — moving the splitter right moves toward main", async () => {
147
+ const onPanelResize = vi.fn();
148
+ const { container } = render(AppShell, {
149
+ props: {
150
+ variant: "workspace",
151
+ panelResize: true,
152
+ ...panelProps,
153
+ defaultPanelWidths: { contextPanel: 300 },
154
+ onPanelResize,
155
+ },
156
+ });
157
+ const handle = container.querySelector('.st-appShell__contextPanel .st-appShell__resizeHandle');
158
+ await fireEvent.keyDown(handle, { key: "ArrowRight" });
159
+ expect(onPanelResize).toHaveBeenCalledWith("contextPanel", 284);
160
+ await fireEvent.keyDown(handle, { key: "ArrowLeft" });
161
+ expect(onPanelResize).toHaveBeenLastCalledWith("contextPanel", 300);
162
+ });
163
+ it("utilityPanel (default utilitySide='right') resizes like a right-edge panel", async () => {
164
+ const onPanelResize = vi.fn();
165
+ const { container } = render(AppShell, {
166
+ props: {
167
+ variant: "workspace",
168
+ panelResize: true,
169
+ ...panelProps,
170
+ defaultPanelWidths: { utilityPanel: 300 },
171
+ onPanelResize,
172
+ },
173
+ });
174
+ const handle = container.querySelector('.st-appShell__utilityPanel .st-appShell__resizeHandle');
175
+ await fireEvent.keyDown(handle, { key: "ArrowRight" });
176
+ expect(onPanelResize).toHaveBeenCalledWith("utilityPanel", 284);
177
+ });
178
+ it("utilityPanel with utilitySide='left' resizes like a left-edge panel", async () => {
179
+ const onPanelResize = vi.fn();
180
+ const { container } = render(AppShell, {
181
+ props: {
182
+ variant: "workspace",
183
+ panelResize: true,
184
+ utilitySide: "left",
185
+ ...panelProps,
186
+ defaultPanelWidths: { utilityPanel: 300 },
187
+ onPanelResize,
188
+ },
189
+ });
190
+ const handle = container.querySelector('.st-appShell__utilityPanel .st-appShell__resizeHandle');
191
+ await fireEvent.keyDown(handle, { key: "ArrowRight" });
192
+ expect(onPanelResize).toHaveBeenCalledWith("utilityPanel", 316);
193
+ });
194
+ it("Home jumps to panelMinWidth and End jumps to panelMaxWidth, both firing onPanelResize", async () => {
195
+ const onPanelResize = vi.fn();
196
+ const { container } = render(AppShell, {
197
+ props: {
198
+ variant: "workspace",
199
+ panelResize: true,
200
+ ...panelProps,
201
+ defaultPanelWidths: { navigationPanel: 300 },
202
+ panelMinWidth: 150,
203
+ panelMaxWidth: 500,
204
+ onPanelResize,
205
+ },
206
+ });
207
+ const handle = container.querySelector('.st-appShell__navigationPanel .st-appShell__resizeHandle');
208
+ await fireEvent.keyDown(handle, { key: "Home" });
209
+ expect(onPanelResize).toHaveBeenCalledWith("navigationPanel", 150);
210
+ expect(handle.getAttribute("aria-valuenow")).toBe("150");
211
+ await fireEvent.keyDown(handle, { key: "End" });
212
+ expect(onPanelResize).toHaveBeenCalledWith("navigationPanel", 500);
213
+ expect(handle.getAttribute("aria-valuenow")).toBe("500");
214
+ });
215
+ it("clamps at the upper bound: repeated ArrowRight never exceeds panelMaxWidth", async () => {
216
+ const onPanelResize = vi.fn();
217
+ const { container } = render(AppShell, {
218
+ props: {
219
+ variant: "workspace",
220
+ panelResize: true,
221
+ ...panelProps,
222
+ defaultPanelWidths: { navigationPanel: 495 },
223
+ panelMinWidth: 180,
224
+ panelMaxWidth: 500,
225
+ onPanelResize,
226
+ },
227
+ });
228
+ const handle = container.querySelector('.st-appShell__navigationPanel .st-appShell__resizeHandle');
229
+ await fireEvent.keyDown(handle, { key: "ArrowRight" }); // 495 + 16 = 511 -> clamped to 500
230
+ expect(onPanelResize).toHaveBeenCalledWith("navigationPanel", 500);
231
+ await fireEvent.keyDown(handle, { key: "ArrowRight" }); // stays clamped, still fires
232
+ expect(onPanelResize).toHaveBeenLastCalledWith("navigationPanel", 500);
233
+ expect(handle.getAttribute("aria-valuenow")).toBe("500");
234
+ });
235
+ it("clamps at the lower bound: repeated ArrowLeft never goes below panelMinWidth", async () => {
236
+ const onPanelResize = vi.fn();
237
+ const { container } = render(AppShell, {
238
+ props: {
239
+ variant: "workspace",
240
+ panelResize: true,
241
+ ...panelProps,
242
+ defaultPanelWidths: { navigationPanel: 190 },
243
+ panelMinWidth: 180,
244
+ onPanelResize,
245
+ },
246
+ });
247
+ const handle = container.querySelector('.st-appShell__navigationPanel .st-appShell__resizeHandle');
248
+ await fireEvent.keyDown(handle, { key: "ArrowLeft" }); // 190 - 16 = 174 -> clamped to 180
249
+ expect(onPanelResize).toHaveBeenCalledWith("navigationPanel", 180);
250
+ });
251
+ it("ignores keys other than ArrowLeft/ArrowRight/Home/End", async () => {
252
+ const onPanelResize = vi.fn();
253
+ const { container } = render(AppShell, {
254
+ props: { variant: "workspace", panelResize: true, ...panelProps, onPanelResize },
255
+ });
256
+ const handle = container.querySelector('.st-appShell__navigationPanel .st-appShell__resizeHandle');
257
+ await fireEvent.keyDown(handle, { key: "Tab" });
258
+ await fireEvent.keyDown(handle, { key: "Enter" });
259
+ expect(onPanelResize).not.toHaveBeenCalled();
260
+ });
261
+ });
262
+ describe("AppShell — panelResize pointer drag (uncontrolled)", () => {
263
+ it("dragging a left-edge handle rightward grows the panel and fires onPanelResize on move", async () => {
264
+ const onPanelResize = vi.fn();
265
+ const { container } = render(AppShell, {
266
+ props: {
267
+ variant: "workspace",
268
+ panelResize: true,
269
+ ...panelProps,
270
+ defaultPanelWidths: { navigationPanel: 300 },
271
+ onPanelResize,
272
+ },
273
+ });
274
+ const handle = container.querySelector('.st-appShell__navigationPanel .st-appShell__resizeHandle');
275
+ await fireEvent.pointerDown(handle, { clientX: 100, pointerId: 1 });
276
+ await fireEvent.pointerMove(handle, { clientX: 140, pointerId: 1 });
277
+ expect(onPanelResize).toHaveBeenCalledWith("navigationPanel", 340);
278
+ await fireEvent.pointerUp(handle, { clientX: 140, pointerId: 1 });
279
+ // Further movement after pointerup is a no-op (drag ended).
280
+ onPanelResize.mockClear();
281
+ await fireEvent.pointerMove(handle, { clientX: 200, pointerId: 1 });
282
+ expect(onPanelResize).not.toHaveBeenCalled();
283
+ });
284
+ it("dragging a right-edge handle rightward shrinks the panel", async () => {
285
+ const onPanelResize = vi.fn();
286
+ const { container } = render(AppShell, {
287
+ props: {
288
+ variant: "workspace",
289
+ panelResize: true,
290
+ ...panelProps,
291
+ defaultPanelWidths: { contextPanel: 300 },
292
+ onPanelResize,
293
+ },
294
+ });
295
+ const handle = container.querySelector('.st-appShell__contextPanel .st-appShell__resizeHandle');
296
+ await fireEvent.pointerDown(handle, { clientX: 100, pointerId: 1 });
297
+ await fireEvent.pointerMove(handle, { clientX: 140, pointerId: 1 });
298
+ expect(onPanelResize).toHaveBeenCalledWith("contextPanel", 260);
299
+ });
300
+ });
301
+ describe("AppShell — panelResize controlled mode (panelWidths)", () => {
302
+ it("never mutates its own state: the rendered width stays exactly what panelWidths says, even after a commit-triggering interaction", async () => {
303
+ const onPanelResize = vi.fn();
304
+ const { container } = render(AppShell, {
305
+ props: {
306
+ variant: "workspace",
307
+ panelResize: true,
308
+ ...panelProps,
309
+ panelWidths: { navigationPanel: 250, contextPanel: 300, utilityPanel: 400 },
310
+ onPanelResize,
311
+ },
312
+ });
313
+ const root = container.querySelector(".st-appShell");
314
+ const handle = container.querySelector('.st-appShell__navigationPanel .st-appShell__resizeHandle');
315
+ expect(handle.getAttribute("aria-valuenow")).toBe("250");
316
+ expect(root.style.getPropertyValue("--st-appShell-navigation-width")).toBe("250px");
317
+ await fireEvent.keyDown(handle, { key: "ArrowRight" });
318
+ // onPanelResize told the consumer what the next width *should* be...
319
+ expect(onPanelResize).toHaveBeenCalledWith("navigationPanel", 266);
320
+ // ...but since the consumer (the test) never fed that back through the
321
+ // `panelWidths` prop, the component itself must not have changed anything.
322
+ expect(handle.getAttribute("aria-valuenow")).toBe("250");
323
+ expect(root.style.getPropertyValue("--st-appShell-navigation-width")).toBe("250px");
324
+ await fireEvent.pointerDown(handle, { clientX: 0, pointerId: 2 });
325
+ await fireEvent.pointerMove(handle, { clientX: 50, pointerId: 2 });
326
+ expect(onPanelResize).toHaveBeenLastCalledWith("navigationPanel", 300);
327
+ expect(handle.getAttribute("aria-valuenow")).toBe("250");
328
+ });
329
+ it("re-renders from a new panelWidths prop (the consumer driving the loop back)", async () => {
330
+ const { container, rerender } = render(AppShell, {
331
+ props: { variant: "workspace", panelResize: true, ...panelProps, panelWidths: { navigationPanel: 250 } },
332
+ });
333
+ const root = container.querySelector(".st-appShell");
334
+ expect(root.style.getPropertyValue("--st-appShell-navigation-width")).toBe("250px");
335
+ await rerender({ variant: "workspace", panelResize: true, ...panelProps, panelWidths: { navigationPanel: 400 } });
336
+ expect(root.style.getPropertyValue("--st-appShell-navigation-width")).toBe("400px");
337
+ });
338
+ });