Skip to content

Commit 50c3042

Browse files
committed
Add simple test for GameDisplay.
1 parent e0f6767 commit 50c3042

1 file changed

Lines changed: 22 additions & 1 deletion

File tree

src/ui/game/GameDisplay.test.ts

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,14 @@
33
* SPDX-FileCopyrightText: Copyright (C) 2025 Gijs van Tulder
44
*/
55

6-
import { describe, test } from "@jest/globals";
6+
import { describe, expect, test } from "@jest/globals";
77
import { GameDisplay } from "./GameDisplay";
88
import { SquaresAtlas } from "../../grid/atlas/SquaresAtlas";
99
import { TileGenerators } from "../../game/TileGenerator";
10+
import { ConnectedSegmentScorer } from "../../game/scorers/ConnectedSegmentScorer";
11+
import { seedPRNG } from "../../geom/RandomSampler";
1012
import { Game } from "../../game/Game";
13+
import { AutoPlayer } from "../../game/autoplayer/AutoPlayer";
1114

1215
describe("GameDisplay", () => {
1316
test("can be created", () => {
@@ -22,4 +25,22 @@ describe("GameDisplay", () => {
2225
const display = new GameDisplay(game);
2326
display.destroy();
2427
});
28+
29+
test("can show a game", () => {
30+
const colors = ["red", "blue", "green", "black"];
31+
const settings = {
32+
atlas: SquaresAtlas,
33+
initialTile: colors,
34+
scorer: ConnectedSegmentScorer,
35+
tilesShownOnStack: 3,
36+
tileGenerator: [TileGenerators.permutations(colors)],
37+
};
38+
const prng = seedPRNG(1234);
39+
const game = new Game(settings, prng);
40+
const display = new GameDisplay(game);
41+
const player = new AutoPlayer(game);
42+
player.playAllTiles(undefined, prng);
43+
expect(display.scoreDisplay.scoreField.innerHTML).toBe("224");
44+
expect(display.element.classList.contains("game-finished")).toBe(true);
45+
});
2546
});

0 commit comments

Comments
 (0)