diff --git a/src/modules/GameWithHooks/hooks/use-game/index.tsx b/src/modules/GameWithHooks/hooks/use-game/index.tsx index bef2ad56..db43ea15 100644 --- a/src/modules/GameWithHooks/hooks/use-game/index.tsx +++ b/src/modules/GameWithHooks/hooks/use-game/index.tsx @@ -7,6 +7,7 @@ interface ReturnType { level: LevelNames; isGameOver: boolean; isWin: boolean; + gameField: Field; settings: [number, number]; playerField: Field; onClickHandler: (coords: Coordinates) => void; @@ -57,6 +58,7 @@ export const useGame = (): ReturnType => { level, isGameOver, isWin, + gameField, settings: [size, bombs], playerField, onClickHandler, diff --git a/src/modules/GameWithHooks/hooks/use-game/use-game-check-game-field.test.ts b/src/modules/GameWithHooks/hooks/use-game/use-game-check-game-field.test.ts new file mode 100644 index 00000000..a7629b1f --- /dev/null +++ b/src/modules/GameWithHooks/hooks/use-game/use-game-check-game-field.test.ts @@ -0,0 +1,29 @@ +import { CellState, Field } from "@helpers/field"; +import { useGame } from "@modules/GameWithHooks/hooks/use-game/index"; +import { act, renderHook } from "@testing-library/react"; + +const { bomb: b } = CellState; + +const flatWithFilter = (field: Field, cond: number) => field.flat().filter((v) => v === cond); + +describe("useGame test cases", () => { + it("Render hook by default", () => { + const { result } = renderHook(useGame); + const { gameField } = result.current; + + expect(flatWithFilter(gameField, b)).toHaveLength(10); + }); + it("onReset game handler", () => { + const { result } = renderHook(useGame); + const { playerField, onClickHandler, onResetHandler } = result.current; + + expect(playerField).toHaveLength(9); + + act(() => onClickHandler([5, 5])); + act(onResetHandler); + + const { gameField } = result.current; + + expect(flatWithFilter(gameField, b)).toHaveLength(10); + }); +});