-
Notifications
You must be signed in to change notification settings - Fork 0
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 #1 from fgandellini/obstacles
Add support for obstacles
- Loading branch information
Showing
23 changed files
with
651 additions
and
244 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
41 changes: 41 additions & 0 deletions
41
apps/react/src/components/welcome/ObstaclesSelector.test.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,41 @@ | ||
import '@testing-library/jest-dom' | ||
import { render, screen } from '@testing-library/react' | ||
import { ObstaclesSelector } from './ObstaclesSelector' | ||
|
||
describe('ObstaclesSelector', () => { | ||
test('Renders the obstacles selector', async () => { | ||
const { container } = render( | ||
<ObstaclesSelector obstacles={0} onSelectObstacles={() => {}} />, | ||
) | ||
|
||
expect(container.getElementsByClassName('obstacles-selector').length).toBe( | ||
1, | ||
) | ||
expect(screen.getByText('SELECT OBSTACLES')).toBeInTheDocument() | ||
expect(screen.getByText('Peaceful (none)')).toBeInTheDocument() | ||
expect(screen.getByText('Easy (2)')).toBeInTheDocument() | ||
expect(screen.getByText('Normal (4)')).toBeInTheDocument() | ||
expect(screen.getByText('Hard (8)')).toBeInTheDocument() | ||
}) | ||
|
||
test('Allows to select the number of obstacles', async () => { | ||
const onSelectObstacles = jest.fn() | ||
|
||
render( | ||
<ObstaclesSelector obstacles={0} onSelectObstacles={onSelectObstacles} />, | ||
) | ||
|
||
const easy = screen.getByText('Easy (2)') | ||
const normal = screen.getByText('Normal (4)') | ||
const hard = screen.getByText('Hard (8)') | ||
|
||
easy.click() | ||
expect(onSelectObstacles).toHaveBeenCalledWith(2) | ||
|
||
normal.click() | ||
expect(onSelectObstacles).toHaveBeenCalledWith(4) | ||
|
||
hard.click() | ||
expect(onSelectObstacles).toHaveBeenCalledWith(8) | ||
}) | ||
}) |
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,65 @@ | ||
type ObstaclesSelectorProps = { | ||
obstacles: number | ||
onSelectObstacles: (obstacles: number) => void | ||
} | ||
|
||
/** | ||
* The obstacles selector | ||
* | ||
* It's responsible for rendering the obstacles selector. | ||
* The obstacles selector allows the player to select the obstacles to include in the board. | ||
* | ||
* The user can choose how many obstacles to add to the board, the options are: none, 2, 4, or 8. | ||
*/ | ||
export const ObstaclesSelector = ({ | ||
obstacles, | ||
onSelectObstacles, | ||
}: ObstaclesSelectorProps) => ( | ||
<div className="nes-container with-title is-dark obstacles-selector"> | ||
<h3 className="title">SELECT OBSTACLES</h3> | ||
<label htmlFor="obstacles-0"> | ||
<input | ||
type="radio" | ||
className="nes-radio is-dark" | ||
id="obstacles-0" | ||
name="obstacles" | ||
checked={obstacles === 0} | ||
onChange={() => onSelectObstacles(0)} | ||
/> | ||
<span>Peaceful (none)</span> | ||
</label> | ||
<label htmlFor="obstacles-2"> | ||
<input | ||
type="radio" | ||
className="nes-radio is-dark" | ||
id="obstacles-2" | ||
name="obstacles" | ||
checked={obstacles === 2} | ||
onChange={() => onSelectObstacles(2)} | ||
/> | ||
<span>Easy (2)</span> | ||
</label> | ||
<label htmlFor="obstacles-4"> | ||
<input | ||
type="radio" | ||
className="nes-radio is-dark" | ||
id="obstacles-4" | ||
name="obstacles" | ||
checked={obstacles === 4} | ||
onChange={() => onSelectObstacles(4)} | ||
/> | ||
<span>Normal (4)</span> | ||
</label> | ||
<label htmlFor="obstacles-8"> | ||
<input | ||
type="radio" | ||
className="nes-radio is-dark" | ||
id="obstacles-8" | ||
name="obstacles" | ||
checked={obstacles === 8} | ||
onChange={() => onSelectObstacles(8)} | ||
/> | ||
<span>Hard (8)</span> | ||
</label> | ||
</div> | ||
) |
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
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
Oops, something went wrong.