-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create scoreboard components - container
- Loading branch information
Showing
8 changed files
with
125 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export * from "./components/counter/counter"; | ||
export * from "./components/level"; | ||
export * from "./counter/counter"; | ||
export * from "./level/level"; | ||
export * from "./reset/reset"; |
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,9 @@ | ||
.resetButton { | ||
font-size: 1.5vw; | ||
cursor: pointer; | ||
font-weight: 700; | ||
border-width: 0.15vw; | ||
border-style: solid; | ||
background-color: #d1d1d1; | ||
border-color: white #9e9e9e #9e9e9e white; | ||
} |
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,42 @@ | ||
import { ResetButton } from "@components/scoreboard/components/reset/reset"; | ||
import { fireEvent, render, screen } from "@testing-library/react"; | ||
import React, { FunctionComponent } from "react"; | ||
|
||
describe("Reset button test", function () { | ||
const ResetWithDummyHandlerOnReset: FunctionComponent = () => <ResetButton onReset={() => null} />; | ||
|
||
it("should render elements with default state", function () { | ||
render(<ResetWithDummyHandlerOnReset />); | ||
|
||
expect(screen.getByText("🙂")).toBeInTheDocument(); | ||
}); | ||
|
||
it("onReset handler should be called", function () { | ||
const onReset = jest.fn(); | ||
|
||
render(<ResetButton onReset={onReset} />); | ||
fireEvent.click(screen.getByText("🙂")); | ||
|
||
expect(onReset).toBeCalled(); | ||
}); | ||
|
||
it("should change state when onMouseDown and onMouseUp events happened", function () { | ||
render(<ResetWithDummyHandlerOnReset />); | ||
|
||
fireEvent.mouseDown(screen.getByText("🙂")); | ||
expect(screen.getByText("😯")).toBeInTheDocument(); | ||
|
||
fireEvent.mouseUp(screen.getByText("😯")); | ||
expect(screen.getByText("🙂")).toBeInTheDocument(); | ||
}); | ||
|
||
it("should change state when onMouseDown and onMouseLeave events happened", function () { | ||
render(<ResetWithDummyHandlerOnReset />); | ||
|
||
fireEvent.mouseDown(screen.getByText("🙂")); | ||
expect(screen.getByText("😯")).toBeInTheDocument(); | ||
|
||
fireEvent.mouseLeave(screen.getByText("😯")); | ||
expect(screen.getByText("🙂")).toBeInTheDocument(); | ||
}); | ||
}); |
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,29 @@ | ||
import React, { FunctionComponent, useState } from "react"; | ||
|
||
import styles from "./reset.module.scss"; | ||
|
||
export interface ResetProps { | ||
/** | ||
* Reset action handler | ||
*/ | ||
onReset: () => void; | ||
} | ||
|
||
export const ResetButton: FunctionComponent<ResetProps> = ({ onReset }) => { | ||
const [mouseDown, setMouseDown] = useState(false); | ||
|
||
const onMouseDown = () => setMouseDown(true); | ||
const onMouseUp = () => setMouseDown(false); | ||
|
||
return ( | ||
<button | ||
className={styles.resetButton} | ||
onMouseDown={onMouseDown} | ||
onMouseUp={onMouseUp} | ||
onMouseLeave={onMouseUp} | ||
onClick={onReset} | ||
> | ||
{mouseDown ? "😯" : "🙂"} | ||
</button> | ||
); | ||
}; |
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 @@ | ||
export { ScoreBoard, ScoreboardProps } from "./scoreboard"; |
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,6 @@ | ||
.wrapperScoreboard { | ||
display: flex; | ||
width: max-content; | ||
padding-bottom: 2vw; | ||
justify-content: space-between; | ||
} |
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,34 @@ | ||
import React, { FunctionComponent } from "react"; | ||
|
||
import { Counter, Level, ResetButton } from "./components"; | ||
import styles from "./scoreboard.module.scss"; | ||
|
||
export interface ScoreboardProps { | ||
/** | ||
* Timer | ||
*/ | ||
time: string; | ||
/** | ||
* Possible game scenarios | ||
*/ | ||
levels: string[]; | ||
/** | ||
* Action handler when the GameReset button is clicked | ||
*/ | ||
onReset: () => void; | ||
/** | ||
* Bombs in the field | ||
*/ | ||
mines: string; | ||
} | ||
|
||
export const ScoreBoard: FunctionComponent<ScoreboardProps> = ({ time, mines, onReset, levels }) => { | ||
return ( | ||
<div className={styles.wrapperScoreboard}> | ||
<Counter itemNumber={time} /> | ||
<Level levelData={levels} /> | ||
<ResetButton onReset={onReset} /> | ||
<Counter itemNumber={mines} /> | ||
</div> | ||
); | ||
}; |