Skip to content

Commit 7a89d46

Browse files
authored
Migrate Chess Example Tests from PR (#3025)
* test: merge in testing-library based tests for the chessboard example (@ryota-murakami ) * refactor: remove file * chore: cut semver file
1 parent d12b62d commit 7a89d46

24 files changed

+568
-103
lines changed

.pnp.js

Lines changed: 67 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

.yarn/versions/b852359f.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
releases:
2+
react-dnd-examples-decorators: patch
3+
react-dnd-examples-hooks: patch
4+
5+
declined:
6+
- react-dnd-documentation

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,11 @@
6868
"@babel/preset-typescript": "^7.12.13",
6969
"@commitlint/cli": "^11.0.0",
7070
"@commitlint/config-conventional": "^11.0.0",
71+
"@testing-library/jest-dom": "^5.11.9",
7172
"@testing-library/react": "^11.2.5",
7273
"@types/jest": "^26.0.20",
7374
"@types/node": "^14.14.25",
75+
"@types/testing-library__jest-dom": "^5",
7476
"@typescript-eslint/eslint-plugin": "^4.15.0",
7577
"@typescript-eslint/parser": "^4.15.0",
7678
"@wojtekmaj/enzyme-adapter-react-17": "^0.4.1",

packages/examples-decorators/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,15 @@
3333
},
3434
"devDependencies": {
3535
"@react-dnd/build": "workspace:packages/build",
36+
"@testing-library/jest-dom": "^5.11.9",
3637
"@testing-library/react": "^11.2.5",
3738
"@types/enzyme": "^3.10.8",
3839
"@types/faker": "^5.1.6",
3940
"@types/jest": "^26.0.20",
4041
"@types/lodash": "^4.14.168",
4142
"@types/react": "^17.0.1",
4243
"@types/react-dom": "^17.0.0",
44+
"@types/testing-library__jest-dom": "^5",
4345
"enzyme": "^3.11.0",
4446
"gulp": "^4.0.2",
4547
"npm-run-all": "^4.1.5",

packages/examples-decorators/src/00-chessboard/Board.tsx

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
import { CSSProperties, FC } from 'react'
1+
import { CSSProperties, FC, useEffect, useState } from 'react'
22
import BoardSquare from './BoardSquare'
3+
import { Game, Position } from './Game'
34
import { Piece } from './Piece'
45

56
export interface BoardProps {
6-
knightPosition: [number, number]
7+
game: Game
78
}
89

910
/** Styling properties applied to the board element */
@@ -20,16 +21,19 @@ const squareStyle: CSSProperties = { width: '12.5%', height: '12.5%' }
2021
* The chessboard component
2122
* @param props The react props
2223
*/
23-
export const Board: FC<BoardProps> = ({
24-
knightPosition: [knightX, knightY],
25-
}) => {
24+
export const Board: FC<BoardProps> = ({ game }) => {
25+
const [[knightX, knightY], setKnightPos] = useState<Position>(
26+
game.knightPosition,
27+
)
28+
useEffect(() => game.observe(setKnightPos))
29+
2630
function renderSquare(i: number) {
2731
const x = i % 8
2832
const y = Math.floor(i / 8)
2933

3034
return (
3135
<div key={i} style={squareStyle}>
32-
<BoardSquare x={x} y={y}>
36+
<BoardSquare x={x} y={y} game={game}>
3337
<Piece isKnight={x === knightX && y === knightY} />
3438
</BoardSquare>
3539
</div>

0 commit comments

Comments
 (0)