File tree Expand file tree Collapse file tree 3 files changed +18
-18
lines changed Expand file tree Collapse file tree 3 files changed +18
-18
lines changed Original file line number Diff line number Diff line change 1
1
import { fireEvent , render , screen } from "@testing-library/react" ;
2
2
import QuestionImage from "." ;
3
3
4
- Object . assign ( navigator , {
5
- clipboard : {
6
- writeText : jest . fn ( ) ,
7
- } ,
8
- } ) ;
9
-
10
4
describe ( "Question Image" , ( ) => {
11
5
const url = "https://example.com/image.jpg" ;
12
6
const mockHandleClickOpen = jest . fn ( ) ;
@@ -15,19 +9,23 @@ describe("Question Image", () => {
15
9
render ( < QuestionImage url = { url } handleClickOpen = { mockHandleClickOpen } /> ) ;
16
10
17
11
const image = screen . getByAltText ( "question image" ) ;
18
-
19
12
expect ( image ) . toBeInTheDocument ( ) ;
20
13
} ) ;
21
14
22
15
it ( "Copy Question Image url" , ( ) => {
16
+ const promptSpy = jest . spyOn ( window , "prompt" ) . mockImplementation ( ( ) => "" ) ;
17
+
23
18
render ( < QuestionImage url = { url } handleClickOpen = { mockHandleClickOpen } /> ) ;
24
19
25
20
const copyButton = screen . getByLabelText ( "copy" ) ;
26
21
fireEvent . click ( copyButton ) ;
27
22
28
- expect ( navigator . clipboard . writeText ) . toHaveBeenCalledWith (
23
+ expect ( promptSpy ) . toHaveBeenCalledWith (
24
+ "Copy to clipboard: Ctrl+C, Enter" ,
29
25
``
30
26
) ;
27
+
28
+ promptSpy . mockRestore ( ) ;
31
29
} ) ;
32
30
33
31
it ( "Expand Question Image" , ( ) => {
Original file line number Diff line number Diff line change 1
1
import { Box , ImageListItem , IconButton } from "@mui/material" ;
2
2
import ContentCopyIcon from "@mui/icons-material/ContentCopy" ;
3
3
import FullscreenIcon from "@mui/icons-material/Fullscreen" ;
4
- import { toast } from "react-toastify" ;
5
4
6
5
interface QuestionImageProps {
7
6
url : string ;
@@ -56,8 +55,11 @@ const QuestionImage: React.FC<QuestionImageProps> = ({
56
55
>
57
56
< IconButton
58
57
onClick = { ( ) => {
59
- navigator . clipboard . writeText ( `` ) ;
60
- toast . success ( "Image URL copied to clipboard" ) ;
58
+ // switch to window.prompt since navigator.clipboard.writeText is not supported in HTTP
59
+ window . prompt (
60
+ "Copy to clipboard: Ctrl+C, Enter" ,
61
+ ``
62
+ ) ;
61
63
} }
62
64
sx = { { color : "#fff" } }
63
65
aria-label = "copy"
Original file line number Diff line number Diff line change 1
- import grey from "@mui/material/colors/grey " ;
1
+ import { grey } from "@mui/material/colors" ;
2
2
import { createTheme } from "@mui/material/styles" ;
3
3
4
4
const theme = createTheme ( {
@@ -47,13 +47,13 @@ const theme = createTheme({
47
47
} ,
48
48
} ,
49
49
} ,
50
- MuiListItemText : {
51
- styleOverrides : {
52
- primary : {
53
- fontSize : "14px" ,
54
- } ,
50
+ MuiListItemText : {
51
+ styleOverrides : {
52
+ primary : {
53
+ fontSize : "14px" ,
55
54
} ,
56
- }
55
+ } ,
56
+ } ,
57
57
} ,
58
58
} ) ;
59
59
You can’t perform that action at this time.
0 commit comments