Skip to content

Commit 9d4f904

Browse files
committed
Increase test coverage from 92.33% to 92.69%
1 parent f87ec1c commit 9d4f904

File tree

5 files changed

+74
-1
lines changed

5 files changed

+74
-1
lines changed

packages/elements/__tests__/artifact.test.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,11 @@ describe("ArtifactAction", () => {
8484
expect(screen.getByText("Action")).toHaveClass("sr-only");
8585
});
8686

87+
it("renders with tooltip only (no label)", () => {
88+
render(<ArtifactAction tooltip="Help text">Content</ArtifactAction>);
89+
expect(screen.getByText("Help text")).toHaveClass("sr-only");
90+
});
91+
8792
it("renders children when no icon", () => {
8893
render(<ArtifactAction label="Custom">Content</ArtifactAction>);
8994
expect(screen.getByText("Content")).toBeInTheDocument();

packages/elements/__tests__/chain-of-thought.test.tsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,17 @@ describe("ChainOfThought", () => {
1818
expect(screen.getByText("Content")).toBeInTheDocument();
1919
});
2020

21+
it("throws error when component used outside provider", () => {
22+
// Suppress console.error for this test
23+
const spy = vi.spyOn(console, "error").mockImplementation(() => {});
24+
25+
expect(() => render(<ChainOfThoughtHeader>Test</ChainOfThoughtHeader>)).toThrow(
26+
"ChainOfThought components must be used within ChainOfThought"
27+
);
28+
29+
spy.mockRestore();
30+
});
31+
2132
it("starts closed by default", () => {
2233
render(
2334
<ChainOfThought>

packages/elements/__tests__/code-block.test.tsx

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,4 +112,39 @@ describe("CodeBlockCopyButton", () => {
112112
expect(onError).toHaveBeenCalledWith(error);
113113
});
114114
});
115+
116+
it("calls onError when clipboard API is not available", async () => {
117+
const onError = vi.fn();
118+
const user = userEvent.setup();
119+
120+
// Temporarily remove clipboard writeText method
121+
const originalClipboard = navigator.clipboard;
122+
Object.defineProperty(navigator, "clipboard", {
123+
value: { writeText: undefined },
124+
writable: true,
125+
configurable: true,
126+
});
127+
128+
render(
129+
<CodeBlock code="test code" language="javascript">
130+
<CodeBlockCopyButton onError={onError} />
131+
</CodeBlock>
132+
);
133+
134+
const button = screen.getByRole("button");
135+
await user.click(button);
136+
137+
expect(onError).toHaveBeenCalledWith(
138+
expect.objectContaining({
139+
message: "Clipboard API not available",
140+
})
141+
);
142+
143+
// Restore clipboard API
144+
Object.defineProperty(navigator, "clipboard", {
145+
value: originalClipboard,
146+
writable: true,
147+
configurable: true,
148+
});
149+
});
115150
});

packages/elements/__tests__/open-in-chat.test.tsx

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { render, screen } from "@testing-library/react";
2-
import { describe, expect, it } from "vitest";
2+
import { describe, expect, it, vi } from "vitest";
33
import {
44
OpenIn,
55
OpenInChatGPT,
@@ -25,6 +25,17 @@ describe("OpenIn", () => {
2525
);
2626
expect(screen.getByText("Content")).toBeInTheDocument();
2727
});
28+
29+
it("throws error when component used outside provider", () => {
30+
// Suppress console.error for this test
31+
const spy = vi.spyOn(console, "error").mockImplementation(() => {});
32+
33+
expect(() => render(<OpenInChatGPT />)).toThrow(
34+
"OpenIn components must be used within an OpenIn provider"
35+
);
36+
37+
spy.mockRestore();
38+
});
2839
});
2940

3041
describe("OpenInTrigger", () => {

packages/elements/__tests__/web-preview.test.tsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,17 @@ describe("WebPreview", () => {
4141

4242
expect(onUrlChange).toHaveBeenCalled();
4343
});
44+
45+
it("throws error when component used outside provider", () => {
46+
// Suppress console.error for this test
47+
const spy = vi.spyOn(console, "error").mockImplementation(() => {});
48+
49+
expect(() => render(<WebPreviewUrl />)).toThrow(
50+
"WebPreview components must be used within a WebPreview"
51+
);
52+
53+
spy.mockRestore();
54+
});
4455
});
4556

4657
describe("WebPreviewNavigation", () => {

0 commit comments

Comments
 (0)