@niwa-labs/ui-kit 0.0.0-stage → 0.0.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/LICENSE +21 -0
- package/README.md +29 -2
- package/package.json +31 -4
- package/src/agent/diff-view.tsx +62 -0
- package/src/agent/execution-track.tsx +201 -0
- package/src/agent/guard.ts +121 -0
- package/src/agent/guarded-action.tsx +272 -0
- package/src/agent/id-chip.tsx +102 -0
- package/src/agent/markdown.tsx +34 -0
- package/src/agent/payload.ts +42 -0
- package/src/agent/phase-plan.tsx +183 -0
- package/src/agent/plan-impact.ts +104 -0
- package/src/agent/state.tsx +75 -0
- package/src/agent/tool-call.tsx +106 -0
- package/src/agent/transcript.tsx +88 -0
- package/src/execution-track.css +327 -0
- package/src/index.ts +76 -0
- package/src/lib/cn.ts +19 -0
- package/src/page-layout.css +183 -0
- package/src/theme.css +136 -0
- package/src/ui/badge.tsx +32 -0
- package/src/ui/button.tsx +38 -0
- package/src/ui/collapsible.tsx +13 -0
- package/src/ui/data-value.tsx +211 -0
- package/src/ui/message.tsx +81 -0
- package/src/ui/page-layout.tsx +33 -0
- package/src/ui/schema-view.tsx +144 -0
- package/src/ui/spinner.tsx +16 -0
- package/src/ui/tabs.tsx +63 -0
- package/src/ui/tooltip.tsx +50 -0
- package/src/ui/trace.tsx +100 -0
- package/test/browser.test.ts +13 -0
- package/test/diff-view.test.tsx +50 -0
- package/test/guard.test.ts +113 -0
- package/test/guarded-action.test.tsx +229 -0
- package/test/helpers.test.ts +83 -0
- package/test/phase-plan.test.tsx +146 -0
- package/test/plan.test.ts +71 -0
- package/test/render.test.tsx +62 -0
- package/test/structured-values.test.tsx +31 -0
- package/test/tabs.test.tsx +90 -0
- package/tsconfig.json +16 -0
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
// A phase plan in a document, as its phases change state while the run goes on.
|
|
2
|
+
|
|
3
|
+
import { GlobalRegistrator } from "@happy-dom/global-registrator";
|
|
4
|
+
import { afterAll, beforeAll, expect, spyOn, test } from "bun:test";
|
|
5
|
+
import { act } from "react";
|
|
6
|
+
import { createRoot } from "react-dom/client";
|
|
7
|
+
|
|
8
|
+
import { PhasePlan, TooltipProvider, type PhasePlanPhase } from "../src/index.ts";
|
|
9
|
+
|
|
10
|
+
declare global {
|
|
11
|
+
var IS_REACT_ACT_ENVIRONMENT: boolean | undefined;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
beforeAll(() => {
|
|
15
|
+
GlobalRegistrator.register();
|
|
16
|
+
globalThis.IS_REACT_ACT_ENVIRONMENT = true;
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
afterAll(async () => {
|
|
20
|
+
globalThis.IS_REACT_ACT_ENVIRONMENT = undefined;
|
|
21
|
+
await GlobalRegistrator.unregister();
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
const phase = (state: PhasePlanPhase["state"]): PhasePlanPhase => ({ id: "build", title: "Build", state, steps: [{ id: "s", title: "Compile", state: state === "running" ? "running" : "done" }] });
|
|
25
|
+
|
|
26
|
+
test("a phase that settles while it is shown does not make its panel complain about a changed default", async () => {
|
|
27
|
+
const complaints = spyOn(console, "error").mockImplementation(() => {});
|
|
28
|
+
const host = document.createElement("div");
|
|
29
|
+
document.body.append(host);
|
|
30
|
+
const root = createRoot(host);
|
|
31
|
+
const plan = (state: PhasePlanPhase["state"]) => (
|
|
32
|
+
<TooltipProvider>
|
|
33
|
+
<PhasePlan phases={[phase(state)]} />
|
|
34
|
+
</TooltipProvider>
|
|
35
|
+
);
|
|
36
|
+
await act(async () => root.render(plan("running")));
|
|
37
|
+
await act(async () => root.render(plan("done")));
|
|
38
|
+
expect(complaints.mock.calls.map((call) => String(call[0]))).toEqual([]);
|
|
39
|
+
complaints.mockRestore();
|
|
40
|
+
await act(async () => root.unmount());
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
test("a phase is open while it runs, and the one who closed it keeps it closed when it settles", async () => {
|
|
44
|
+
const host = document.createElement("div");
|
|
45
|
+
document.body.append(host);
|
|
46
|
+
const root = createRoot(host);
|
|
47
|
+
const plan = (state: PhasePlanPhase["state"]) => (
|
|
48
|
+
<TooltipProvider>
|
|
49
|
+
<PhasePlan phases={[phase(state)]} />
|
|
50
|
+
</TooltipProvider>
|
|
51
|
+
);
|
|
52
|
+
const expanded = (): string | null => host.querySelector('[data-slot="collapsible-trigger"]')!.getAttribute("aria-expanded");
|
|
53
|
+
await act(async () => root.render(plan("running")));
|
|
54
|
+
expect(expanded()).toBe("true");
|
|
55
|
+
await act(async () => host.querySelector<HTMLElement>('[data-slot="plan-phase"] button')!.click());
|
|
56
|
+
expect(expanded()).toBe("false");
|
|
57
|
+
await act(async () => root.render(plan("done")));
|
|
58
|
+
expect(expanded()).toBe("false");
|
|
59
|
+
await act(async () => root.unmount());
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
test("a phase that settles closes by itself when nobody chose", async () => {
|
|
63
|
+
const host = document.createElement("div");
|
|
64
|
+
document.body.append(host);
|
|
65
|
+
const root = createRoot(host);
|
|
66
|
+
const plan = (state: PhasePlanPhase["state"]) => (
|
|
67
|
+
<TooltipProvider>
|
|
68
|
+
<PhasePlan phases={[phase(state)]} />
|
|
69
|
+
</TooltipProvider>
|
|
70
|
+
);
|
|
71
|
+
await act(async () => root.render(plan("running")));
|
|
72
|
+
await act(async () => root.render(plan("done")));
|
|
73
|
+
expect(host.querySelector('[data-slot="collapsible-trigger"]')!.getAttribute("aria-expanded")).toBe("false");
|
|
74
|
+
await act(async () => root.unmount());
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
test("an explanation is worked out only for the control that shows it", async () => {
|
|
78
|
+
const asked: string[] = [];
|
|
79
|
+
const host = document.createElement("div");
|
|
80
|
+
document.body.append(host);
|
|
81
|
+
const root = createRoot(host);
|
|
82
|
+
const phases: PhasePlanPhase[] = [
|
|
83
|
+
{
|
|
84
|
+
id: "build",
|
|
85
|
+
title: "Build",
|
|
86
|
+
state: "running",
|
|
87
|
+
steps: [
|
|
88
|
+
{ id: "a", title: "A", state: "done" },
|
|
89
|
+
{ id: "b", title: "B", state: "done" },
|
|
90
|
+
],
|
|
91
|
+
},
|
|
92
|
+
];
|
|
93
|
+
await act(async () =>
|
|
94
|
+
root.render(
|
|
95
|
+
<TooltipProvider>
|
|
96
|
+
<PhasePlan
|
|
97
|
+
phases={phases}
|
|
98
|
+
onRecompute={() => {}}
|
|
99
|
+
onStop={() => {}}
|
|
100
|
+
explainRecompute={(target) => {
|
|
101
|
+
asked.push(`recompute ${target.step ?? target.phase}`);
|
|
102
|
+
return "explained";
|
|
103
|
+
}}
|
|
104
|
+
explainStop={(target) => {
|
|
105
|
+
asked.push(`stop ${target.step ?? target.phase}`);
|
|
106
|
+
return "explained";
|
|
107
|
+
}}
|
|
108
|
+
/>
|
|
109
|
+
</TooltipProvider>,
|
|
110
|
+
),
|
|
111
|
+
);
|
|
112
|
+
expect(asked).toEqual([]);
|
|
113
|
+
const first = host.querySelector<HTMLElement>('[data-slot="plan-step"] [data-slot="guard-button"]')!;
|
|
114
|
+
await act(async () => {
|
|
115
|
+
first.dispatchEvent(new MouseEvent("click", { bubbles: true, detail: 0 }));
|
|
116
|
+
});
|
|
117
|
+
expect(asked.length).toBeGreaterThan(0);
|
|
118
|
+
expect(new Set(asked)).toEqual(new Set(["recompute a"]));
|
|
119
|
+
expect(host.textContent).toContain("explained");
|
|
120
|
+
await act(async () => root.unmount());
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
test("arming a completed action warns before an external change can be repeated", async () => {
|
|
124
|
+
const host = document.createElement("div");
|
|
125
|
+
document.body.append(host);
|
|
126
|
+
const root = createRoot(host);
|
|
127
|
+
let confirmed = false;
|
|
128
|
+
try {
|
|
129
|
+
await act(async () => root.render(
|
|
130
|
+
<TooltipProvider>
|
|
131
|
+
<PhasePlan phases={[{ id: "ship", title: "Ship", state: "running", steps: [
|
|
132
|
+
{ id: "publish", title: "Publish", state: "done" },
|
|
133
|
+
] }]} onRecompute={() => { confirmed = true; }} />
|
|
134
|
+
</TooltipProvider>,
|
|
135
|
+
));
|
|
136
|
+
const control = host.querySelector<HTMLElement>('[data-slot="plan-step"] [data-slot="guard-button"]')!;
|
|
137
|
+
await act(async () => {
|
|
138
|
+
control.dispatchEvent(new MouseEvent("click", { bubbles: true, detail: 0 }));
|
|
139
|
+
});
|
|
140
|
+
expect(host.querySelector('[data-slot="guard-notice"]')?.textContent).toContain("external changes may be repeated");
|
|
141
|
+
expect(confirmed).toBe(false);
|
|
142
|
+
} finally {
|
|
143
|
+
await act(async () => root.unmount());
|
|
144
|
+
host.remove();
|
|
145
|
+
}
|
|
146
|
+
});
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { describe, expect, test } from "bun:test";
|
|
2
|
+
|
|
3
|
+
import { describeRecompute, describeStop, recomputeImpact, stopImpact, type PlanPhase } from "../src/index.ts";
|
|
4
|
+
|
|
5
|
+
const plan: PlanPhase[] = [
|
|
6
|
+
{
|
|
7
|
+
id: "prepare",
|
|
8
|
+
title: "Prepare",
|
|
9
|
+
state: "done",
|
|
10
|
+
steps: [
|
|
11
|
+
{ id: "fetch", title: "Fetch sources", state: "done" },
|
|
12
|
+
{ id: "lint", title: "Lint", state: "skipped" },
|
|
13
|
+
],
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
id: "build",
|
|
17
|
+
title: "Build",
|
|
18
|
+
state: "running",
|
|
19
|
+
steps: [
|
|
20
|
+
{ id: "compile", title: "Compile", state: "done" },
|
|
21
|
+
{ id: "notify", title: "Notify the channel", state: "done", effect: true },
|
|
22
|
+
{ id: "test", title: "Test", state: "running" },
|
|
23
|
+
],
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
id: "ship",
|
|
27
|
+
title: "Ship",
|
|
28
|
+
state: "pending",
|
|
29
|
+
steps: [
|
|
30
|
+
{ id: "push", title: "Push", state: "pending", effect: true },
|
|
31
|
+
{ id: "announce", title: "Announce", state: "pending" },
|
|
32
|
+
],
|
|
33
|
+
},
|
|
34
|
+
];
|
|
35
|
+
|
|
36
|
+
describe("recompute impact", () => {
|
|
37
|
+
test("selecting a completed send warns about redelivery", () => {
|
|
38
|
+
const target = { phase: "build", step: "notify" };
|
|
39
|
+
expect(recomputeImpact(plan, target)).toEqual({ selected: 1, flagged: 1 });
|
|
40
|
+
expect(describeRecompute(plan, target)).toContain("Previously sent messages or other external changes may be repeated.");
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
test("a phase counts its recorded steps without forecasting later branches", () => {
|
|
44
|
+
expect(recomputeImpact(plan, { phase: "build" })).toEqual({ selected: 3, flagged: 1 });
|
|
45
|
+
expect(describeRecompute(plan, { phase: "build" })).toContain("3 steps in this phase");
|
|
46
|
+
expect(recomputeImpact(plan, { phase: "build", step: "compile" })).toEqual({ selected: 1, flagged: 0 });
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
test("missing effect metadata and a failed send both retain the external-effect warning", () => {
|
|
50
|
+
for (const effect of [true, undefined]) {
|
|
51
|
+
const phases: PlanPhase[] = [{ id: "p", title: "Send", state: "failed", steps: [{ id: "send", title: "Send", state: "failed", effect }] }];
|
|
52
|
+
expect(describeRecompute(phases, { phase: "p", step: "send" })).toContain("external changes may be repeated");
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
test("an unknown selection has no recorded steps", () => {
|
|
57
|
+
expect(recomputeImpact(plan, { phase: "nope" })).toEqual({ selected: 0, flagged: 0 });
|
|
58
|
+
});
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
describe("stop impact", () => {
|
|
62
|
+
test("stopping a phase stops what runs in it and keeps later steps from starting", () => {
|
|
63
|
+
expect(stopImpact(plan, { phase: "build" })).toEqual({ stopping: 1, notStarting: 2 });
|
|
64
|
+
expect(describeStop(plan, { phase: "build" })).toBe("Stop “Build”: 1 step running stop, 2 steps will not start.");
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
test("stopping a step that does not run only keeps the pending ones from starting", () => {
|
|
68
|
+
expect(stopImpact(plan, { phase: "ship", step: "push" })).toEqual({ stopping: 0, notStarting: 2 });
|
|
69
|
+
expect(describeStop(plan, { phase: "ship", step: "push" })).toBe("Stop “Push”: 2 steps will not start.");
|
|
70
|
+
});
|
|
71
|
+
});
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
// Server rendering checks the markup the components produce without a browser.
|
|
2
|
+
|
|
3
|
+
import { describe, expect, test } from "bun:test";
|
|
4
|
+
import { renderToString } from "react-dom/server";
|
|
5
|
+
|
|
6
|
+
import { IdChip, PhasePlan, StateRing, ToolCall, TooltipProvider, type PhasePlanPhase } from "../src/index.ts";
|
|
7
|
+
|
|
8
|
+
const phases: PhasePlanPhase[] = [
|
|
9
|
+
{
|
|
10
|
+
id: "build",
|
|
11
|
+
title: "Build",
|
|
12
|
+
state: "running",
|
|
13
|
+
steps: [
|
|
14
|
+
{ id: "compile", title: "Compile", state: "done", meta: "4.2s" },
|
|
15
|
+
{ id: "test", title: "Test", state: "running" },
|
|
16
|
+
{ id: "ship", title: "Ship", state: "pending" },
|
|
17
|
+
],
|
|
18
|
+
},
|
|
19
|
+
];
|
|
20
|
+
|
|
21
|
+
describe("rendering", () => {
|
|
22
|
+
test("a phase plan shows recompute on settled steps and stop on running ones", () => {
|
|
23
|
+
const html = renderToString(
|
|
24
|
+
<TooltipProvider>
|
|
25
|
+
<PhasePlan phases={phases} onRecompute={() => {}} onStop={() => {}} />
|
|
26
|
+
</TooltipProvider>,
|
|
27
|
+
);
|
|
28
|
+
expect(html).toContain('data-slot="phase-plan"');
|
|
29
|
+
expect(html.match(/aria-label="Recompute from here"/g)?.length).toBe(1);
|
|
30
|
+
// The phase and the running step can be stopped.
|
|
31
|
+
expect(html.match(/aria-label="Stop"/g)?.length).toBe(2);
|
|
32
|
+
expect(html).not.toContain('data-slot="guard-notice"');
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
test("without handlers a plan has no controls", () => {
|
|
36
|
+
const html = renderToString(<PhasePlan phases={phases} />);
|
|
37
|
+
expect(html).not.toContain("guard-button");
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
test("a tool call shows its name, state and duration", () => {
|
|
41
|
+
const html = renderToString(<ToolCall name="bash" state="done" durationMs={1200} input="ls" output="a\nb" />);
|
|
42
|
+
expect(html).toContain('data-tool="bash"');
|
|
43
|
+
expect(html).toContain("1.2s");
|
|
44
|
+
expect(html).toContain('aria-label="Done"');
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
test("an id chip links only when given a target", () => {
|
|
48
|
+
expect(renderToString(<IdChip id="run-1f3a9c" />)).not.toContain("<a");
|
|
49
|
+
expect(renderToString(<IdChip id="run-1f3a9c" href="/runs/run-1f3a9c" />)).toContain('href="/runs/run-1f3a9c"');
|
|
50
|
+
expect(renderToString(<StateRing state="waiting" label="Waiting for the owner" />)).toContain(
|
|
51
|
+
'aria-label="Waiting for the owner"',
|
|
52
|
+
);
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
test("the copy button stays in the tab order and is only faded until hover or focus", () => {
|
|
56
|
+
const html = renderToString(<IdChip id="run-1f3a9c" />);
|
|
57
|
+
const button = /<button[^>]*>/.exec(html)![0];
|
|
58
|
+
expect(button).toContain("opacity-0");
|
|
59
|
+
expect(button).toContain("focus-visible:opacity-100");
|
|
60
|
+
expect(button).not.toMatch(/class="[^"]*\bhidden\b/);
|
|
61
|
+
});
|
|
62
|
+
});
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { expect, test } from "bun:test";
|
|
2
|
+
import { renderToStaticMarkup } from "react-dom/server";
|
|
3
|
+
import { DataValue, FileRef, SchemaView } from "../src/index.ts";
|
|
4
|
+
|
|
5
|
+
test("stored JSON strings and nested results render as labelled values", () => {
|
|
6
|
+
const view = renderToStaticMarkup(<DataValue value={{ result: '{"answer":"готово","count":2,"ok":true}' }} />);
|
|
7
|
+
expect(view).toContain("<dt");
|
|
8
|
+
for (const text of ["Результат", "Ответ", "готово", "Да"]) expect(view).toContain(text);
|
|
9
|
+
expect(view).not.toContain(""answer"");
|
|
10
|
+
expect(view).not.toContain("[object Object]");
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
test("paths use the basename and keep the original clipboard value", () => {
|
|
14
|
+
const view = renderToStaticMarkup(<FileRef path="/work/qa/scripts/review.ts" />);
|
|
15
|
+
expect(view).toContain("<b>review.ts</b>");
|
|
16
|
+
expect(view).toContain('title="/work/qa/scripts/review.ts"');
|
|
17
|
+
expect(view).toContain("qa/scripts/");
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
test("workflow inputs expose the required fields, references, defaults and constraints", () => {
|
|
21
|
+
const schema = {
|
|
22
|
+
type: "object",
|
|
23
|
+
properties: { branch: { type: "string", default: "main", minLength: 1 }, repo: { $ref: "#/$defs/repo" } },
|
|
24
|
+
required: ["repo"],
|
|
25
|
+
$defs: { repo: { type: "object", properties: { path: { type: "string", description: "Local clone" } } } },
|
|
26
|
+
};
|
|
27
|
+
const view = renderToStaticMarkup(<SchemaView schema={schema} />);
|
|
28
|
+
for (const text of ["branch", "По умолчанию", "main", "Обязательно", "path", "Local clone", "Мин. символов"])
|
|
29
|
+
expect(view).toContain(text);
|
|
30
|
+
expect(view).not.toContain("minLength");
|
|
31
|
+
});
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
// Tabs in a document: orientation reaches the primitive, and a className function is honoured.
|
|
2
|
+
|
|
3
|
+
import { GlobalRegistrator } from "@happy-dom/global-registrator";
|
|
4
|
+
import { afterAll, beforeAll, describe, expect, test } from "bun:test";
|
|
5
|
+
import { act } from "react";
|
|
6
|
+
import { createRoot } from "react-dom/client";
|
|
7
|
+
|
|
8
|
+
import { cnWith, Tabs, TabsContent, TabsList, TabsTrigger } from "../src/index.ts";
|
|
9
|
+
|
|
10
|
+
declare global {
|
|
11
|
+
var IS_REACT_ACT_ENVIRONMENT: boolean | undefined;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
beforeAll(() => {
|
|
15
|
+
GlobalRegistrator.register();
|
|
16
|
+
globalThis.IS_REACT_ACT_ENVIRONMENT = true;
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
afterAll(async () => {
|
|
20
|
+
globalThis.IS_REACT_ACT_ENVIRONMENT = undefined;
|
|
21
|
+
await GlobalRegistrator.unregister();
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
async function mount(element: React.ReactElement) {
|
|
25
|
+
const host = document.createElement("div");
|
|
26
|
+
document.body.append(host);
|
|
27
|
+
const root = createRoot(host);
|
|
28
|
+
await act(async () => root.render(element));
|
|
29
|
+
return { host, root };
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
describe("tabs", () => {
|
|
33
|
+
test("a vertical set is vertical for the list and the tabs", async () => {
|
|
34
|
+
const { host, root } = await mount(
|
|
35
|
+
<Tabs orientation="vertical" defaultValue="a">
|
|
36
|
+
<TabsList>
|
|
37
|
+
<TabsTrigger value="a">A</TabsTrigger>
|
|
38
|
+
<TabsTrigger value="b">B</TabsTrigger>
|
|
39
|
+
</TabsList>
|
|
40
|
+
<TabsContent value="a">first</TabsContent>
|
|
41
|
+
<TabsContent value="b">second</TabsContent>
|
|
42
|
+
</Tabs>,
|
|
43
|
+
);
|
|
44
|
+
expect(host.querySelector('[data-slot="tabs"]')?.getAttribute("data-orientation")).toBe("vertical");
|
|
45
|
+
const list = host.querySelector<HTMLElement>('[data-slot="tabs-list"]')!;
|
|
46
|
+
expect(list.getAttribute("aria-orientation")).toBe("vertical");
|
|
47
|
+
expect(list.getAttribute("data-orientation")).toBe("vertical");
|
|
48
|
+
// The tabs follow the root: arrow keys move along the vertical axis, and the styles bind to it.
|
|
49
|
+
for (const tab of host.querySelectorAll('[data-slot="tabs-trigger"]')) {
|
|
50
|
+
expect(tab.getAttribute("data-orientation")).toBe("vertical");
|
|
51
|
+
}
|
|
52
|
+
await act(async () => root.unmount());
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
test("a className function receives the state and is merged with the base classes", async () => {
|
|
56
|
+
const seen: (string | undefined)[] = [];
|
|
57
|
+
const { host, root } = await mount(
|
|
58
|
+
<Tabs
|
|
59
|
+
defaultValue="a"
|
|
60
|
+
className={(state) => {
|
|
61
|
+
seen.push(state.orientation);
|
|
62
|
+
return "extra";
|
|
63
|
+
}}
|
|
64
|
+
>
|
|
65
|
+
<TabsList className={() => "list-extra"}>
|
|
66
|
+
<TabsTrigger value="a" className={(state) => (state.active ? "tab-active" : "tab-idle")}>
|
|
67
|
+
A
|
|
68
|
+
</TabsTrigger>
|
|
69
|
+
</TabsList>
|
|
70
|
+
</Tabs>,
|
|
71
|
+
);
|
|
72
|
+
expect(seen).toContain("horizontal");
|
|
73
|
+
const rootClass = host.querySelector('[data-slot="tabs"]')?.className ?? "";
|
|
74
|
+
expect(rootClass).toContain("extra");
|
|
75
|
+
expect(rootClass).toContain("group/tabs");
|
|
76
|
+
expect(host.querySelector('[data-slot="tabs-list"]')?.className).toContain("list-extra");
|
|
77
|
+
expect(host.querySelector('[data-slot="tabs-trigger"]')?.className).toContain("tab-active");
|
|
78
|
+
await act(async () => root.unmount());
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
describe("cnWith", () => {
|
|
83
|
+
test("a string merges at once, a function when it gets its state", () => {
|
|
84
|
+
expect(cnWith("p-2", "p-4")).toBe("p-4");
|
|
85
|
+
const merged = cnWith<{ n: number }>("p-2", (state) => `p-${String(state.n)}`);
|
|
86
|
+
expect(typeof merged).toBe("function");
|
|
87
|
+
expect(typeof merged === "function" ? merged({ n: 6 }) : "").toBe("p-6");
|
|
88
|
+
expect(cnWith("p-2", undefined)).toBe("p-2");
|
|
89
|
+
});
|
|
90
|
+
});
|