Skip to content

Commit

Permalink
test: cleanup test fixtures (#117)
Browse files Browse the repository at this point in the history
  • Loading branch information
garrappachc authored Dec 15, 2024
1 parent 6f4758d commit 104751e
Show file tree
Hide file tree
Showing 20 changed files with 223 additions and 235 deletions.
2 changes: 2 additions & 0 deletions src/games/views/html/game-slot.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ export async function GameSlot(props: {
[SlotStatus.replaced]: 'replaced',
}[props.slot.status],
]}
data-player={player.steamId}
data-status={props.slot.status}
>
<span class="sr-only" safe>
{player.name}'s slot
Expand Down
7 changes: 2 additions & 5 deletions tests/10-queue/01-update-player-count.spec.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
import { mergeTests } from '@playwright/test'
import { authUsers, expect } from '../fixtures/auth-users'
import { QueuePage } from '../pages/queue.page'
import { queuePage } from '../fixtures/queue-page'
import { waitForEmptyQueue } from '../fixtures/wait-for-empty-queue'

const test = mergeTests(authUsers, queuePage)
test.beforeEach(async ({ queue }) => {
await queue.waitToBeEmpty()
})
const test = mergeTests(authUsers, waitForEmptyQueue)

test('update player count', async ({ page, users }) => {
const queuePage = new QueuePage(page)
Expand Down
7 changes: 2 additions & 5 deletions tests/10-queue/02-vote-for-map.spec.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
import { mergeTests } from '@playwright/test'
import { authUsers, expect } from '../fixtures/auth-users'
import { queuePage } from '../fixtures/queue-page'
import { waitForEmptyQueue } from '../fixtures/wait-for-empty-queue'

const test = mergeTests(authUsers, queuePage)
test.beforeEach(async ({ queue }) => {
await queue.waitToBeEmpty()
})
const test = mergeTests(authUsers, waitForEmptyQueue)

test('vote for map', async ({ users }) => {
const page = await users.byName('SlitherTuft').queuePage()
Expand Down
8 changes: 2 additions & 6 deletions tests/10-queue/03-mark-as-friend.spec.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
import { mergeTests } from '@playwright/test'
import { authUsers, expect } from '../fixtures/auth-users'
import type { QueuePage } from '../pages/queue.page'
import { queuePage } from '../fixtures/queue-page'
import { waitForEmptyQueue } from '../fixtures/wait-for-empty-queue'

const test = mergeTests(authUsers, queuePage)

test.beforeEach(async ({ queue }) => {
await queue.waitToBeEmpty()
})
const test = mergeTests(authUsers, waitForEmptyQueue)

test('mark as friend', async ({ users }) => {
const [medic1, medic2, soldier] = (await Promise.all(
Expand Down
8 changes: 2 additions & 6 deletions tests/10-queue/04-everybody-leaves.spec.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
import { mergeTests } from '@playwright/test'
import { authUsers } from '../fixtures/auth-users'
import { minutesToMilliseconds } from 'date-fns'
import { queuePage } from '../fixtures/queue-page'
import { waitForEmptyQueue } from '../fixtures/wait-for-empty-queue'

const test = mergeTests(authUsers, queuePage)

test.beforeEach(async ({ queue }) => {
await queue.waitToBeEmpty()
})
const test = mergeTests(authUsers, waitForEmptyQueue)

test('everybody leaves', async ({ steamIds, users }) => {
authUsers.setTimeout(minutesToMilliseconds(2))
Expand Down
8 changes: 2 additions & 6 deletions tests/10-queue/05-late-for-ready-up.spec.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
import { mergeTests } from '@playwright/test'
import { authUsers, expect } from '../fixtures/auth-users'
import { minutesToMilliseconds } from 'date-fns'
import { queuePage } from '../fixtures/queue-page'
import { waitForEmptyQueue } from '../fixtures/wait-for-empty-queue'

const test = mergeTests(authUsers, queuePage)

test.beforeEach(async ({ queue }) => {
await queue.waitToBeEmpty()
})
const test = mergeTests(authUsers, waitForEmptyQueue)

test('player is late for ready up', async ({ steamIds, users, page }) => {
authUsers.setTimeout(minutesToMilliseconds(2))
Expand Down
22 changes: 3 additions & 19 deletions tests/10-queue/07-pre-ready-up.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,17 @@ import { mergeTests } from '@playwright/test'
import { accessMongoDb } from '../fixtures/access-mongo-db'
import { minutesToMilliseconds, secondsToMilliseconds } from 'date-fns'
import { launchGame, expect } from '../fixtures/launch-game'
import { queuePage } from '../fixtures/queue-page'
import { waitForEmptyQueue } from '../fixtures/wait-for-empty-queue'

const test = mergeTests(accessMongoDb, launchGame, queuePage)
const test = mergeTests(accessMongoDb, launchGame, waitForEmptyQueue)

test.beforeEach(async ({ db, queue }) => {
test.beforeEach(async ({ db }) => {
const configuration = db.collection('configuration')
await configuration.updateOne(
{ key: 'queue.pre_ready_up_timeout' },
{ $set: { value: secondsToMilliseconds(10) } },
{ upsert: true },
)
await queue.waitToBeEmpty()
})

test('pre-ready up button is visible for logged-in-users', async ({ users }) => {
Expand Down Expand Up @@ -124,19 +123,4 @@ test('pre-ready up enables automatically after readying up', async ({
await page.readyUpDialog().readyUp()
await expect(page.preReadyUpButton()).toHaveAttribute('aria-selected')
}

// await Promise.all(
// players.map(async user => {
// const page = await user.queuePage()
// const slot = desiredSlots.get(user.playerName)!

// if (!(await page.slot(slot).isReady())) {
// await page.readyUpDialog().notReady()
// }

// if (await page.slot(slot).isTaken()) {
// await page.leaveQueue(minutesToMilliseconds(1.5))
// }
// }),
// )
})
132 changes: 65 additions & 67 deletions tests/20-game/02-free-players.spec.ts
Original file line number Diff line number Diff line change
@@ -1,75 +1,73 @@
import { expect } from '@playwright/test'
import { waitABit } from '../utils/wait-a-bit'
import { secondsToMilliseconds } from 'date-fns'
import { launchGameAndInitialize } from '../fixtures/launch-game-and-initialize'
import { launchGame } from '../fixtures/launch-game'

launchGameAndInitialize(
'free players when the game ends',
async ({ players, gameServer, gameNumber }) => {
await Promise.all(
players.map(async player => {
const page = await player.queuePage()
await page.goto()
await expect(page.goBackToGameLink()).toBeVisible()
for (let i = 0; i < 12; ++i) {
await expect(page.slot(i).joinButton()).toBeDisabled()
}
}),
)
launchGame.use({ waitForStage: 'launching' })
launchGame('free players when the game ends', async ({ players, gameServer, gameNumber }) => {
await Promise.all(
players.map(async player => {
const page = await player.queuePage()
await page.goto()
await expect(page.goBackToGameLink()).toBeVisible()
for (let i = 0; i < 12; ++i) {
await expect(page.slot(i).joinButton()).toBeDisabled()
}
}),
)

await gameServer.connectAllPlayers()
await gameServer.matchStarts()
await waitABit(secondsToMilliseconds(3))
await gameServer.matchEnds()
await gameServer.connectAllPlayers()
await gameServer.matchStarts()
await waitABit(secondsToMilliseconds(3))
await gameServer.matchEnds()

const medics = ['AstraGirl', 'BellBoy']
const medics = ['AstraGirl', 'BellBoy']

// medics are freed before other players
await Promise.all([
...medics
.map(playerName => players.find(p => p.playerName === playerName)!)
.map(async player => {
const page = await player.queuePage()
await page.goto()
await Promise.all([
expect(page.goBackToGameLink()).not.toBeVisible({
timeout: secondsToMilliseconds(1),
}),
...Array.from(Array(12).keys()).map(
async i => await expect(page.slot(i).joinButton()).toBeEnabled(),
),
])
}),
...players
.filter(p => !medics.includes(p.playerName))
.map(async player => {
const page = await player.queuePage()
await page.goto()
await Promise.all([
expect(page.goBackToGameLink()).toBeVisible(),
...Array.from(Array(12).keys()).map(
async i => await expect(page.slot(i).joinButton()).toBeDisabled(),
),
])
}),
])
// medics are freed before other players
await Promise.all([
...medics
.map(playerName => players.find(p => p.playerName === playerName)!)
.map(async player => {
const page = await player.queuePage()
await page.goto()
await Promise.all([
expect(page.goBackToGameLink()).not.toBeVisible({
timeout: secondsToMilliseconds(1),
}),
...Array.from(Array(12).keys()).map(
async i => await expect(page.slot(i).joinButton()).toBeEnabled(),
),
])
}),
...players
.filter(p => !medics.includes(p.playerName))
.map(async player => {
const page = await player.queuePage()
await page.goto()
await Promise.all([
expect(page.goBackToGameLink()).toBeVisible(),
...Array.from(Array(12).keys()).map(
async i => await expect(page.slot(i).joinButton()).toBeDisabled(),
),
])
}),
])

// other players are freed after 5 seconds
await Promise.all(
players
.filter(p => !medics.includes(p.playerName))
.map(async player => {
const page = await player.queuePage()
await page.goto()
await Promise.all([
expect(page.goBackToGameLink()).not.toBeVisible({
timeout: secondsToMilliseconds(5),
}),
...Array.from(Array(12).keys()).map(
async i => await expect(page.slot(i).joinButton()).toBeEnabled(),
),
])
}),
)
},
)
// other players are freed after 5 seconds
await Promise.all(
players
.filter(p => !medics.includes(p.playerName))
.map(async player => {
const page = await player.queuePage()
await page.goto()
await Promise.all([
expect(page.goBackToGameLink()).not.toBeVisible({
timeout: secondsToMilliseconds(5),
}),
...Array.from(Array(12).keys()).map(
async i => await expect(page.slot(i).joinButton()).toBeEnabled(),
),
])
}),
)
})
6 changes: 1 addition & 5 deletions tests/20-game/03-update-player-connection-status.spec.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
import { secondsToMilliseconds } from 'date-fns'
import { expect, launchGame } from '../fixtures/launch-game'

launchGame.use({ waitForStage: 'launching' })
launchGame('update player connection status', async ({ players, gameNumber, gameServer }) => {
await Promise.all(
players.map(async player => {
const page = await player.gamePage(gameNumber)
await expect(page.gameEvent('Game server initialized')).toBeVisible({
timeout: secondsToMilliseconds(30),
})

const slot = page.playerSlot(player.playerName)
await expect(slot.getByLabel('Player connection status')).toHaveClass(/offline/)

Expand Down
7 changes: 4 additions & 3 deletions tests/20-game/04-cleanup-game-server.spec.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { minutesToMilliseconds, secondsToMilliseconds } from 'date-fns'
import { waitABit } from '../utils/wait-a-bit'
import { expect, launchGameAndStartMatch } from '../fixtures/launch-game-and-start-match'
import { expect, launchGame } from '../fixtures/launch-game'

launchGameAndStartMatch('cleanup game server', async ({ gameServer, gameNumber }) => {
launchGameAndStartMatch.setTimeout(minutesToMilliseconds(2))
launchGame.use({ waitForStage: 'started' })
launchGame('cleanup game server', async ({ gameServer, gameNumber }) => {
launchGame.setTimeout(minutesToMilliseconds(2))

await waitABit(secondsToMilliseconds(3))
await gameServer.matchEnds()
Expand Down
7 changes: 1 addition & 6 deletions tests/20-game/05-report-rounds.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,11 @@ import { expect, launchGame } from '../fixtures/launch-game'
import { GamePage } from '../pages/game.page'
import { waitABit } from '../utils/wait-a-bit'

launchGame.use({ waitForStage: 'started' })
launchGame('report rounds', async ({ gameNumber, page, gameServer }) => {
// wait for the gameserver to be configured
const gamePage = new GamePage(page, gameNumber)
await gamePage.goto()
await expect(gamePage.gameEvent('Game server assigned')).toBeVisible()
await expect(gamePage.gameEvent('Game server initialized')).toBeVisible({ timeout: 13000 })

await gameServer.connectAllPlayers()
await gameServer.matchStarts()
await waitABit(secondsToMilliseconds(1))

await expect(gamePage.page.getByLabel('blu team score')).toHaveText('0')
await expect(gamePage.page.getByLabel('red team score')).toHaveText('0')
Expand Down
5 changes: 3 additions & 2 deletions tests/30-player-substitutes/03-manages-in-game.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { secondsToMilliseconds } from 'date-fns'
import { expect, launchGameAndStartMatch } from '../fixtures/launch-game-and-start-match'
import { expect, launchGame } from '../fixtures/launch-game'

launchGameAndStartMatch('manages in-game', async ({ gameNumber, users, gameServer }) => {
launchGame.use({ waitForStage: 'started' })
launchGame('manages in-game', async ({ gameNumber, users, gameServer }) => {
const admin = users.getAdmin()

const adminsPage = await admin.gamePage(gameNumber)
Expand Down
9 changes: 2 additions & 7 deletions tests/40-bans/01-lock-queue.spec.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
import { mergeTests } from '@playwright/test'
import { authUsers, expect } from '../fixtures/auth-users'
import { queuePage } from '../fixtures/queue-page'

const test = mergeTests(authUsers, queuePage)

test.beforeEach(async ({ queue }) => {
await queue.waitToBeEmpty()
})
import { waitForEmptyQueue } from '../fixtures/wait-for-empty-queue'

const test = mergeTests(authUsers, waitForEmptyQueue)
test('banned player gets kicked from the queue', async ({ users }) => {
const playerPage = await users.byName('AstraGirl').queuePage()
await playerPage.goto()
Expand Down
Loading

0 comments on commit 104751e

Please sign in to comment.