@blackbelt-technology/pi-dashboard-client-utils 0.7.0 → 0.9.0
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/README.md +25 -0
- package/package.json +37 -4
- package/src/ActionList.tsx +9 -12
- package/src/Dialog.tsx +59 -23
- package/src/LayerPortal.tsx +61 -0
- package/src/SearchableSelectDialog.tsx +94 -31
- package/src/StatusPill.tsx +10 -8
- package/src/ZoomControls.tsx +6 -3
- package/src/agent-card-utils.ts +10 -3
- package/src/identity/dpop.ts +75 -0
- package/src/identity/login-flow.ts +197 -0
- package/src/identity/oidc-flow.ts +96 -0
- package/src/identity/pkce.ts +129 -0
- package/src/identity/token-store.ts +66 -0
- package/src/mdi-by-key.ts +90 -0
- package/src/useFocusTrap.ts +55 -1
- package/src/useZoomPan.ts +33 -13
- package/src/AGENTS.md +0 -25
- package/src/__tests__/ActionList.test.tsx +0 -72
- package/src/__tests__/Confirm.test.tsx +0 -105
- package/src/__tests__/Dialog.test.tsx +0 -215
- package/src/__tests__/DialogPortal.test.tsx +0 -58
- package/src/__tests__/EmptyState.test.tsx +0 -44
- package/src/__tests__/Skeleton.test.tsx +0 -51
- package/src/__tests__/StatusPill.test.tsx +0 -63
- package/src/__tests__/escape-stack.test.ts +0 -166
- package/src/__tests__/statusPresentation.test.ts +0 -34
- package/src/__tests__/useFocusTrap.test.tsx +0 -68
- package/src/__tests__/useMobile.test.tsx +0 -92
- package/src/__tests__/useZoomPan.test.ts +0 -128
- package/src/extension-ui/AGENTS.md +0 -10
- package/src/minimal-chat/AGENTS.md +0 -9
- package/src/minimal-chat/__tests__/MinimalChatView.test.tsx +0 -235
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import { cleanup, fireEvent, render } from "@testing-library/react";
|
|
2
|
-
import React from "react";
|
|
3
|
-
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
4
|
-
import { EmptyState } from "../EmptyState.js";
|
|
5
|
-
|
|
6
|
-
afterEach(() => cleanup());
|
|
7
|
-
|
|
8
|
-
describe("EmptyState", () => {
|
|
9
|
-
it("renders title, body, and a single primary CTA", () => {
|
|
10
|
-
const onClick = vi.fn();
|
|
11
|
-
const { getByText, getAllByRole, container } = render(
|
|
12
|
-
<EmptyState
|
|
13
|
-
title="No sessions yet"
|
|
14
|
-
body="Spawn a pi session to see it here."
|
|
15
|
-
action={{ label: "Spawn session", onClick }}
|
|
16
|
-
/>,
|
|
17
|
-
);
|
|
18
|
-
expect(getByText("No sessions yet")).toBeDefined();
|
|
19
|
-
expect(getByText("Spawn a pi session to see it here.")).toBeDefined();
|
|
20
|
-
const primaries = container.querySelectorAll('[data-empty-state-action="primary"]');
|
|
21
|
-
expect(primaries).toHaveLength(1);
|
|
22
|
-
fireEvent.click(getAllByRole("button")[0]);
|
|
23
|
-
expect(onClick).toHaveBeenCalledTimes(1);
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
it("allows at most one primary action (single `action` prop)", () => {
|
|
27
|
-
const { container } = render(
|
|
28
|
-
<EmptyState
|
|
29
|
-
title="Empty"
|
|
30
|
-
action={{ label: "Primary", onClick: () => {} }}
|
|
31
|
-
secondaryAction={{ label: "Escape", onClick: () => {} }}
|
|
32
|
-
/>,
|
|
33
|
-
);
|
|
34
|
-
// The contract: exactly one primary, at most one secondary — never >1 primary.
|
|
35
|
-
expect(container.querySelectorAll('[data-empty-state-action="primary"]')).toHaveLength(1);
|
|
36
|
-
expect(container.querySelectorAll('[data-empty-state-action="secondary"]')).toHaveLength(1);
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
it("renders without any actions", () => {
|
|
40
|
-
const { container, getByText } = render(<EmptyState title="Nothing here" />);
|
|
41
|
-
expect(getByText("Nothing here")).toBeDefined();
|
|
42
|
-
expect(container.querySelectorAll("button")).toHaveLength(0);
|
|
43
|
-
});
|
|
44
|
-
});
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import { cleanup, render } from "@testing-library/react";
|
|
2
|
-
import React from "react";
|
|
3
|
-
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
4
|
-
import { Skeleton } from "../Skeleton.js";
|
|
5
|
-
|
|
6
|
-
afterEach(() => cleanup());
|
|
7
|
-
|
|
8
|
-
function mockReducedMotion(reduce: boolean) {
|
|
9
|
-
vi.stubGlobal(
|
|
10
|
-
"matchMedia",
|
|
11
|
-
(query: string) =>
|
|
12
|
-
({
|
|
13
|
-
matches: query.includes("prefers-reduced-motion") ? reduce : false,
|
|
14
|
-
media: query,
|
|
15
|
-
addEventListener: () => {},
|
|
16
|
-
removeEventListener: () => {},
|
|
17
|
-
addListener: () => {},
|
|
18
|
-
removeListener: () => {},
|
|
19
|
-
dispatchEvent: () => false,
|
|
20
|
-
onchange: null,
|
|
21
|
-
}) as unknown as MediaQueryList,
|
|
22
|
-
);
|
|
23
|
-
// jsdom attaches matchMedia to window; mirror the stub there too.
|
|
24
|
-
(window as unknown as { matchMedia: typeof window.matchMedia }).matchMedia =
|
|
25
|
-
globalThis.matchMedia;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
describe("Skeleton", () => {
|
|
29
|
-
beforeEach(() => mockReducedMotion(false));
|
|
30
|
-
|
|
31
|
-
it("renders `count` shaped placeholder rows", () => {
|
|
32
|
-
const { container } = render(<Skeleton variant="bubble" count={3} />);
|
|
33
|
-
expect(container.querySelectorAll("[data-skeleton-item]")).toHaveLength(3);
|
|
34
|
-
expect(container.querySelector("[data-skeleton='bubble']")).toBeTruthy();
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
it("animates (shimmer) when reduced motion is off", () => {
|
|
38
|
-
mockReducedMotion(false);
|
|
39
|
-
const { container } = render(<Skeleton variant="row" />);
|
|
40
|
-
const item = container.querySelector("[data-skeleton-item]");
|
|
41
|
-
expect(item?.className).toContain("animate-pulse");
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
it("renders static (no shimmer) under prefers-reduced-motion: reduce", () => {
|
|
45
|
-
mockReducedMotion(true);
|
|
46
|
-
const { container } = render(<Skeleton variant="row" />);
|
|
47
|
-
expect(container.querySelector("[data-skeleton][data-static='true']")).toBeTruthy();
|
|
48
|
-
const item = container.querySelector("[data-skeleton-item]");
|
|
49
|
-
expect(item?.className).not.toContain("animate-pulse");
|
|
50
|
-
});
|
|
51
|
-
});
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
import { describe, it, expect, afterEach } from "vitest";
|
|
3
|
-
import { render, cleanup } from "@testing-library/react";
|
|
4
|
-
import { StatusPill } from "../StatusPill.js";
|
|
5
|
-
|
|
6
|
-
afterEach(() => cleanup());
|
|
7
|
-
|
|
8
|
-
describe("StatusPill", () => {
|
|
9
|
-
it("renders the text", () => {
|
|
10
|
-
const { getByText } = render(<StatusPill state="running" text="Working" />);
|
|
11
|
-
expect(getByText("Working")).toBeDefined();
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
it("sets data-status-pill attribute to state", () => {
|
|
15
|
-
const { container } = render(<StatusPill state="error" text="Failed" />);
|
|
16
|
-
expect(container.firstChild).toHaveProperty("dataset");
|
|
17
|
-
const el = container.querySelector("[data-status-pill]");
|
|
18
|
-
expect(el?.getAttribute("data-status-pill")).toBe("error");
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
it("each state renders with state-specific styling", () => {
|
|
22
|
-
const states: Array<"running" | "success" | "error" | "info" | "warn" | "muted"> = [
|
|
23
|
-
"running",
|
|
24
|
-
"success",
|
|
25
|
-
"error",
|
|
26
|
-
"info",
|
|
27
|
-
"warn",
|
|
28
|
-
"muted",
|
|
29
|
-
];
|
|
30
|
-
for (const state of states) {
|
|
31
|
-
const { container, unmount } = render(<StatusPill state={state} text={state} />);
|
|
32
|
-
const el = container.querySelector(`[data-status-pill="${state}"]`);
|
|
33
|
-
expect(el).toBeTruthy();
|
|
34
|
-
unmount();
|
|
35
|
-
}
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
it("tooltip is set from `tooltip` prop", () => {
|
|
39
|
-
const { container } = render(
|
|
40
|
-
<StatusPill state="running" text="X" tooltip="Currently running" />,
|
|
41
|
-
);
|
|
42
|
-
expect(container.firstChild?.parentElement?.getAttribute("title") ?? container.querySelector("[title]")?.getAttribute("title")).toBe("Currently running");
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
// Post static-conversion (change: shrink-client-index-chunk): mdi[key] is a
|
|
46
|
-
// synchronous lookup, so the icon path renders immediately with no useEffect.
|
|
47
|
-
it("renders the icon <path> synchronously for a valid mdi key (test-plan #S3)", () => {
|
|
48
|
-
const { container } = render(
|
|
49
|
-
<StatusPill state="running" text="Working" icon="mdiRefresh" />,
|
|
50
|
-
);
|
|
51
|
-
const p = container.querySelector("svg path");
|
|
52
|
-
expect(p).toBeTruthy();
|
|
53
|
-
expect(p?.getAttribute("d") ?? "").not.toBe("");
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
it("renders no icon and does not throw for an unknown mdi key (test-plan #S3)", () => {
|
|
57
|
-
const { container } = render(
|
|
58
|
-
<StatusPill state="error" text="Failed" icon="mdiNotAReal" />,
|
|
59
|
-
);
|
|
60
|
-
expect(container.querySelector("svg path")).toBeNull();
|
|
61
|
-
expect(container.querySelector("[data-status-pill]")?.textContent).toContain("Failed");
|
|
62
|
-
});
|
|
63
|
-
});
|
|
@@ -1,166 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect, afterEach, vi } from "vitest";
|
|
2
|
-
import { createElement, StrictMode } from "react";
|
|
3
|
-
import { render, cleanup } from "@testing-library/react";
|
|
4
|
-
import {
|
|
5
|
-
registerEscapeLayer,
|
|
6
|
-
unregisterEscapeLayer,
|
|
7
|
-
useEscapeDismiss,
|
|
8
|
-
__resetEscapeStack,
|
|
9
|
-
} from "../escape-stack.js";
|
|
10
|
-
|
|
11
|
-
afterEach(() => {
|
|
12
|
-
cleanup();
|
|
13
|
-
__resetEscapeStack();
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
function pressEscape(init: KeyboardEventInit = {}): KeyboardEvent {
|
|
17
|
-
const ev = new KeyboardEvent("keydown", {
|
|
18
|
-
key: "Escape",
|
|
19
|
-
bubbles: true,
|
|
20
|
-
cancelable: true,
|
|
21
|
-
...init,
|
|
22
|
-
});
|
|
23
|
-
document.dispatchEvent(ev);
|
|
24
|
-
return ev;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
describe("escape-stack — topmost-only dispatch", () => {
|
|
28
|
-
it("E1 topmost-only: only the top layer's onEscape fires", () => {
|
|
29
|
-
const a = vi.fn();
|
|
30
|
-
const b = vi.fn();
|
|
31
|
-
registerEscapeLayer("A", a);
|
|
32
|
-
registerEscapeLayer("B", b);
|
|
33
|
-
pressEscape();
|
|
34
|
-
expect(b).toHaveBeenCalledTimes(1);
|
|
35
|
-
expect(a).not.toHaveBeenCalled();
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
it("E2 successive peel: three Escapes dismiss C, B, A in order", () => {
|
|
39
|
-
const order: string[] = [];
|
|
40
|
-
registerEscapeLayer("A", () => {
|
|
41
|
-
order.push("A");
|
|
42
|
-
unregisterEscapeLayer("A");
|
|
43
|
-
});
|
|
44
|
-
registerEscapeLayer("B", () => {
|
|
45
|
-
order.push("B");
|
|
46
|
-
unregisterEscapeLayer("B");
|
|
47
|
-
});
|
|
48
|
-
registerEscapeLayer("C", () => {
|
|
49
|
-
order.push("C");
|
|
50
|
-
unregisterEscapeLayer("C");
|
|
51
|
-
});
|
|
52
|
-
pressEscape();
|
|
53
|
-
pressEscape();
|
|
54
|
-
pressEscape();
|
|
55
|
-
expect(order).toEqual(["C", "B", "A"]);
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
it("E3 lone layer: single layer still dismisses", () => {
|
|
59
|
-
const a = vi.fn();
|
|
60
|
-
registerEscapeLayer("A", a);
|
|
61
|
-
pressEscape();
|
|
62
|
-
expect(a).toHaveBeenCalledTimes(1);
|
|
63
|
-
});
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
describe("escape-stack — lifecycle", () => {
|
|
67
|
-
it("E4 order-independent unregister: removing A by id leaves B live", () => {
|
|
68
|
-
const a = vi.fn();
|
|
69
|
-
const b = vi.fn();
|
|
70
|
-
registerEscapeLayer("A", a);
|
|
71
|
-
registerEscapeLayer("B", b);
|
|
72
|
-
unregisterEscapeLayer("A");
|
|
73
|
-
pressEscape();
|
|
74
|
-
expect(b).toHaveBeenCalledTimes(1);
|
|
75
|
-
expect(a).not.toHaveBeenCalled();
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
it("E11 latest handler without re-registration: re-register same id uses cb2", () => {
|
|
79
|
-
const cb1 = vi.fn();
|
|
80
|
-
const cb2 = vi.fn();
|
|
81
|
-
registerEscapeLayer("A", cb1);
|
|
82
|
-
registerEscapeLayer("A", cb2); // same id → refresh, not a second entry
|
|
83
|
-
pressEscape();
|
|
84
|
-
expect(cb2).toHaveBeenCalledTimes(1);
|
|
85
|
-
expect(cb1).not.toHaveBeenCalled();
|
|
86
|
-
});
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
describe("escape-stack — consume + passthrough", () => {
|
|
90
|
-
it("E5 empty passthrough: no layers → event not consumed, window spy fires", () => {
|
|
91
|
-
const spy = vi.fn();
|
|
92
|
-
window.addEventListener("keydown", spy);
|
|
93
|
-
const ev = pressEscape();
|
|
94
|
-
expect(spy).toHaveBeenCalledTimes(1);
|
|
95
|
-
expect(ev.defaultPrevented).toBe(false);
|
|
96
|
-
window.removeEventListener("keydown", spy);
|
|
97
|
-
});
|
|
98
|
-
|
|
99
|
-
it("E6 consume blocks window: layer dismisses, window spy does not fire", () => {
|
|
100
|
-
const a = vi.fn();
|
|
101
|
-
const spy = vi.fn();
|
|
102
|
-
window.addEventListener("keydown", spy);
|
|
103
|
-
registerEscapeLayer("A", a);
|
|
104
|
-
const ev = pressEscape();
|
|
105
|
-
expect(a).toHaveBeenCalledTimes(1);
|
|
106
|
-
expect(spy).not.toHaveBeenCalled();
|
|
107
|
-
expect(ev.defaultPrevented).toBe(true);
|
|
108
|
-
window.removeEventListener("keydown", spy);
|
|
109
|
-
});
|
|
110
|
-
});
|
|
111
|
-
|
|
112
|
-
describe("escape-stack — guards", () => {
|
|
113
|
-
it("E7 key-repeat guard: repeat dismisses nothing, non-repeat dismisses B", () => {
|
|
114
|
-
const a = vi.fn();
|
|
115
|
-
const b = vi.fn();
|
|
116
|
-
registerEscapeLayer("A", a);
|
|
117
|
-
registerEscapeLayer("B", b);
|
|
118
|
-
pressEscape({ repeat: true });
|
|
119
|
-
expect(a).not.toHaveBeenCalled();
|
|
120
|
-
expect(b).not.toHaveBeenCalled();
|
|
121
|
-
pressEscape({ repeat: false });
|
|
122
|
-
expect(b).toHaveBeenCalledTimes(1);
|
|
123
|
-
expect(a).not.toHaveBeenCalled();
|
|
124
|
-
});
|
|
125
|
-
|
|
126
|
-
it("E8 defaultPrevented opt-out: layer stays, onEscape not called", () => {
|
|
127
|
-
const a = vi.fn();
|
|
128
|
-
registerEscapeLayer("A", a);
|
|
129
|
-
// A focused input already handled Escape (defaultPrevented) before it bubbles
|
|
130
|
-
// to document — simulate via a capture-phase listener that preventDefaults.
|
|
131
|
-
const pre = (e: KeyboardEvent) => e.preventDefault();
|
|
132
|
-
document.addEventListener("keydown", pre, { capture: true });
|
|
133
|
-
pressEscape();
|
|
134
|
-
expect(a).not.toHaveBeenCalled();
|
|
135
|
-
document.removeEventListener("keydown", pre, { capture: true });
|
|
136
|
-
// A is still registered → a clean Escape now dismisses it.
|
|
137
|
-
pressEscape();
|
|
138
|
-
expect(a).toHaveBeenCalledTimes(1);
|
|
139
|
-
});
|
|
140
|
-
});
|
|
141
|
-
|
|
142
|
-
describe("escape-stack — hook lifecycle", () => {
|
|
143
|
-
it("E9 StrictMode id stability: one entry, fires once, no leak/drop", () => {
|
|
144
|
-
const onEscape = vi.fn();
|
|
145
|
-
function Layer() {
|
|
146
|
-
useEscapeDismiss(true, onEscape);
|
|
147
|
-
return null;
|
|
148
|
-
}
|
|
149
|
-
render(createElement(StrictMode, null, createElement(Layer)));
|
|
150
|
-
pressEscape();
|
|
151
|
-
expect(onEscape).toHaveBeenCalledTimes(1);
|
|
152
|
-
});
|
|
153
|
-
});
|
|
154
|
-
|
|
155
|
-
describe("escape-stack — attach-once / never-detach", () => {
|
|
156
|
-
it("E10 attaches document keydown once, no duplicate across empty→refill", () => {
|
|
157
|
-
__resetEscapeStack(); // clean module state: detached
|
|
158
|
-
const addSpy = vi.spyOn(document, "addEventListener");
|
|
159
|
-
registerEscapeLayer("A", vi.fn()); // first registration attaches
|
|
160
|
-
unregisterEscapeLayer("A"); // stack empty, listener stays attached
|
|
161
|
-
registerEscapeLayer("B", vi.fn()); // already attached → no new listener
|
|
162
|
-
const keydownAdds = addSpy.mock.calls.filter((c) => c[0] === "keydown");
|
|
163
|
-
expect(keydownAdds).toHaveLength(1);
|
|
164
|
-
addSpy.mockRestore();
|
|
165
|
-
});
|
|
166
|
-
});
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from "vitest";
|
|
2
|
-
import {
|
|
3
|
-
type StatusKind,
|
|
4
|
-
statusAriaLabel,
|
|
5
|
-
statusPresentation,
|
|
6
|
-
} from "../statusPresentation.js";
|
|
7
|
-
|
|
8
|
-
describe("statusPresentation", () => {
|
|
9
|
-
const kinds: StatusKind[] = ["done", "current", "todo", "error"];
|
|
10
|
-
|
|
11
|
-
it("provides a non-color glyph indicator for every state", () => {
|
|
12
|
-
for (const kind of kinds) {
|
|
13
|
-
expect(statusPresentation(kind).glyph.trim().length).toBeGreaterThan(0);
|
|
14
|
-
}
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
it("renders a distinct glyph per state (distinguishable without color)", () => {
|
|
18
|
-
const glyphs = kinds.map((k) => statusPresentation(k).glyph);
|
|
19
|
-
expect(new Set(glyphs).size).toBe(kinds.length);
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
it("done is distinguishable from todo by glyph alone", () => {
|
|
23
|
-
expect(statusPresentation("done").glyph).not.toBe(statusPresentation("todo").glyph);
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
it("maps each state to a semantic --status / token var", () => {
|
|
27
|
-
expect(statusPresentation("done").tokenVar).toContain("var(--");
|
|
28
|
-
expect(statusPresentation("error").tokenVar).toContain("var(--status-error)");
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
it("statusAriaLabel names the item and its state", () => {
|
|
32
|
-
expect(statusAriaLabel("Proposal", "done")).toBe("Proposal, done");
|
|
33
|
-
});
|
|
34
|
-
});
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect, afterEach } from "vitest";
|
|
2
|
-
import { render, cleanup, fireEvent } from "@testing-library/react";
|
|
3
|
-
import React, { useRef } from "react";
|
|
4
|
-
import { useFocusTrap } from "../useFocusTrap.js";
|
|
5
|
-
|
|
6
|
-
afterEach(() => cleanup());
|
|
7
|
-
|
|
8
|
-
function Harness({ open }: { open: boolean }) {
|
|
9
|
-
const ref = useRef<HTMLDivElement>(null);
|
|
10
|
-
useFocusTrap(ref, open);
|
|
11
|
-
if (!open) return null;
|
|
12
|
-
return (
|
|
13
|
-
<div ref={ref} tabIndex={-1} data-testid="trap">
|
|
14
|
-
<button data-testid="first">First</button>
|
|
15
|
-
<button data-testid="mid">Mid</button>
|
|
16
|
-
<button data-testid="last">Last</button>
|
|
17
|
-
</div>
|
|
18
|
-
);
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
describe("useFocusTrap", () => {
|
|
22
|
-
it("focuses the first focusable child on open", () => {
|
|
23
|
-
const { getByTestId } = render(<Harness open={true} />);
|
|
24
|
-
expect(document.activeElement).toBe(getByTestId("first"));
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
it("wraps Tab from last to first", () => {
|
|
28
|
-
const { getByTestId } = render(<Harness open={true} />);
|
|
29
|
-
const last = getByTestId("last");
|
|
30
|
-
last.focus();
|
|
31
|
-
fireEvent.keyDown(document, { key: "Tab" });
|
|
32
|
-
expect(document.activeElement).toBe(getByTestId("first"));
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
it("wraps Shift+Tab from first to last", () => {
|
|
36
|
-
const { getByTestId } = render(<Harness open={true} />);
|
|
37
|
-
const first = getByTestId("first");
|
|
38
|
-
first.focus();
|
|
39
|
-
fireEvent.keyDown(document, { key: "Tab", shiftKey: true });
|
|
40
|
-
expect(document.activeElement).toBe(getByTestId("last"));
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
it("restores focus to the previously-focused element on close", () => {
|
|
44
|
-
const outside = document.createElement("button");
|
|
45
|
-
outside.setAttribute("data-testid", "outside");
|
|
46
|
-
document.body.appendChild(outside);
|
|
47
|
-
outside.focus();
|
|
48
|
-
expect(document.activeElement).toBe(outside);
|
|
49
|
-
|
|
50
|
-
const { rerender } = render(<Harness open={true} />);
|
|
51
|
-
// focus moved into the trap
|
|
52
|
-
expect(document.activeElement).not.toBe(outside);
|
|
53
|
-
|
|
54
|
-
rerender(<Harness open={false} />);
|
|
55
|
-
expect(document.activeElement).toBe(outside);
|
|
56
|
-
outside.remove();
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
it("focuses the container itself when no focusable child exists", () => {
|
|
60
|
-
function Empty() {
|
|
61
|
-
const ref = useRef<HTMLDivElement>(null);
|
|
62
|
-
useFocusTrap(ref, true);
|
|
63
|
-
return <div ref={ref} tabIndex={-1} data-testid="empty" />;
|
|
64
|
-
}
|
|
65
|
-
const { getByTestId } = render(<Empty />);
|
|
66
|
-
expect(document.activeElement).toBe(getByTestId("empty"));
|
|
67
|
-
});
|
|
68
|
-
});
|
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect, beforeEach, vi } from "vitest";
|
|
2
|
-
import React from "react";
|
|
3
|
-
import { renderHook } from "@testing-library/react";
|
|
4
|
-
import { MobileProvider, useMobile } from "../useMobile.js";
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Mocks `window.matchMedia` so it answers any query string the way a browser
|
|
8
|
-
* with the given viewport (vw, vh) would: parses `(max-width: Npx)` and
|
|
9
|
-
* `(max-height: Npx)` clauses, treats commas as OR. This mirrors what
|
|
10
|
-
* `useMediaQuery` consumes — the comma-OR semantics is the actual contract
|
|
11
|
-
* we want to pin in `useMobile`.
|
|
12
|
-
*/
|
|
13
|
-
function installMatchMediaForViewport(vw: number, vh: number): void {
|
|
14
|
-
Object.defineProperty(window, "matchMedia", {
|
|
15
|
-
writable: true,
|
|
16
|
-
configurable: true,
|
|
17
|
-
value: vi.fn().mockImplementation((query: string) => {
|
|
18
|
-
const clauses = query.split(",").map((c) => c.trim());
|
|
19
|
-
const matches = clauses.some((clause) => {
|
|
20
|
-
const w = clause.match(/\(\s*max-width:\s*(\d+)px\s*\)/);
|
|
21
|
-
if (w) return vw <= Number(w[1]);
|
|
22
|
-
const h = clause.match(/\(\s*max-height:\s*(\d+)px\s*\)/);
|
|
23
|
-
if (h) return vh <= Number(h[1]);
|
|
24
|
-
return false;
|
|
25
|
-
});
|
|
26
|
-
return {
|
|
27
|
-
matches,
|
|
28
|
-
media: query,
|
|
29
|
-
onchange: null,
|
|
30
|
-
addListener: vi.fn(),
|
|
31
|
-
removeListener: vi.fn(),
|
|
32
|
-
addEventListener: vi.fn(),
|
|
33
|
-
removeEventListener: vi.fn(),
|
|
34
|
-
dispatchEvent: vi.fn(),
|
|
35
|
-
};
|
|
36
|
-
}),
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
function wrapper({ children }: { children: React.ReactNode }) {
|
|
41
|
-
return <MobileProvider>{children}</MobileProvider>;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
describe("useMobile — width-or-height predicate", () => {
|
|
45
|
-
beforeEach(() => {
|
|
46
|
-
vi.restoreAllMocks();
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
it("portrait phone (375x812) is mobile (width arm)", () => {
|
|
50
|
-
installMatchMediaForViewport(375, 812);
|
|
51
|
-
const { result } = renderHook(() => useMobile(), { wrapper });
|
|
52
|
-
expect(result.current).toBe(true);
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
it("landscape phone (844x390) is mobile (height arm) — the iPhone 14 case", () => {
|
|
56
|
-
installMatchMediaForViewport(844, 390);
|
|
57
|
-
const { result } = renderHook(() => useMobile(), { wrapper });
|
|
58
|
-
expect(result.current).toBe(true);
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
it("landscape phone (915x412) is mobile (height arm) — the Pixel 8 case", () => {
|
|
62
|
-
installMatchMediaForViewport(915, 412);
|
|
63
|
-
const { result } = renderHook(() => useMobile(), { wrapper });
|
|
64
|
-
expect(result.current).toBe(true);
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
it("tablet portrait (768x1024) is NOT mobile", () => {
|
|
68
|
-
installMatchMediaForViewport(768, 1024);
|
|
69
|
-
const { result } = renderHook(() => useMobile(), { wrapper });
|
|
70
|
-
expect(result.current).toBe(false);
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
it("tablet landscape (1024x768) is NOT mobile", () => {
|
|
74
|
-
installMatchMediaForViewport(1024, 768);
|
|
75
|
-
const { result } = renderHook(() => useMobile(), { wrapper });
|
|
76
|
-
expect(result.current).toBe(false);
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
it("desktop (1440x900) is NOT mobile", () => {
|
|
80
|
-
installMatchMediaForViewport(1440, 900);
|
|
81
|
-
const { result } = renderHook(() => useMobile(), { wrapper });
|
|
82
|
-
expect(result.current).toBe(false);
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
it("desktop short window (1200x500) flips to mobile (documented side effect)", () => {
|
|
86
|
-
// Pinned regression: shrinking a desktop window vertically below 600px
|
|
87
|
-
// intentionally enters mobile mode. See design.md decision 1 alternatives.
|
|
88
|
-
installMatchMediaForViewport(1200, 500);
|
|
89
|
-
const { result } = renderHook(() => useMobile(), { wrapper });
|
|
90
|
-
expect(result.current).toBe(true);
|
|
91
|
-
});
|
|
92
|
-
});
|
|
@@ -1,128 +0,0 @@
|
|
|
1
|
-
import { act, renderHook } from "@testing-library/react";
|
|
2
|
-
import { describe, expect, it } from "vitest";
|
|
3
|
-
import { useZoomPan } from "../useZoomPan.js";
|
|
4
|
-
|
|
5
|
-
describe("useZoomPan", () => {
|
|
6
|
-
it("starts at scale 1 with zero translate", () => {
|
|
7
|
-
const { result } = renderHook(() => useZoomPan());
|
|
8
|
-
expect(result.current.state).toEqual({ scale: 1, translateX: 0, translateY: 0 });
|
|
9
|
-
});
|
|
10
|
-
|
|
11
|
-
it("zoomIn increases scale by step", () => {
|
|
12
|
-
const { result } = renderHook(() => useZoomPan({ zoomStep: 1.2 }));
|
|
13
|
-
act(() => result.current.zoomIn());
|
|
14
|
-
expect(result.current.state.scale).toBeCloseTo(1.2);
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
it("zoomOut decreases scale by step", () => {
|
|
18
|
-
const { result } = renderHook(() => useZoomPan({ zoomStep: 1.2 }));
|
|
19
|
-
act(() => result.current.zoomOut());
|
|
20
|
-
expect(result.current.state.scale).toBeCloseTo(1 / 1.2);
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
it("clamps scale at maxScale", () => {
|
|
24
|
-
const { result } = renderHook(() => useZoomPan({ maxScale: 2, zoomStep: 2 }));
|
|
25
|
-
act(() => result.current.zoomIn()); // 2
|
|
26
|
-
act(() => result.current.zoomIn()); // clamped to 2
|
|
27
|
-
expect(result.current.state.scale).toBe(2);
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
it("clamps scale at minScale", () => {
|
|
31
|
-
const { result } = renderHook(() => useZoomPan({ minScale: 0.5, zoomStep: 2 }));
|
|
32
|
-
act(() => result.current.zoomOut()); // 0.5
|
|
33
|
-
act(() => result.current.zoomOut()); // clamped to 0.5
|
|
34
|
-
expect(result.current.state.scale).toBe(0.5);
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
it("reset restores initial state", () => {
|
|
38
|
-
const { result } = renderHook(() => useZoomPan());
|
|
39
|
-
act(() => result.current.zoomIn());
|
|
40
|
-
act(() => result.current.zoomIn());
|
|
41
|
-
expect(result.current.state.scale).not.toBe(1);
|
|
42
|
-
act(() => result.current.reset());
|
|
43
|
-
expect(result.current.state).toEqual({ scale: 1, translateX: 0, translateY: 0 });
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
it("double-click resets state", () => {
|
|
47
|
-
const { result } = renderHook(() => useZoomPan());
|
|
48
|
-
act(() => result.current.zoomIn());
|
|
49
|
-
act(() => result.current.handlers.onDoubleClick());
|
|
50
|
-
expect(result.current.state).toEqual({ scale: 1, translateX: 0, translateY: 0 });
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
it("exposes all expected handler keys", () => {
|
|
54
|
-
const { result } = renderHook(() => useZoomPan());
|
|
55
|
-
const keys = Object.keys(result.current.handlers);
|
|
56
|
-
expect(keys).toContain("onWheel");
|
|
57
|
-
expect(keys).toContain("onPointerDown");
|
|
58
|
-
expect(keys).toContain("onPointerMove");
|
|
59
|
-
expect(keys).toContain("onPointerUp");
|
|
60
|
-
expect(keys).toContain("onTouchMove");
|
|
61
|
-
expect(keys).toContain("onTouchEnd");
|
|
62
|
-
expect(keys).toContain("onDoubleClick");
|
|
63
|
-
});
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
describe("useZoomPan click-vs-drag threshold", () => {
|
|
67
|
-
function makeTarget() {
|
|
68
|
-
let captures = 0;
|
|
69
|
-
const target = {
|
|
70
|
-
setPointerCapture: () => { captures += 1; },
|
|
71
|
-
releasePointerCapture: () => {},
|
|
72
|
-
};
|
|
73
|
-
return { target, captureCount: () => captures };
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
// A press+release with no movement must remain a click: no capture (which would
|
|
77
|
-
// steal the click from a child onClick), no translate.
|
|
78
|
-
it("tap with no movement: no capture, no translate", () => {
|
|
79
|
-
const { result } = renderHook(() => useZoomPan());
|
|
80
|
-
const { target, captureCount } = makeTarget();
|
|
81
|
-
act(() => {
|
|
82
|
-
result.current.handlers.onPointerDown({ button: 0, clientX: 50, clientY: 50, pointerId: 1, currentTarget: target } as never);
|
|
83
|
-
result.current.handlers.onPointerUp();
|
|
84
|
-
});
|
|
85
|
-
expect(captureCount()).toBe(0);
|
|
86
|
-
expect(result.current.state).toEqual({ scale: 1, translateX: 0, translateY: 0 });
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
it("movement at or below threshold (3px): no capture, no translate", () => {
|
|
90
|
-
const { result } = renderHook(() => useZoomPan());
|
|
91
|
-
const { target, captureCount } = makeTarget();
|
|
92
|
-
act(() => {
|
|
93
|
-
result.current.handlers.onPointerDown({ button: 0, clientX: 50, clientY: 50, pointerId: 1, currentTarget: target } as never);
|
|
94
|
-
result.current.handlers.onPointerMove({ clientX: 53, clientY: 50, pointerId: 1, currentTarget: target } as never);
|
|
95
|
-
});
|
|
96
|
-
expect(captureCount()).toBe(0);
|
|
97
|
-
expect(result.current.state.translateX).toBe(0);
|
|
98
|
-
expect(result.current.state.translateY).toBe(0);
|
|
99
|
-
});
|
|
100
|
-
|
|
101
|
-
it("movement beyond threshold: captures once and translates", () => {
|
|
102
|
-
const { result } = renderHook(() => useZoomPan());
|
|
103
|
-
const { target, captureCount } = makeTarget();
|
|
104
|
-
act(() => {
|
|
105
|
-
result.current.handlers.onPointerDown({ button: 0, clientX: 50, clientY: 50, pointerId: 1, currentTarget: target } as never);
|
|
106
|
-
result.current.handlers.onPointerMove({ clientX: 60, clientY: 50, pointerId: 1, currentTarget: target } as never);
|
|
107
|
-
});
|
|
108
|
-
expect(captureCount()).toBe(1);
|
|
109
|
-
expect(result.current.state.translateX).toBe(10);
|
|
110
|
-
// A further move keeps dragging without re-capturing.
|
|
111
|
-
act(() => {
|
|
112
|
-
result.current.handlers.onPointerMove({ clientX: 65, clientY: 50, pointerId: 1, currentTarget: target } as never);
|
|
113
|
-
});
|
|
114
|
-
expect(captureCount()).toBe(1);
|
|
115
|
-
expect(result.current.state.translateX).toBe(15);
|
|
116
|
-
});
|
|
117
|
-
|
|
118
|
-
it("non-primary button does not start a pending drag", () => {
|
|
119
|
-
const { result } = renderHook(() => useZoomPan());
|
|
120
|
-
const { target, captureCount } = makeTarget();
|
|
121
|
-
act(() => {
|
|
122
|
-
result.current.handlers.onPointerDown({ button: 2, clientX: 50, clientY: 50, pointerId: 1, currentTarget: target } as never);
|
|
123
|
-
result.current.handlers.onPointerMove({ clientX: 80, clientY: 50, pointerId: 1, currentTarget: target } as never);
|
|
124
|
-
});
|
|
125
|
-
expect(captureCount()).toBe(0);
|
|
126
|
-
expect(result.current.state.translateX).toBe(0);
|
|
127
|
-
});
|
|
128
|
-
});
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
# DOX — packages/client-utils/src/extension-ui
|
|
2
|
-
|
|
3
|
-
Files in this directory. One row per source file.
|
|
4
|
-
|
|
5
|
-
| File | Purpose |
|
|
6
|
-
|------|---------|
|
|
7
|
-
| `AgentMetricSlot.tsx` | Phase-2 `agent-metric` slot. Exports `AgentMetricSlot({ session, agentId })` — renders `kind: "agent-metric"` decorators matching `payload.agentId`, inside `FlowAgentCard`. Ignores unknown agentId. Uses `decoratorsOfKind`. |
|
|
8
|
-
| `BreadcrumbSlot.tsx` | Phase-2 `breadcrumb` slot. Exports `BreadcrumbSlot({ session })` — renders most-recently-cached `kind: "breadcrumb"` descriptor as step indicator at top of `FlowDashboard`. Last-write-wins on collision. Step status active/done/error/pending. Uses `decoratorsOfKind`. |
|
|
9
|
-
| `decorator-utils.ts` | Exports `decoratorsOfKind(decorators, kind)` — type-narrowing helper filtering `DashboardSession.uiDecorators` record by `DecoratorKind`. Shared by all Phase-2 decorator slot components (`AgentMetricSlot`, `BreadcrumbSlot`, `GateSlot`). |
|
|
10
|
-
| `GateSlot.tsx` | Phase-2 `gate` slot. Exports `GateSlot({ session, flowId })` + `aggregateGateState` pure helper. Most-restrictive-wins: any `available: false` for `flowId` blocks; reasons concatenated. Renders amber banner inside `FlowLaunchDialog`; `useGateState` disables Run button. |
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
# DOX — packages/client-utils/src/minimal-chat
|
|
2
|
-
|
|
3
|
-
Files in this directory. One row per source file.
|
|
4
|
-
|
|
5
|
-
| File | Purpose |
|
|
6
|
-
|------|---------|
|
|
7
|
-
| `index.ts` | Barrel for `./minimal-chat` subpath export. Re-exports `MinimalChatView`, `statusVisualsFor`, `extractInputPreview` from `MinimalChatView.js`; re-exports types `MinimalChatEntry`, `MinimalChatMeta`, `MinimalChatMode`, `MinimalChatStatus`, `MinimalChatViewProps` from `types.js`. Import path: `@blackbelt-technology/pi-dashboard-client-utils/minimal-chat`. |
|
|
8
|
-
| `MinimalChatView.tsx` | Shared subagent/agent timeline renderer. Exports `MinimalChatView` (props `MinimalChatViewProps`), `statusVisualsFor(status)` → `{ iconPath, colorClass }`, `extractInputPreview(toolName, input)` → preview string. Modes: `inline` (body `h-[60vh]`), `popout` (`h-full`), `row` (single-line, no body). Resolves `MarkdownContent`, `formatTokens`, `formatDuration`, `toolCallStep`, `thinkingBlock` via `useUiPrimitive`/`useUiPrimitiveOrNull`; falls back to inline renderers when primitive absent. Entry kinds: `tool`, `text`, `thinking`, `error`. Single source of truth replacing duplicated timeline UI in `SubagentDetailView` and `FlowAgentDetail`. Header renders `meta.cost` (pre-formatted string) between tokens and duration when present. See change: surface-flow-agent-cost. |
|
|
9
|
-
| `types.ts` | Type contracts for `MinimalChatView`. Exports `MinimalChatMode` (`"inline" | "popout" | "row"`), `MinimalChatStatus` (`"pending" | "running" | "complete" | "error" | "blocked"`), `MinimalChatEntry` (discriminated union `tool | text | thinking | error`), `MinimalChatMeta` (`modelName?`, `tokens?`, `cost?` pre-formatted USD string, `durationMs?`; see change surface-flow-agent-cost), `MinimalChatViewProps`. Producer adapters map plugin-specific state into these structural types at shim boundary. |
|