Skip to content

Commit

Permalink
test: cleanup e2e tests (#101)
Browse files Browse the repository at this point in the history
  • Loading branch information
garrappachc authored Dec 10, 2024
1 parent 3749d6d commit 14c699f
Show file tree
Hide file tree
Showing 12 changed files with 20 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/games/plugins/launch-new-game.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const launchGame = debounce(async () => {
const slots = await queue.getSlots()
const map = await queue.getMapWinner()
await create(slots, map)
}, 1000)
}, 100)

export default fp(
// eslint-disable-next-line @typescript-eslint/require-await
Expand Down
1 change: 1 addition & 0 deletions tests/00-misc/03-accept-rules.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ test.describe('when user has not accepted the rules yet', () => {

test('accept rules', async ({ users }) => {
const page = await users.getFirst().page()
await page.goto('/')
await expect(page.getByTitle('Accept rules dialog')).toBeVisible()

const btn = page.getByRole('button', { name: 'I accept these rules' })
Expand Down
4 changes: 2 additions & 2 deletions tests/10-queue/01-update-player-count.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ import { QueuePage } from '../pages/queue.page'

authUsers('update player count', async ({ page, users }) => {
const queuePage = new QueuePage(page)
await queuePage.goto()

const p1 = await users.getNext().queuePage()
const p2 = await users.getNext().queuePage()

await Promise.all([queuePage.goto(), p1.goto(), p2.goto()])

await expect(queuePage.header()).toContainText('0/12')
await expect(queuePage.page).toHaveTitle(/\[0\/12\]/)
await p1.joinQueue(0)
Expand Down
1 change: 1 addition & 0 deletions tests/10-queue/02-vote-for-map.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { authUsers, expect } from '../fixtures/auth-users'

authUsers('vote for map', async ({ users }) => {
const page = await users.getFirst().queuePage()
await page.goto()
const mapBtn = page.voteForMapButton(0)
expect(await mapBtn.getAttribute('aria-checked')).toBe('false')

Expand Down
6 changes: 5 additions & 1 deletion tests/10-queue/03-mark-as-friend.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ import type { QueuePage } from '../pages/queue.page'

authUsers('mark as friend', async ({ users }) => {
const [medic1, medic2, soldier] = (await Promise.all(
users.getMany(3).map(async user => await user.queuePage()),
users.getMany(3).map(async user => {
const page = await user.queuePage()
await page.goto()
return page
}),
)) as [QueuePage, QueuePage, QueuePage]
await medic1.slot(10).join()
await medic2.slot(11).join()
Expand Down
1 change: 1 addition & 0 deletions tests/10-queue/04-everybody-leaves.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ authUsers('everybody leaves', async ({ steamIds, users }) => {
for (let i = 0; i < queueUsers.length; ++i) {
const steamId = queueUsers[i]!
const page = await users.bySteamId(steamId).queuePage()
await page.goto()
await page.joinQueue(i)
}

Expand Down
1 change: 1 addition & 0 deletions tests/10-queue/05-late-for-ready-up.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ authUsers('player is late for ready up', async ({ steamIds, users, page }) => {
await Promise.all(
queueUsers.map(async (steamId, i) => {
const page = await users.bySteamId(steamId).queuePage()
await page.goto()
await page.joinQueue(i)
}),
)
Expand Down
5 changes: 5 additions & 0 deletions tests/10-queue/07-pre-ready-up.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@ test.beforeEach(async ({ db }) => {

test('pre-ready up button is visible for logged-in-users', async ({ users }) => {
const page = await users.getNext().queuePage()
await page.goto()
await expect(page.preReadyUpButton()).toBeVisible()
})

test('pre-ready up button is enabled when a player joins the queue', async ({ users }) => {
const page = await users.getNext().queuePage()
await page.goto()
await expect(page.preReadyUpButton()).toBeDisabled()
await page.joinQueue(3)
await expect(page.preReadyUpButton()).toBeEnabled()
Expand All @@ -30,6 +32,7 @@ test('pre-ready up button is enabled when a player joins the queue', async ({ us

test('pre-ready expires', async ({ users }) => {
const page = await users.getNext().queuePage()
await page.goto()
await page.joinQueue(4)
await page.preReadyUpButton().click()
await expect(page.preReadyUpButton()).toHaveAttribute('aria-selected')
Expand All @@ -53,6 +56,7 @@ test('pre-ready up readies up when the queue is ready', async ({
await Promise.all(
preReadiedPlayers.map(async user => {
const page = await user.queuePage()
await page.goto()
const slot = desiredSlots.get(user.playerName)!
await page.slot(slot).join()
await page.preReadyUpButton().click()
Expand All @@ -61,6 +65,7 @@ test('pre-ready up readies up when the queue is ready', async ({

{
const page = await lastPlayer.queuePage()
await page.goto()
const slot = desiredSlots.get(lastPlayer.playerName)!
await page.slot(slot).join()
}
Expand Down
1 change: 1 addition & 0 deletions tests/90-admin/01-admin-panel.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { authUsers } from '../fixtures/auth-users'
authUsers.use({ steamIds: [users[0].steamId] })
authUsers('admin panel is visible & accessible', async ({ users }) => {
const adminsPage = await users.getAdmin().page()
await adminsPage.goto('/')
await adminsPage.getByRole('link', { name: 'Admin panel' }).click()
await adminsPage.waitForURL(/admin/)
})
1 change: 1 addition & 0 deletions tests/90-admin/02-force-end-game.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { expect, launchGame } from '../fixtures/launch-game'
launchGame('force end game', async ({ users, gameNumber }) => {
const admin = users.getAdmin()
const adminsPage = await admin.gamePage(gameNumber)
await adminsPage.goto()

await adminsPage.forceEnd()
await expect(adminsPage.gameEvent(`Game interrupted by ${admin.playerName}`)).toBeVisible()
Expand Down
1 change: 1 addition & 0 deletions tests/fixtures/launch-game.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export const launchGame = mergeTests(authUsers, simulateGameServer).extend<
await Promise.all(
players.map(async user => {
const page = await user.queuePage()
await page.goto()
const slot = desiredSlots.get(user.playerName)!
await page.slot(slot).join()
await page.readyUpDialog().readyUp()
Expand Down
1 change: 0 additions & 1 deletion tests/user-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ export class UserContext {
async page() {
if (!this._page) {
this._page = await this.browserContext.newPage()
await this._page.goto('/')
}
return this._page
}
Expand Down

0 comments on commit 14c699f

Please sign in to comment.