Skip to content

Commit

Permalink
test(e2e): fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
garrappachc committed Aug 2, 2024
1 parent c818ce0 commit 00c5d04
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 21 deletions.
8 changes: 4 additions & 4 deletions playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ export default defineConfig<AuthUsersOptions>({
/* Run tests in files in parallel */
fullyParallel: true,
/* Fail the build on CI if you accidentally left test.only in the source code. */
forbidOnly: !!process.env['CI'],
forbidOnly: !!process.env.CI,
/* Retry on CI only */
retries: process.env['CI'] ? 2 : 0,
retries: process.env.CI ? 2 : 0,
/* Opt out of parallel tests on CI. */
workers: process.env['CI'] ? 1 : '50%',
workers: process.env.CI ? 1 : '50%',
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
reporter: 'html',
reporter: process.env.CI ? 'github' : 'html',
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
use: {
/* Base URL to use in actions like `await page.goto('/')`. */
Expand Down
2 changes: 1 addition & 1 deletion src/queue/views/html/queue-slot.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ function PlayerInfo(props: {
markAsFriendButtonState: MarkAsFriendButtonState | undefined
}) {
let slotButton = <></>
if (props.isActorsSlot) {
if (props.isActorsSlot && !props.ready) {
slotButton = (
<button class="leave-queue-button" name="leave" value="" aria-label="Leave queue">
<IconMinus />
Expand Down
21 changes: 16 additions & 5 deletions tests/10-queue/04-everybody-leaves.spec.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,27 @@
import { authUsers } from '../fixtures/auth-users'
import { minutesToMilliseconds } from 'date-fns'

authUsers('everybody leaves', async ({ steamIds, pages }) => {
authUsers.setTimeout(minutesToMilliseconds(2))
const queueUsers = steamIds.slice(0, 12)
for (let i = 0; i < queueUsers.length; ++i) {
const steamId = queueUsers[i]!
const page = pages.get(steamId)!

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

await Promise.all(
queueUsers.map(async (steamId, i) => {
queueUsers.slice(0, -1).map(async steamId => {
const page = pages.get(steamId)!

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

// wait for ready-up
// don't ready up
await page.getByRole('button', { name: `Can't play right now` }).click()
}),
)

// last player leaves
const page = pages.get(queueUsers[11]!)!
await page.getByLabel(`Leave queue`, { exact: true }).click({ timeout: minutesToMilliseconds(1) })
})
32 changes: 21 additions & 11 deletions tests/10-queue/05-late-for-ready-up.spec.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
import { authUsers, expect } from '../fixtures/auth-users'
import { minutesToMilliseconds } from 'date-fns'

authUsers('player is late for ready up', async ({ steamIds, pages, page }) => {
authUsers.setTimeout(minutesToMilliseconds(2))
const queueUsers = steamIds.slice(0, 12)
await Promise.all(
queueUsers.map(async (steamId, i) => {
const page = pages.get(steamId)!
for (let i = 0; i < queueUsers.length; ++i) {
const steamId = queueUsers[i]!
const page = pages.get(steamId)!

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

const readyUsers = queueUsers.slice(0, -1)
const readyUsers = queueUsers.slice(1, -1)
await Promise.all(
readyUsers.map(async user => {
const page = pages.get(user)!
Expand All @@ -21,12 +22,21 @@ authUsers('player is late for ready up', async ({ steamIds, pages, page }) => {
}),
)

// player gets kicked
await expect(page.getByRole('heading', { name: /^Players:/ })).toHaveText('Players: 11/12', {
timeout: 60000,
})

// player gets kicked
await expect(
pages.get(queueUsers[11]!)!.getByLabel(`Join queue on slot 11`, { exact: true }),
pages.get(queueUsers[0]!)!.getByLabel(`Join queue on slot 0`, { exact: true }),
).toBeVisible()

// everybody leaves the queue
await Promise.all(
queueUsers.slice(1).map(async steamId => {
const page = pages.get(steamId)!
await page
.getByLabel(`Leave queue`, { exact: true })
.click({ timeout: minutesToMilliseconds(1) })
}),
)
})
1 change: 1 addition & 0 deletions tests/fixtures/auth-users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export const authUsers = test.extend<AuthUsersOptions & AuthUsersFixture>({
)
await use(pages)
for (const page of pages.values()) {
await page.context().close()
await page.close()
}
pages.clear()
Expand Down

0 comments on commit 00c5d04

Please sign in to comment.