-
-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathExpandableSummary.test.tsx
More file actions
59 lines (51 loc) · 2.07 KB
/
ExpandableSummary.test.tsx
File metadata and controls
59 lines (51 loc) · 2.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import { renderToStaticMarkup } from "react-dom/server";
import { describe, expect, it } from "vitest";
import { ExpandableSummary } from "./ExpandableSummary";
describe("ExpandableSummary", () => {
it("renders inline text by default when no children are provided", () => {
const html = renderToStaticMarkup(
<ExpandableSummary text="This is an AI summary that is long enough to be expandable and interesting." />,
);
expect(html).toContain(
"This is an AI summary that is long enough to be expandable and interesting.",
);
});
it("renders custom children when provided", () => {
const html = renderToStaticMarkup(
<ExpandableSummary text="Raw text here">
<span className="custom">Custom inline render</span>
</ExpandableSummary>,
);
expect(html).toContain("Custom inline render");
expect(html).toContain("custom");
});
it("shows the expand button for text longer than 40 characters", () => {
const html = renderToStaticMarkup(
<ExpandableSummary text="This is definitely long enough to warrant an expand button for the user." />,
);
expect(html).toContain("Expand summary");
});
it("hides the expand button for very short text", () => {
const html = renderToStaticMarkup(<ExpandableSummary text="Short." />);
expect(html).not.toContain("Expand summary");
});
it("hides the expand button for whitespace-only text", () => {
const html = renderToStaticMarkup(<ExpandableSummary text=" " />);
expect(html).not.toContain("Expand summary");
});
it("applies the group/expand class for hover interaction", () => {
const html = renderToStaticMarkup(
<ExpandableSummary text="A sufficiently long expandable AI response summary text." />,
);
expect(html).toContain("group/expand");
});
it("passes className to the wrapper div", () => {
const html = renderToStaticMarkup(
<ExpandableSummary
className="mt-3"
text="Another long expandable text for testing className."
/>,
);
expect(html).toContain("mt-3");
});
});