-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
151 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import React from "react" | ||
import { render, screen, fireEvent } from "@testing-library/react" | ||
import "@testing-library/jest-dom" | ||
import ShortcutsDialog from "./index" // Adjust the import based on your file structure | ||
import { useTranslation } from "react-i18next" | ||
|
||
// Mock the useTranslation hook | ||
jest.mock("react-i18next", () => ({ | ||
useTranslation: () => ({ | ||
t: (key) => key, // Simply return the key as the translation | ||
}), | ||
})) | ||
|
||
describe("ShortcutsDialog", () => { | ||
const mockHandleClose = jest.fn() | ||
|
||
const defaultProps = { | ||
open: true, | ||
handleClose: mockHandleClose, | ||
} | ||
|
||
beforeEach(() => { | ||
render(<ShortcutsDialog {...defaultProps} />) | ||
}) | ||
|
||
afterEach(() => { | ||
jest.clearAllMocks() | ||
}) | ||
|
||
test("renders all shortcuts with corresponding actions", () => { | ||
const shortcuts = [ | ||
{ key: "Ctrl + Shift + B", action: "helptext_boundingbox" }, | ||
{ key: "Ctrl + Shift + Z", action: "helptext_zoom" }, | ||
{ key: "Ctrl + Shift + P", action: "helptext_polypolygon" }, | ||
{ key: "Ctrl + Shift + C", action: "helptext_circle" }, | ||
{ key: "↑", action: "short_key_up" }, | ||
{ key: "↓", action: "short_key_down" }, | ||
] | ||
shortcuts.forEach((shortcut, index) => { | ||
expect(screen.getByTestId(`shortcut-key-${index}`)).toBeInTheDocument() | ||
}) | ||
}) | ||
|
||
test("calls handleClose when close button is clicked", () => { | ||
const closeButton = screen.getByTestId("close-button") | ||
fireEvent.click(closeButton) | ||
expect(mockHandleClose).toHaveBeenCalledTimes(1) | ||
}) | ||
|
||
|
||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import * as React from "react" | ||
import Button from "@mui/material/Button" | ||
import Dialog from "@mui/material/Dialog" | ||
import DialogActions from "@mui/material/DialogActions" | ||
import DialogContent from "@mui/material/DialogContent" | ||
import DialogTitle from "@mui/material/DialogTitle" | ||
import Box from "@mui/material/Box" | ||
import Typography from "@mui/material/Typography" | ||
import { useTranslation } from "react-i18next" | ||
|
||
export const ShortcutsDialog = ({ open, handleClose }) => { | ||
const { t } = useTranslation() | ||
|
||
const shortcuts = [ | ||
{ key: "Ctrl + Shift + B", action: t("helptext_boundingbox") }, | ||
{ key: "Ctrl + Shift + Z", action: t("helptext_zoom") }, | ||
{ key: "Ctrl + Shift + P", action: t("helptext_polypolygon") }, | ||
{ key: "Ctrl + Shift + C", action: t("helptext_circle") }, | ||
{ key: "↑", action: t("short_key_up") }, // Up arrow key for navigation | ||
{ key: "↓", action: t("short_key_down") }, // Down arrow key for navigation | ||
] | ||
|
||
return ( | ||
<Dialog | ||
open={open} | ||
onClose={handleClose} | ||
aria-labelledby="shortcuts-dialog-title" | ||
aria-describedby="shortcuts-dialog-description" | ||
data-testid="shortcuts-dialog" | ||
fullWidth | ||
maxWidth="sm" | ||
PaperProps={{ | ||
style: { | ||
minHeight: "40vh", | ||
maxHeight: "80vh", | ||
padding: "20px", | ||
}, | ||
}} | ||
> | ||
<DialogTitle id="shortcuts-dialog-title" data-testid="shortcuts-dialog-title"> | ||
{t("Keyboard Shortcuts")} | ||
</DialogTitle> | ||
<DialogContent data-testid="shortcuts-dialog-content"> | ||
<Box display="flex" flexDirection="column" gap={2}> | ||
{shortcuts.map((shortcut, index) => ( | ||
<Box | ||
key={index} | ||
display="flex" | ||
justifyContent="space-between" | ||
alignItems="center" | ||
px={1} | ||
> | ||
<Typography variant="body1" data-testid={`shortcut-key-${index}`}> | ||
{shortcut.key} | ||
</Typography> | ||
<Typography variant="body2" data-testid={`shortcut-action-${index}`}> | ||
{shortcut.action} | ||
</Typography> | ||
</Box> | ||
))} | ||
</Box> | ||
</DialogContent> | ||
<DialogActions data-testid="shortcuts-dialog-actions"> | ||
<Button onClick={handleClose} data-testid="close-button"> | ||
{t("Close")} | ||
</Button> | ||
</DialogActions> | ||
</Dialog> | ||
) | ||
} | ||
|
||
export default ShortcutsDialog |