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" ;
77import { GameDisplay } from "./GameDisplay" ;
88import { SquaresAtlas } from "../../grid/atlas/SquaresAtlas" ;
99import { TileGenerators } from "../../game/TileGenerator" ;
10+ import { ConnectedSegmentScorer } from "../../game/scorers/ConnectedSegmentScorer" ;
11+ import { seedPRNG } from "../../geom/RandomSampler" ;
1012import { Game } from "../../game/Game" ;
13+ import { AutoPlayer } from "../../game/autoplayer/AutoPlayer" ;
1114
1215describe ( "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