File tree 2 files changed +21
-4
lines changed
2 files changed +21
-4
lines changed Original file line number Diff line number Diff line change
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
+ } )
Original file line number Diff line number Diff line change 1
- import type React from "react"
2
- import { IconButton , type IconButtonProps } from "@mui/material"
3
1
import { ContentCopy as ContentCopyIcon } from "@mui/icons-material"
2
+ import { IconButton , type IconButtonProps } from "@mui/material"
3
+ import type { FC } from "react"
4
4
5
5
export interface CopyIconButtonProps extends Omit < IconButtonProps , "onClick" > {
6
6
content : string
7
7
}
8
8
9
- const CopyIconButton : React . FC < CopyIconButtonProps > = ( {
9
+ const CopyIconButton : FC < CopyIconButtonProps > = ( {
10
10
content,
11
11
children = < ContentCopyIcon /> ,
12
12
...otherIconButtonProps
13
13
} ) => {
14
14
return (
15
15
< IconButton
16
+ data-testid = "copy-icon-button"
16
17
onClick = { ( ) => {
17
- void navigator . clipboard . writeText ( content )
18
+ navigator . clipboard . writeText ( content )
18
19
} }
19
20
{ ...otherIconButtonProps }
20
21
>
You can’t perform that action at this time.
0 commit comments