Skip to content
This repository was archived by the owner on Jul 8, 2025. It is now read-only.

Commit 92a0411

Browse files
committed
test: add CopyToClipboard
1 parent b9bc1ec commit 92a0411

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

src/components/CopyToClipboard.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export function CopyToClipboard({
2727
className,
2828
)}
2929
>
30-
<ClipboardCopy className="w-5 h-5 text-gray-200" />
30+
<ClipboardCopy role="img" className="w-5 h-5 text-gray-200" />
3131
</button>
3232
);
3333
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { render, screen } from "@testing-library/react";
2+
import userEvent from "@testing-library/user-event";
3+
import { describe, it, vi, expect } from "vitest";
4+
import { CopyToClipboard } from "../CopyToClipboard";
5+
6+
describe("CopyToClipboard", () => {
7+
it("renders the button with the correct icon", () => {
8+
render(<CopyToClipboard text="Fake text" />);
9+
10+
expect(screen.getByRole("button")).toBeVisible();
11+
expect(screen.getByRole("img", { hidden: true })).toBeVisible();
12+
});
13+
14+
it("copies text to clipboard when clicked", async () => {
15+
const mockedText = vi.fn();
16+
Object.assign(navigator, {
17+
clipboard: {
18+
writeText: mockedText,
19+
},
20+
});
21+
22+
render(<CopyToClipboard text="Fake text" />);
23+
24+
await userEvent.click(screen.getByRole("button"));
25+
26+
expect(mockedText).toHaveBeenCalledWith("Fake text");
27+
});
28+
});

0 commit comments

Comments
 (0)