-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
- Loading branch information
1 parent
d12b62d
commit 7a89d46
Showing
24 changed files
with
568 additions
and
103 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Binary file added
BIN
+36.4 KB
.yarn/cache/@testing-library-jest-dom-npm-5.11.9-ad0c7dbe3e-c285c044ed.zip
Binary file not shown.
Binary file added
BIN
+7.09 KB
.yarn/cache/@types-testing-library__jest-dom-npm-5.9.5-5a42b58918-32aa324a83.zip
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
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 @@ | ||
releases: | ||
react-dnd-examples-decorators: patch | ||
react-dnd-examples-hooks: patch | ||
|
||
declined: | ||
- react-dnd-documentation |
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,32 +1,37 @@ | ||
let knightPosition: [number, number] = [1, 7] | ||
let observers: PositionObserver[] = [] | ||
export type PositionObserver = ((position: [number, number]) => void) | null | ||
export type Position = [number, number] | ||
export type PositionObserver = ((position: Position) => void) | null | ||
|
||
function emitChange() { | ||
observers.forEach((o) => o && o(knightPosition)) | ||
} | ||
export class Game { | ||
public knightPosition: Position = [1, 7] | ||
private observers: PositionObserver[] = [] | ||
|
||
export function observe(o: PositionObserver): () => void { | ||
observers.push(o) | ||
emitChange() | ||
public observe(o: PositionObserver): () => void { | ||
this.observers.push(o) | ||
this.emitChange() | ||
|
||
return (): void => { | ||
observers = observers.filter((t) => t !== o) | ||
return (): void => { | ||
this.observers = this.observers.filter((t) => t !== o) | ||
} | ||
} | ||
} | ||
|
||
export function canMoveKnight(toX: number, toY: number): boolean { | ||
const [x, y] = knightPosition | ||
const dx = toX - x | ||
const dy = toY - y | ||
public moveKnight(toX: number, toY: number): void { | ||
this.knightPosition = [toX, toY] | ||
this.emitChange() | ||
} | ||
|
||
return ( | ||
(Math.abs(dx) === 2 && Math.abs(dy) === 1) || | ||
(Math.abs(dx) === 1 && Math.abs(dy) === 2) | ||
) | ||
} | ||
public canMoveKnight(toX: number, toY: number): boolean { | ||
const [x, y] = this.knightPosition | ||
const dx = toX - x | ||
const dy = toY - y | ||
|
||
export function moveKnight(toX: number, toY: number): void { | ||
knightPosition = [toX, toY] | ||
emitChange() | ||
return ( | ||
(Math.abs(dx) === 2 && Math.abs(dy) === 1) || | ||
(Math.abs(dx) === 1 && Math.abs(dy) === 2) | ||
) | ||
} | ||
|
||
private emitChange() { | ||
const pos = this.knightPosition | ||
this.observers.forEach((o) => o && o(pos)) | ||
} | ||
} |
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.