Admins need to find orders quickly and read full letter text without a cramped table column. - Make stat cards clickable filters (Totalt, Att göra, Betalda, Väntar) - Add search by partial order ID or registration number - Show shortened order ID in table with full ID on hover - Replace message column with "Visa meddelande" opening a modal - Keep expanded row for tracking only; remove duplicate brevtext block - Update AdminDashboard unit tests and admin-dashboard e2e specs
136 lines
4.5 KiB
TypeScript
136 lines
4.5 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.evaluate(() => localStorage.clear())
|
|
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.locator('.admin__plate').first()).toBeVisible()
|
|
await expect(page.getByText('DEF456').first()).toBeVisible()
|
|
await expect(page.getByText('GHI789').first()).toBeVisible()
|
|
})
|
|
|
|
test('show message button opens modal with full letter text', async ({
|
|
page,
|
|
}) => {
|
|
await page.goto('/admin')
|
|
|
|
await page
|
|
.locator('.admin__row', { hasText: 'ABC123' })
|
|
.getByRole('button', { name: 'Visa meddelande' })
|
|
.click()
|
|
|
|
const dialog = page.getByRole('dialog', { name: 'Brevtext' })
|
|
await expect(dialog).toBeVisible()
|
|
await expect(dialog).toContainText('fin bil')
|
|
await dialog.getByRole('button', { name: 'Stäng' }).click()
|
|
await expect(dialog).not.toBeVisible()
|
|
})
|
|
|
|
test('click expand button shows tracking section', async ({ page }) => {
|
|
await page.goto('/admin')
|
|
|
|
const expandBtns = page.locator('.admin__expand-btn')
|
|
await expandBtns.first().click()
|
|
|
|
await expect(page.getByText('Spårnings-ID').first()).toBeVisible()
|
|
})
|
|
|
|
test('click expand button again collapses it', async ({ page }) => {
|
|
await page.goto('/admin')
|
|
|
|
const expandBtns = page.locator('.admin__expand-btn')
|
|
await expandBtns.first().click()
|
|
await expect(page.locator('.admin__tracking-input').first()).toBeVisible()
|
|
|
|
await expandBtns.first().click()
|
|
await expect(page.locator('.admin__tracking-input').first()).not.toBeVisible()
|
|
})
|
|
|
|
test('status dropdown changes update order status', async ({ page }) => {
|
|
await page.goto('/admin')
|
|
|
|
const selects = page.locator('.admin__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.evaluate(() => localStorage.clear())
|
|
await page.goto('/admin')
|
|
|
|
await expect(page).toHaveURL(/\/logga-in\?redirect=\/admin/)
|
|
})
|
|
|
|
test('expanded row shows tracking input and save button', async ({ page }) => {
|
|
await page.goto('/admin')
|
|
|
|
const expandBtns = page.locator('.admin__expand-btn')
|
|
await expandBtns.first().click()
|
|
|
|
await expect(page.getByText('Spårnings-ID').first()).toBeVisible()
|
|
await expect(page.locator('.admin__tracking-input')).toBeVisible()
|
|
await expect(page.getByRole('button', { name: 'Spara' })).toBeVisible()
|
|
})
|
|
|
|
test('shows PostNord link when trackingId exists', async ({ page }) => {
|
|
await page.goto('/admin')
|
|
|
|
const expandBtns = page.locator('.admin__expand-btn')
|
|
await expandBtns.last().click()
|
|
|
|
const trackingLink = page.locator('.admin__tracking-link')
|
|
await expect(trackingLink).toBeVisible()
|
|
await expect(trackingLink).toHaveAttribute('href', /postnord/)
|
|
})
|
|
|
|
test('hides PostNord link when trackingId is null', async ({ page }) => {
|
|
await page.goto('/admin')
|
|
|
|
const defRow = page.locator('.admin__row', { hasText: 'DEF456' }).first()
|
|
const expandBtn = defRow.locator('.admin__expand-btn')
|
|
await expandBtn.click()
|
|
|
|
const trackingLink = page.locator('.admin__tracking-link')
|
|
await expect(trackingLink).not.toBeVisible()
|
|
})
|
|
})
|