bilhej/frontend/e2e/login.spec.ts
Joakim Mörling 2506a0283c test: update Vitest and E2E specs for redesigned UI
- Update HomePage specs: new headline, CTA class from btn--success to btn--primary
- Update ComposePage specs: new button text, brand name in GDPR footer
- Update PaymentRedirect specs: button text, class, and test payment note
- Update TemplatePicker specs: remove emoji icon assertion
- Update AdminDashboard specs: expand button selectors instead of row clicks
- Update AppHeader specs: BilHälsning to Bilhej brand text
- Update AboutPage specs: BilHälsning to Bilhej heading
- Update App specs: new homepage headline text
- Update OrdersPage specs: badge class renames
- Update LoginPage specs: form name/action attribute tests
- Update E2E compose specs: button text, GDPR footer brand name
- Update E2E payment specs: button text and note selectors
- Update E2E admin-dashboard specs: expand button and tracking label selectors
- Update E2E header-auth specs: new test additions for admin visibility
2026-05-16 16:11:58 +02:00

65 lines
2.1 KiB
TypeScript

import { test, expect } from '@playwright/test'
test.describe('Login page', () => {
test('can navigate to login page', async ({ page }) => {
await page.goto('/logga-in')
await expect(page.getByRole('heading', { name: 'Logga in' })).toBeVisible()
})
test('shows error for invalid credentials', async ({ page }) => {
await page.goto('/logga-in')
await page.getByLabel('E-postadress').fill('user@example.com')
await page.getByLabel('Lösenord').fill('wrongpassword')
await page.getByRole('button', { name: 'Logga in' }).click()
await expect(page.getByText('Felaktig e-post eller lösenord')).toBeVisible()
})
test('redirects to home after successful login', 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 expect(page).toHaveURL('/')
})
test('can navigate from login to register', async ({ page }) => {
await page.goto('/logga-in')
await page.getByRole('link', { name: 'Skapa konto' }).click()
await expect(page).toHaveURL('/registrera')
await expect(
page.getByRole('heading', { name: 'Skapa konto' }),
).toBeVisible()
})
test('login form has correct input types', async ({ page }) => {
await page.goto('/logga-in')
await expect(page.getByLabel('E-postadress')).toHaveAttribute(
'type',
'email',
)
await expect(page.getByLabel('Lösenord')).toHaveAttribute(
'type',
'password',
)
})
test('login form has name attributes and form action', async ({ page }) => {
await page.goto('/logga-in')
const form = page.locator('form')
await expect(form).toHaveAttribute('method', 'post')
await expect(form).toHaveAttribute('action', '/api/auth/login')
await expect(page.getByLabel('E-postadress')).toHaveAttribute(
'name',
'email',
)
await expect(page.getByLabel('Lösenord')).toHaveAttribute(
'name',
'password',
)
})
})