Skip to content

Commit

Permalink
test(e2e): use QueuePage in launchGame fixture
Browse files Browse the repository at this point in the history
  • Loading branch information
garrappachc committed Aug 6, 2024
1 parent 5a89fae commit 1679587
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
10 changes: 5 additions & 5 deletions tests/fixtures/launch-game.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Mutex } from 'async-mutex'
import { GamePage } from '../pages/game.page'
import { mergeTests } from '@playwright/test'
import { simulateGameServer } from './simulate-game-server'
import { QueuePage } from '../pages/queue.page'

export const launchGame = mergeTests(authUsers, simulateGameServer).extend<{
gameNumber: number
Expand All @@ -19,20 +20,19 @@ export const launchGame = mergeTests(authUsers, simulateGameServer).extend<{
const mutex = new Mutex()
await Promise.all(
queueUsers.map(async (user, i) => {
const page = pages.get(user)!
const page = new QueuePage(pages.get(user)!)

await mutex.runExclusive(async () => {
// join the queue
await page.getByLabel(`Join queue on slot ${i}`, { exact: true }).click()
await page.slot(i).join()
})

// last player joining the queue is ready by default
if (i !== 11) {
// wait for ready-up
await page.getByRole('button', { name: `I'M READY` }).click()
await page.readyUpDialog().readyUp()
}

await page.waitForURL(/games\/(\d+)/)
await page.page.waitForURL(/games\/(\d+)/)
}),
)

Expand Down
14 changes: 13 additions & 1 deletion tests/pages/queue.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@ class QueueSlot {
this.locator = this.page.getByLabel(`Queue slot ${this.slotNumber}`, { exact: true })
}

joinButton() {
return this.page.getByLabel(`Join queue on slot ${this.slotNumber}`, { exact: true })
}

async join() {
await this.joinButton().click()
}

markAsFriendButton() {
return this.locator.getByRole('button', { name: 'Mark as friend' })
}
Expand All @@ -29,7 +37,7 @@ class ReadyUpDialog {
}

export class QueuePage {
constructor(private readonly page: Page) {}
constructor(public readonly page: Page) {}

async goto() {
await this.page.goto('/')
Expand All @@ -43,6 +51,10 @@ export class QueuePage {
await this.page.getByLabel(`Leave queue`, { exact: true }).click({ timeout })
}

slot(slot: number) {
return new QueueSlot(this.page, slot)
}

queueSlot(slot: number) {
return this.page.getByLabel(`Queue slot ${slot}`, { exact: true })
}
Expand Down

0 comments on commit 1679587

Please sign in to comment.