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 11import { fireEvent , render , screen } from "@testing-library/react" ;
22import QuestionImage from "." ;
33
4- Object . assign ( navigator , {
5- clipboard : {
6- writeText : jest . fn ( ) ,
7- } ,
8- } ) ;
9-
104describe ( "Question Image" , ( ) => {
115 const url = "https://example.com/image.jpg" ;
126 const mockHandleClickOpen = jest . fn ( ) ;
@@ -15,19 +9,23 @@ describe("Question Image", () => {
159 render ( < QuestionImage url = { url } handleClickOpen = { mockHandleClickOpen } /> ) ;
1610
1711 const image = screen . getByAltText ( "question image" ) ;
18-
1912 expect ( image ) . toBeInTheDocument ( ) ;
2013 } ) ;
2114
2215 it ( "Copy Question Image url" , ( ) => {
16+ const promptSpy = jest . spyOn ( window , "prompt" ) . mockImplementation ( ( ) => "" ) ;
17+
2318 render ( < QuestionImage url = { url } handleClickOpen = { mockHandleClickOpen } /> ) ;
2419
2520 const copyButton = screen . getByLabelText ( "copy" ) ;
2621 fireEvent . click ( copyButton ) ;
2722
28- expect ( navigator . clipboard . writeText ) . toHaveBeenCalledWith (
23+ expect ( promptSpy ) . toHaveBeenCalledWith (
24+ "Copy to clipboard: Ctrl+C, Enter" ,
2925 ``
3026 ) ;
27+
28+ promptSpy . mockRestore ( ) ;
3129 } ) ;
3230
3331 it ( "Expand Question Image" , ( ) => {
Original file line number Diff line number Diff line change 11import { Box , ImageListItem , IconButton } from "@mui/material" ;
22import ContentCopyIcon from "@mui/icons-material/ContentCopy" ;
33import FullscreenIcon from "@mui/icons-material/Fullscreen" ;
4- import { toast } from "react-toastify" ;
54
65interface QuestionImageProps {
76 url : string ;
@@ -56,8 +55,11 @@ const QuestionImage: React.FC<QuestionImageProps> = ({
5655 >
5756 < IconButton
5857 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+ ) ;
6163 } }
6264 sx = { { color : "#fff" } }
6365 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" ;
22import { createTheme } from "@mui/material/styles" ;
33
44const theme = createTheme ( {
@@ -47,13 +47,13 @@ const theme = createTheme({
4747 } ,
4848 } ,
4949 } ,
50- MuiListItemText : {
51- styleOverrides : {
52- primary : {
53- fontSize : "14px" ,
54- } ,
50+ MuiListItemText : {
51+ styleOverrides : {
52+ primary : {
53+ fontSize : "14px" ,
5554 } ,
56- }
55+ } ,
56+ } ,
5757 } ,
5858} ) ;
5959
You can’t perform that action at this time.
0 commit comments