test(board): unit + e2e tests for board posts and channels

This commit is contained in:
Jennie Robinson Faber 2026-04-14 17:36:12 +01:00
parent f3df1945bd
commit 5fb069a80e
4 changed files with 707 additions and 0 deletions

View file

@ -0,0 +1,64 @@
import { test, expect } from './helpers/fixtures.js'
test.describe('Admin board channels page', () => {
test('page loads for admin', async ({ adminPage }) => {
await adminPage.goto('/admin/board-channels')
await expect(adminPage.getByRole('heading', { name: 'Board Channels' })).toBeVisible({
timeout: 15000,
})
await expect(adminPage.getByRole('button', { name: '+ New Channel' })).toBeVisible()
})
test('create, edit, and delete a channel', async ({ adminPage }) => {
await adminPage.goto('/admin/board-channels')
await expect(adminPage.getByRole('heading', { name: 'Board Channels' })).toBeVisible({
timeout: 15000,
})
const suffix = Date.now().toString().slice(-6)
const channelName = `e2e-channel-${suffix}`
const editedName = `e2e-channel-${suffix}-edited`
const slackId = `C${suffix}XYZ`
// --- Create ---
await adminPage.getByRole('button', { name: '+ New Channel' }).click()
await expect(adminPage.getByRole('heading', { name: 'New Channel' })).toBeVisible()
await adminPage.locator('input[placeholder="e.g., #coop-formation"]').fill(channelName)
await adminPage.locator('input[placeholder="C0123456789"]').fill(slackId)
// Select the first available cooperative tag if any are present
const firstTagCheckbox = adminPage.locator('.tag-select input[type="checkbox"]').first()
if (await firstTagCheckbox.isVisible().catch(() => false)) {
await firstTagCheckbox.check()
}
await adminPage.getByRole('button', { name: 'Create Channel' }).click()
await expect(adminPage.getByRole('cell', { name: channelName })).toBeVisible({
timeout: 10000,
})
// --- Edit ---
const row = adminPage.locator('tr', { hasText: channelName })
await row.getByRole('button', { name: 'Edit' }).click()
await expect(adminPage.getByRole('heading', { name: 'Edit Channel' })).toBeVisible()
const nameInput = adminPage.locator('input[placeholder="e.g., #coop-formation"]')
await nameInput.fill(editedName)
await adminPage.getByRole('button', { name: 'Save Changes' }).click()
await expect(adminPage.getByRole('cell', { name: editedName })).toBeVisible({
timeout: 10000,
})
// --- Delete (confirm dialog) ---
adminPage.once('dialog', (dialog) => dialog.accept())
const editedRow = adminPage.locator('tr', { hasText: editedName })
await editedRow.getByRole('button', { name: 'Delete' }).click()
await expect(adminPage.getByRole('cell', { name: editedName })).not.toBeVisible({
timeout: 10000,
})
})
})

87
e2e/board.spec.js Normal file
View file

@ -0,0 +1,87 @@
import { test, expect } from './helpers/fixtures.js'
test.describe('Board page', () => {
test('page loads for authenticated member', async ({ memberPage }) => {
await memberPage.goto('/board')
await expect(memberPage.getByRole('heading', { name: 'Board' })).toBeVisible({ timeout: 15000 })
await expect(memberPage.getByRole('button', { name: '+ New Post' }).first()).toBeVisible()
})
test('clicking New Post reveals the form', async ({ memberPage }) => {
await memberPage.goto('/board')
await expect(memberPage.getByRole('button', { name: '+ New Post' }).first()).toBeVisible({
timeout: 15000,
})
await memberPage.getByRole('button', { name: '+ New Post' }).first().click()
await expect(memberPage.getByRole('heading', { name: 'New post' })).toBeVisible()
await expect(memberPage.locator('#post-title')).toBeVisible()
await expect(memberPage.locator('#post-seeking')).toBeVisible()
})
test('tags drawer toggles open and closed', async ({ memberPage }) => {
await memberPage.goto('/board')
await expect(memberPage.getByRole('heading', { name: 'Board' })).toBeVisible({ timeout: 15000 })
const drawerToggle = memberPage.getByRole('button', { name: /^Tags\.\.\./ })
// Drawer toggle only appears if cooperative tags exist — skip quietly if not
if (!(await drawerToggle.isVisible().catch(() => false))) {
test.skip(true, 'No cooperative tags seeded in this environment')
return
}
await drawerToggle.click()
await expect(memberPage.getByText('Filter:')).toBeVisible()
await drawerToggle.click()
await expect(memberPage.getByText('Filter:')).not.toBeVisible()
})
test('create, edit, and delete own post', async ({ memberPage }) => {
await memberPage.goto('/board')
await expect(memberPage.getByRole('button', { name: '+ New Post' }).first()).toBeVisible({
timeout: 15000,
})
const uniqueSuffix = Date.now().toString().slice(-6)
const originalTitle = `E2E test post ${uniqueSuffix}`
const editedTitle = `E2E test post edited ${uniqueSuffix}`
// --- Create ---
await memberPage.getByRole('button', { name: '+ New Post' }).first().click()
await expect(memberPage.getByRole('heading', { name: 'New post' })).toBeVisible()
await memberPage.locator('#post-title').fill(originalTitle)
await memberPage.locator('#post-seeking').fill('Playwright test seeking text')
await memberPage.getByRole('button', { name: 'Post' }).click()
await expect(memberPage.getByRole('heading', { name: originalTitle })).toBeVisible({
timeout: 10000,
})
// --- Edit ---
// Find the post card containing our title, then click its Edit button
const postCard = memberPage.locator('article.board-post', { hasText: originalTitle })
await postCard.getByRole('button', { name: 'Edit' }).click()
await expect(memberPage.getByRole('heading', { name: 'Edit post' })).toBeVisible()
const titleInput = memberPage.locator('#post-title')
await titleInput.fill(editedTitle)
await memberPage.getByRole('button', { name: 'Save changes' }).click()
await expect(memberPage.getByRole('heading', { name: editedTitle })).toBeVisible({
timeout: 10000,
})
// --- Delete (confirm dialog) ---
memberPage.once('dialog', (dialog) => dialog.accept())
const editedCard = memberPage.locator('article.board-post', { hasText: editedTitle })
await editedCard.getByRole('button', { name: 'Delete' }).click()
await expect(memberPage.getByRole('heading', { name: editedTitle })).not.toBeVisible({
timeout: 10000,
})
})
})