Skip to content

Commit

Permalink
Merge branch 'development' into deployment
Browse files Browse the repository at this point in the history
  • Loading branch information
jolynloh committed Nov 10, 2024
2 parents 086f03b + 1342ab4 commit 4ab2040
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 18 deletions.
14 changes: 6 additions & 8 deletions frontend/src/components/QuestionImage/QuestionImage.test.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
import { fireEvent, render, screen } from "@testing-library/react";
import QuestionImage from ".";

Object.assign(navigator, {
clipboard: {
writeText: jest.fn(),
},
});

describe("Question Image", () => {
const url = "https://example.com/image.jpg";
const mockHandleClickOpen = jest.fn();
Expand All @@ -15,19 +9,23 @@ describe("Question Image", () => {
render(<QuestionImage url={url} handleClickOpen={mockHandleClickOpen} />);

const image = screen.getByAltText("question image");

expect(image).toBeInTheDocument();
});

it("Copy Question Image url", () => {
const promptSpy = jest.spyOn(window, "prompt").mockImplementation(() => "");

render(<QuestionImage url={url} handleClickOpen={mockHandleClickOpen} />);

const copyButton = screen.getByLabelText("copy");
fireEvent.click(copyButton);

expect(navigator.clipboard.writeText).toHaveBeenCalledWith(
expect(promptSpy).toHaveBeenCalledWith(
"Copy to clipboard: Ctrl+C, Enter",
`![image](${url})`
);

promptSpy.mockRestore();
});

it("Expand Question Image", () => {
Expand Down
8 changes: 5 additions & 3 deletions frontend/src/components/QuestionImage/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { Box, ImageListItem, IconButton } from "@mui/material";
import ContentCopyIcon from "@mui/icons-material/ContentCopy";
import FullscreenIcon from "@mui/icons-material/Fullscreen";
import { toast } from "react-toastify";

interface QuestionImageProps {
url: string;
Expand Down Expand Up @@ -56,8 +55,11 @@ const QuestionImage: React.FC<QuestionImageProps> = ({
>
<IconButton
onClick={() => {
navigator.clipboard.writeText(`![image](${url})`);
toast.success("Image URL copied to clipboard");
// switch to window.prompt since navigator.clipboard.writeText is not supported in HTTP
window.prompt(
"Copy to clipboard: Ctrl+C, Enter",
`![image](${url})`
);
}}
sx={{ color: "#fff" }}
aria-label="copy"
Expand Down
14 changes: 7 additions & 7 deletions frontend/src/theme.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import grey from "@mui/material/colors/grey";
import { grey } from "@mui/material/colors";
import { createTheme } from "@mui/material/styles";

const theme = createTheme({
Expand Down Expand Up @@ -47,13 +47,13 @@ const theme = createTheme({
},
},
},
MuiListItemText: {
styleOverrides: {
primary: {
fontSize: "14px",
},
MuiListItemText: {
styleOverrides: {
primary: {
fontSize: "14px",
},
}
},
},
},
});

Expand Down

0 comments on commit 4ab2040

Please sign in to comment.