Vitest (14 tests) — AdminDashboard.spec.ts:
- renders heading, subtitle, table columns, order data in rows
- shows loading, empty, and error states
- fetches GET /api/admin/orders on mount
- expands row on click to reveal letter content (Brevtext label)
- collapses row on second click
- only one row expanded at a time (clicking row 2 closes row 1)
- status dropdown change fires PATCH /api/admin/orders/{id}/status
with correct URL, method, and JSON body
- shows error message on failed status update
Playwright E2E (8 tests) — admin-dashboard.spec.ts:
- admin login (admin@bilhalsning.se / test1234) before each test
- admin can navigate to /admin and see heading
- non-admin user (test@bilhalsning.se) is redirected away from /admin
- table renders Datum/E-post/Regnr/Status column headers
- seeded order plates visible (ABC123, DEF456, GHI789)
- click row expands letter content
- click again collapses letter content
- status dropdown change persists (selectOption delivered)
- unauthenticated access redirects to login with ?redirect=/admin
84 lines
2.6 KiB
TypeScript
84 lines
2.6 KiB
TypeScript
import { test, expect } from '@playwright/test'
|
|
|
|
test.describe('Admin dashboard', () => {
|
|
test.beforeEach(async ({ page }) => {
|
|
await page.goto('/logga-in')
|
|
await page.getByLabel('E-postadress').fill('admin@bilhalsning.se')
|
|
await page.getByLabel('Lösenord').fill('test1234')
|
|
await page.getByRole('button', { name: 'Logga in' }).click()
|
|
await page.waitForURL('/')
|
|
})
|
|
|
|
test('admin can navigate to admin page', async ({ page }) => {
|
|
await page.goto('/admin')
|
|
|
|
await expect(
|
|
page.getByRole('heading', { name: 'Administration' }),
|
|
).toBeVisible()
|
|
})
|
|
|
|
test('non-admin user is redirected away from admin', async ({ page }) => {
|
|
await page.goto('/logga-in')
|
|
await page.getByLabel('E-postadress').fill('test@bilhalsning.se')
|
|
await page.getByLabel('Lösenord').fill('test1234')
|
|
await page.getByRole('button', { name: 'Logga in' }).click()
|
|
await page.waitForURL('/')
|
|
|
|
await page.goto('/admin')
|
|
|
|
await expect(page).toHaveURL('/')
|
|
})
|
|
|
|
test('shows orders table with columns', async ({ page }) => {
|
|
await page.goto('/admin')
|
|
|
|
await expect(page.getByText('Datum')).toBeVisible()
|
|
await expect(page.getByText('E-post')).toBeVisible()
|
|
await expect(page.getByText('Regnr')).toBeVisible()
|
|
await expect(page.getByText('Status')).toBeVisible()
|
|
})
|
|
|
|
test('shows seeded order data', async ({ page }) => {
|
|
await page.goto('/admin')
|
|
|
|
await expect(page.getByText('ABC123')).toBeVisible()
|
|
await expect(page.getByText('DEF456')).toBeVisible()
|
|
await expect(page.getByText('GHI789')).toBeVisible()
|
|
})
|
|
|
|
test('click row expands letter content', async ({ page }) => {
|
|
await page.goto('/admin')
|
|
|
|
const rows = page.locator('.admin-dashboard__row')
|
|
await rows.first().click()
|
|
|
|
await expect(page.getByText('Brevtext')).toBeVisible()
|
|
})
|
|
|
|
test('click expanded row collapses it', async ({ page }) => {
|
|
await page.goto('/admin')
|
|
|
|
const rows = page.locator('.admin-dashboard__row')
|
|
await rows.first().click()
|
|
await expect(page.getByText('Brevtext')).toBeVisible()
|
|
|
|
await rows.first().click()
|
|
await expect(page.getByText('Brevtext')).not.toBeVisible()
|
|
})
|
|
|
|
test('status dropdown changes update order status', async ({ page }) => {
|
|
await page.goto('/admin')
|
|
|
|
const selects = page.locator('.admin-dashboard__status-select')
|
|
await selects.first().selectOption('delivered')
|
|
|
|
const updatedSelect = selects.first()
|
|
await expect(updatedSelect).toHaveValue('delivered')
|
|
})
|
|
|
|
test('admin cannot access admin page without auth', async ({ page }) => {
|
|
await page.goto('/admin')
|
|
|
|
await expect(page).toHaveURL(/\/logga-in\?redirect=\/admin/)
|
|
})
|
|
})
|