import { test, expect } from '@playwright/test' test.describe('Order history', () => { test('redirects unauthenticated user to login', async ({ page }) => { await page.goto('/orders') await expect(page).toHaveURL(/\/logga-in\?redirect=\/orders/) await expect(page.getByRole('heading', { name: 'Logga in' })).toBeVisible() }) test('can navigate from home to orders via header link', 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('/') const header = page.locator('header') await header.getByRole('link', { name: 'Mina beställningar' }).click() await expect(page).toHaveURL('/orders') await expect( page.getByRole('heading', { name: 'Mina beställningar' }), ).toBeVisible() }) test('displays page heading and seeded orders', 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('/orders') await expect(page.getByRole('heading', { name: 'Mina beställningar' })).toBeVisible() await expect(page.getByText('ABC123')).toBeVisible() await expect(page.getByText('DEF456')).toBeVisible() await expect(page.getByText('GHI789')).toBeVisible() }) test('shows correct status badges', 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('/orders') await expect(page.getByText('Skickat')).toBeVisible() await expect(page.getByText('Väntar på betalning')).toBeVisible() await expect(page.getByText('Levererat')).toBeVisible() }) test('shows tracking links for orders with tracking ID', 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('/orders') const trackingLink1 = page.getByRole('link', { name: 'PN123456789' }) await expect(trackingLink1).toBeVisible() await expect(trackingLink1).toHaveAttribute('href', /postnord/) await expect(trackingLink1).toHaveAttribute('target', '_blank') const trackingLink2 = page.getByRole('link', { name: 'PN987654321' }) await expect(trackingLink2).toBeVisible() }) test('shows template names', 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('/orders') await expect(page.getByText('Komplimang')).toBeVisible() await expect(page.getByText('Jag vill köpa din bil')).toBeVisible() await expect(page.getByText('Tips / servicebehov')).toBeVisible() }) })