Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions Tests/E2E/fixtures/game-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,26 @@ function makeNearSolvedCells(emptyRow = 0, emptyCol = 0): CellModel[] {
return cells;
}

/**
* Builds 81 cells with TWO empty user-editable cells.
* Filling only one of them won't solve the board, so isSolved() stays false.
*/
function makeNearSolvedCellsWith2Empty(
emptyRow1 = 0, emptyCol1 = 0,
emptyRow2 = 0, emptyCol2 = 1,
): CellModel[] {
const cells: CellModel[] = [];
for (let r = 0; r < 9; r++) {
for (let c = 0; c < 9; c++) {
const isEmpty =
(r === emptyRow1 && c === emptyCol1) ||
(r === emptyRow2 && c === emptyCol2);
cells.push(isEmpty ? makeEmptyCell(r, c) : makeCell(r, c, SOLVED_BOARD[r][c], true));
}
}
return cells;
}

/**
* Builds a fully solved 81-cell board.
* Cell (0,0) is user-placed (isFixed=false) to reflect that the user filled it in.
Expand Down Expand Up @@ -178,6 +198,30 @@ export function makeSolvedGame(): GameModel {
});
}

/**
* A game with TWO empty cells — cell (0,0) and cell (0,1) — so that filling
* cell (0,0) does NOT complete the board and isSolved() stays false.
* Use this as `initialGame` in cell-interaction tests.
*/
export function makeTestGameForInteraction(): GameModel {
return makeTestGame({
cells: makeNearSolvedCellsWith2Empty(EMPTY_CELL_ROW, EMPTY_CELL_COL, 0, 1),
});
}

/**
* State after the user places EMPTY_CELL_VALUE in cell (0,0) while cell (0,1)
* is still empty. isSolved() returns false so no victory display is triggered.
* Use as `gameAfterMove` in cell-interaction tests.
*/
export function makeTestGameAfterInteractionMove(): GameModel {
const cells = makeNearSolvedCellsWith2Empty(EMPTY_CELL_ROW, EMPTY_CELL_COL, 0, 1);
const cell = cells.find(c => c.row === EMPTY_CELL_ROW && c.column === EMPTY_CELL_COL)!;
cell.value = EMPTY_CELL_VALUE;
cell.hasValue = true;
return makeTestGame({ cells });
}

/**
* A lightweight saved game for populating the home-page load-game list.
*/
Expand Down
10 changes: 6 additions & 4 deletions Tests/E2E/tests/game.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import {
makeTestGameWithMove,
makeTestGameWithStats,
makeSolvedGame,
makeTestGameForInteraction,
makeTestGameAfterInteractionMove,
} from '../fixtures/game-data';

// ────────────────────────────────────────────────────────────────────────────
Expand Down Expand Up @@ -58,8 +60,8 @@ test.describe('Game Page – Board', () => {
test.describe('Game Page – Cell Interaction', () => {
test('clicking a number button places a value in the selected cell', async ({ page, gamePage }) => {
await setupApiMocks(page, {
initialGame: makeTestGame(),
gameAfterMove: makeTestGameWithMove(),
initialGame: makeTestGameForInteraction(),
gameAfterMove: makeTestGameAfterInteractionMove(),
});
await gamePage.goto(TEST_GAME_ID);

Expand All @@ -72,8 +74,8 @@ test.describe('Game Page – Cell Interaction', () => {

test('pressing a number key on the keyboard places a value in the selected cell', async ({ page, gamePage }) => {
await setupApiMocks(page, {
initialGame: makeTestGame(),
gameAfterMove: makeTestGameWithMove(),
initialGame: makeTestGameForInteraction(),
gameAfterMove: makeTestGameAfterInteractionMove(),
});
await gamePage.goto(TEST_GAME_ID);

Expand Down
2 changes: 1 addition & 1 deletion src/backend/Tests/Blazor/Services/GameTimerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public async Task OnTick_ShouldFireAtInterval()

// Act
_timer.Start();
await Task.Delay(_interval * 5);
await Task.Delay(_interval * 10);
_timer.Pause();

// Assert
Expand Down
Loading