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
12 changes: 12 additions & 0 deletions e2e/fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,24 @@ import { FoundWordsPanel } from './pages/FoundWordsPanel'
import { FourtileStarsPanel } from './pages/FourtileStarsPanel'

interface Fixtures {
freshGame: Record<string, never>
board: GameBoardPage
foundWordsPanel: FoundWordsPanel
stars: FourtileStarsPanel
}

export const test = base.extend<Fixtures>({
freshGame: [
async ({ page }, use) => {
await page.goto('/')
await page.evaluate(() => {
localStorage.clear()
})
await page.reload()
await use({})
},
{ auto: true },
],
board: async ({ page }, use) => {
await use(new GameBoardPage(page))
},
Expand Down
36 changes: 35 additions & 1 deletion e2e/game-helpers.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { Page } from '@playwright/test'
import { expect, type Page } from '@playwright/test'
import { difference, sample, without } from 'lodash-es'
import type { GameBoardPage } from './pages/GameBoardPage'

async function getDataAttr(page: Page, attr: string): Promise<string[]> {
const value = await page.getByTestId('game-board').getAttribute(attr)
Expand Down Expand Up @@ -97,3 +98,36 @@ export async function tilesForWordFromPage(page: Page, word: string): Promise<st
if (!result) throw new Error(`Could not form word "${word}" from tiles: [${tileList.join(', ')}]`)
return result
}

interface PlayWordOptions {
/** Timeout in ms for the current-word-cleared synchronization after submitting. */
clearTimeout?: number
}

/**
* Plays a single word: resolves it to a tile sequence from the current board, taps those tiles,
* and submits, then waits for the current-word display to clear before returning.
*/
export async function playWord(
page: Page,
board: GameBoardPage,
word: string,
options: PlayWordOptions = {},
): Promise<void> {
const wordTiles = await tilesForWordFromPage(page, word)
await board.clickTiles(wordTiles)
await board.clickAdd()
await expect(board.getCurrentWord()).toHaveText('', { timeout: options.clearTimeout })
}

/** Plays every word in order, waiting for the board to settle between each. */
export async function playWords(
page: Page,
board: GameBoardPage,
wordList: string[],
options: PlayWordOptions = {},
): Promise<void> {
for (const word of wordList) {
await playWord(page, board, word, options)
}
}
24 changes: 4 additions & 20 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,
playWords,
} from './game-helpers'

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 @@ -151,13 +141,7 @@ test.describe('Gameplay', () => {
test.setTimeout(120_000)

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, await words(page), { clearTimeout: 10_000 })
})

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