Skip to content

Commit 4ab2040

Browse files
committed
Merge branch 'development' into deployment
2 parents 086f03b + 1342ab4 commit 4ab2040

File tree

3 files changed

+18
-18
lines changed

3 files changed

+18
-18
lines changed

frontend/src/components/QuestionImage/QuestionImage.test.tsx

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
11
import { fireEvent, render, screen } from "@testing-library/react";
22
import QuestionImage from ".";
33

4-
Object.assign(navigator, {
5-
clipboard: {
6-
writeText: jest.fn(),
7-
},
8-
});
9-
104
describe("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
`![image](${url})`
3026
);
27+
28+
promptSpy.mockRestore();
3129
});
3230

3331
it("Expand Question Image", () => {

frontend/src/components/QuestionImage/index.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { Box, ImageListItem, IconButton } from "@mui/material";
22
import ContentCopyIcon from "@mui/icons-material/ContentCopy";
33
import FullscreenIcon from "@mui/icons-material/Fullscreen";
4-
import { toast } from "react-toastify";
54

65
interface QuestionImageProps {
76
url: string;
@@ -56,8 +55,11 @@ const QuestionImage: React.FC<QuestionImageProps> = ({
5655
>
5756
<IconButton
5857
onClick={() => {
59-
navigator.clipboard.writeText(`![image](${url})`);
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+
`![image](${url})`
62+
);
6163
}}
6264
sx={{ color: "#fff" }}
6365
aria-label="copy"

frontend/src/theme.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import grey from "@mui/material/colors/grey";
1+
import { grey } from "@mui/material/colors";
22
import { createTheme } from "@mui/material/styles";
33

44
const 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

0 commit comments

Comments
 (0)