-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1294 from qdraw/feature/202312_code_smells
move from div to button and code smells fix
- Loading branch information
Showing
124 changed files
with
2,147 additions
and
1,658 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
#nullable enable | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
|
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
104 changes: 104 additions & 0 deletions
104
starsky/starsky/clientapp/src/components/atoms/menu-option-modal/menu-option-modal.spec.tsx
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,104 @@ | ||
import { fireEvent, render, screen } from "@testing-library/react"; | ||
import MenuOptionModal from "./menu-option-modal.tsx"; | ||
|
||
describe("MenuOption component", () => { | ||
it("expect content", () => { | ||
const setMock = jest.fn(); | ||
const setEnableMoreMenuMock = jest.fn(); | ||
render( | ||
<MenuOptionModal | ||
localization={{ nl: "Content", en: "Content" }} | ||
isSet={false} | ||
set={setMock} | ||
testName="test" | ||
isReadOnly={true} | ||
setEnableMoreMenu={setEnableMoreMenuMock} | ||
/> | ||
); | ||
|
||
expect(screen.getByTestId("test")).toBeTruthy(); | ||
expect(screen.getByTestId("test").innerHTML).toBe("Content"); | ||
}); | ||
|
||
it("expect child no localisation field", () => { | ||
const setMock = jest.fn(); | ||
const setEnableMoreMenuMock = jest.fn(); | ||
render( | ||
<MenuOptionModal | ||
isSet={false} | ||
set={setMock} | ||
testName="test" | ||
isReadOnly={true} | ||
setEnableMoreMenu={setEnableMoreMenuMock} | ||
> | ||
<div>Content</div> | ||
</MenuOptionModal> | ||
); | ||
|
||
expect(screen.getByTestId("test")).toBeTruthy(); | ||
expect(screen.getByTestId("test").innerHTML).toBe("<div>Content</div>"); | ||
}); | ||
|
||
it("should not trigger setEnableMoreMenu when isReadOnly is true", () => { | ||
const setMock = jest.fn(); | ||
const setEnableMoreMenuMock = jest.fn(); | ||
render( | ||
<MenuOptionModal | ||
localization={{ nl: "Nederlands", en: "English" }} | ||
isSet={false} | ||
set={setMock} | ||
testName="test" | ||
isReadOnly={true} | ||
setEnableMoreMenu={setEnableMoreMenuMock} | ||
/> | ||
); | ||
|
||
fireEvent.click(screen.getByTestId("test")); | ||
|
||
expect(setMock).toHaveBeenCalledTimes(0); | ||
expect(setEnableMoreMenuMock).not.toHaveBeenCalled(); | ||
}); | ||
|
||
it("should trigger setEnableMoreMenu when isReadOnly is false", () => { | ||
const setMock = jest.fn(); | ||
const setEnableMoreMenuMock = jest.fn(); | ||
render( | ||
<MenuOptionModal | ||
localization={{ nl: "Nederlands", en: "English" }} | ||
isSet={false} | ||
set={setMock} | ||
testName="test" | ||
isReadOnly={false} | ||
setEnableMoreMenu={setEnableMoreMenuMock} | ||
/> | ||
); | ||
expect(screen.getByTestId("test")).toBeTruthy(); | ||
|
||
fireEvent.click(screen.getByTestId("test")); | ||
|
||
expect(setMock).toHaveBeenCalledTimes(1); | ||
expect(setEnableMoreMenuMock).toHaveBeenCalled(); | ||
}); | ||
|
||
it("missing localisation field", () => { | ||
const setMock = jest.fn(); | ||
const setEnableMoreMenuMock = jest.fn(); | ||
render( | ||
<MenuOptionModal | ||
isSet={false} | ||
set={setMock} | ||
testName="test" | ||
isReadOnly={false} | ||
setEnableMoreMenu={setEnableMoreMenuMock} | ||
/> | ||
); | ||
|
||
expect(screen.getByTestId("test")).toBeTruthy(); | ||
expect(screen.getByTestId("test").innerHTML).toBe(""); | ||
|
||
fireEvent.click(screen.getByTestId("test")); | ||
|
||
expect(setMock).toHaveBeenCalledTimes(1); | ||
expect(setEnableMoreMenuMock).toHaveBeenCalled(); | ||
}); | ||
}); |
28 changes: 28 additions & 0 deletions
28
...ky/starsky/clientapp/src/components/atoms/menu-option-modal/menu-option-modal.stories.tsx
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,28 @@ | ||
import MenuOptionModal from "./menu-option-modal.tsx"; | ||
|
||
export default { | ||
title: "components/atoms/menu-option-modal" | ||
}; | ||
|
||
export const Default = () => { | ||
return ( | ||
<div className="menu-context"> | ||
<ul className="menu-options"> | ||
<MenuOptionModal | ||
localization={{ nl: "Nederlands", en: "English" }} | ||
isSet={false} | ||
set={() => {}} | ||
testName="test" | ||
isReadOnly={false} | ||
setEnableMoreMenu={(value) => { | ||
alert(value); | ||
}} | ||
/> | ||
</ul> | ||
</div> | ||
); | ||
}; | ||
|
||
Default.story = { | ||
name: "default" | ||
}; |
62 changes: 62 additions & 0 deletions
62
starsky/starsky/clientapp/src/components/atoms/menu-option-modal/menu-option-modal.tsx
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,62 @@ | ||
import React, { memo } from "react"; | ||
import useGlobalSettings from "../../../hooks/use-global-settings"; | ||
import { Language } from "../../../shared/language"; | ||
|
||
interface IMenuOptionModalProps { | ||
isReadOnly: boolean; | ||
testName: string; | ||
isSet: boolean; | ||
set: React.Dispatch<React.SetStateAction<boolean>>; | ||
localization?: { nl: string; en: string }; | ||
setEnableMoreMenu?: React.Dispatch<React.SetStateAction<boolean>>; | ||
children?: React.ReactNode; | ||
} | ||
|
||
const MenuOptionModal: React.FunctionComponent<IMenuOptionModalProps> = memo( | ||
({ | ||
localization, | ||
isSet, | ||
set, | ||
testName, | ||
isReadOnly = true, | ||
setEnableMoreMenu = undefined, | ||
children = undefined | ||
}) => { | ||
const settings = useGlobalSettings(); | ||
const language = new Language(settings.language); | ||
|
||
const Message = !localization ? "" : language.key(localization); | ||
|
||
function onClickHandler() { | ||
if (isReadOnly) { | ||
return; | ||
} | ||
// close menu | ||
if (setEnableMoreMenu) { | ||
setEnableMoreMenu(false); | ||
} | ||
set(!isSet); | ||
} | ||
|
||
return ( | ||
<> | ||
{ | ||
<li className={!isReadOnly ? "menu-option" : "menu-option disabled"}> | ||
<button | ||
data-test={testName} | ||
onClick={onClickHandler} | ||
onKeyDown={(event) => { | ||
event.key === "Enter" && onClickHandler(); | ||
}} | ||
> | ||
{Message} | ||
{children} | ||
</button> | ||
</li> | ||
} | ||
</> | ||
); | ||
} | ||
); | ||
|
||
export default MenuOptionModal; |
Oops, something went wrong.
87f7bb0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎉 Published on https://starskyapp.netlify.app as production
🚀 Deployed on https://65736df162d11550776a7f45--starskyapp.netlify.app