Skip to content

Commit f32903d

Browse files
committed
fix: test
1 parent eab4e39 commit f32903d

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed
+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { screen } from "@testing-library/react"
2+
3+
import { renderWithUser } from "../helpers/test"
4+
import CopyIconButton from "./CopyIconButton"
5+
6+
test("Clicking button should copy content", async () => {
7+
const content = "Example string to be copied."
8+
9+
const { user } = renderWithUser(<CopyIconButton content={content} />)
10+
11+
expect(await navigator.clipboard.readText()).toEqual("")
12+
13+
await user.click(screen.getByTestId("copy-icon-button"))
14+
15+
expect(await navigator.clipboard.readText()).toEqual(content)
16+
})

src/components/CopyIconButton.tsx

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,21 @@
1-
import type React from "react"
2-
import { IconButton, type IconButtonProps } from "@mui/material"
31
import { ContentCopy as ContentCopyIcon } from "@mui/icons-material"
2+
import { IconButton, type IconButtonProps } from "@mui/material"
3+
import type { FC } from "react"
44

55
export interface CopyIconButtonProps extends Omit<IconButtonProps, "onClick"> {
66
content: string
77
}
88

9-
const CopyIconButton: React.FC<CopyIconButtonProps> = ({
9+
const CopyIconButton: FC<CopyIconButtonProps> = ({
1010
content,
1111
children = <ContentCopyIcon />,
1212
...otherIconButtonProps
1313
}) => {
1414
return (
1515
<IconButton
16+
data-testid="copy-icon-button"
1617
onClick={() => {
17-
void navigator.clipboard.writeText(content)
18+
navigator.clipboard.writeText(content)
1819
}}
1920
{...otherIconButtonProps}
2021
>

0 commit comments

Comments
 (0)