Skip to content
Closed
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
14 changes: 14 additions & 0 deletions e2e/fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ interface Fixtures {
board: GameBoardPage
foundWordsPanel: FoundWordsPanel
stars: FourtileStarsPanel
// Auto-fixture that resets game state per test; it exposes no value to specs.
// eslint-disable-next-line @typescript-eslint/no-invalid-void-type
resetGame: void
}

export const test = base.extend<Fixtures>({
Expand All @@ -19,6 +22,17 @@ export const test = base.extend<Fixtures>({
stars: async ({ page }, use) => {
await use(new FourtileStarsPanel(page))
},
resetGame: [
async ({ page }, use) => {
await page.goto('/')
await page.evaluate(() => {
localStorage.clear()
})
await page.reload()
await use()
},
{ auto: true },
],
})

export { expect } from '@playwright/test'
34 changes: 34 additions & 0 deletions e2e/game-flows.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { expect } from '@playwright/test'
import type { Page } from '@playwright/test'
import type { GameBoardPage } from './pages/GameBoardPage'
import { tilesForWordFromPage } from './game-helpers'

/**
* Plays a single word: resolves the tiles that spell it, clicks them, clicks
* Add, and waits for the current word to clear before returning.
*/
export async function playWord(
page: Page,
board: GameBoardPage,
word: string,
timeout?: number,
): Promise<void> {
const wordTiles = await tilesForWordFromPage(page, word)
await board.clickTiles(wordTiles)
await board.clickAdd()
await expect(board.getCurrentWord()).toHaveText('', timeout ? { timeout } : undefined)
}

/**
* Plays every word in {@link words} in order, one after another.
*/
export async function playWords(
page: Page,
board: GameBoardPage,
words: string[],
timeout?: number,
): Promise<void> {
for (const word of words) {
await playWord(page, board, word, timeout)
}
}
23 changes: 4 additions & 19 deletions e2e/gameplay.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,13 @@ import {
fourtiles,
tiles,
words,
tilesForWordFromPage,
} from './game-helpers'
import { playWords } from './game-flows'

test.describe('Gameplay', () => {
let wordsRemaining: number

test.beforeEach(async ({ page, foundWordsPanel }) => {
await page.goto('/')
await page.evaluate(() => {
localStorage.clear()
})
await page.reload()
test.beforeEach(async ({ foundWordsPanel }) => {
wordsRemaining = parseInt(await foundWordsPanel.getWordsRemaining().innerText(), 10)
})

Expand Down Expand Up @@ -114,12 +109,7 @@ test.describe('Gameplay', () => {

test.beforeEach(async ({ page, board }) => {
fourtileWords = await fourtiles(page)
for (const fourtile of fourtileWords) {
const tiles = await tilesForWordFromPage(page, fourtile)
await board.clickTiles(tiles)
await board.clickAdd()
await expect(board.getCurrentWord()).toHaveText('')
}
await playWords(page, board, fourtileWords)
})

test('pops confetti', async ({ page }) => {
Expand Down Expand Up @@ -152,12 +142,7 @@ test.describe('Gameplay', () => {

test.beforeEach(async ({ page, board }) => {
const allWords = await words(page)
for (const word of allWords) {
const wordTiles = await tilesForWordFromPage(page, word)
await board.clickTiles(wordTiles)
await board.clickAdd()
await expect(board.getCurrentWord()).toHaveText('', { timeout: 10_000 })
}
await playWords(page, board, allWords, 10_000)
})

test('pops confetti and unicorns', async ({ page }) => {
Expand Down