Redesigns the order list so unpaid and paid orders share a consistent card layout, with clearer payment context and labeled metadata users need before paying via Swish. - Split list into Obetalda/Tidigare sections with pending orders first - Pending cards: preview box, labeled Beställnings-ID, price row, Betala 49 kr - Completed cards: same header/preview layout, prominent Spåra brev button - Replace em-dash pay label and update unit/E2E selectors Co-authored-by: Cursor <cursoragent@cursor.com>
144 lines
5.5 KiB
TypeScript
144 lines
5.5 KiB
TypeScript
import { test, expect } from '@playwright/test'
|
|
|
|
test.describe.configure({ mode: 'serial' })
|
|
|
|
function uniquePlate(prefix: string): string {
|
|
const digits = String((Date.now() % 90) + 10)
|
|
return `${prefix}${digits}E`
|
|
}
|
|
|
|
test.describe('Deferred payment and admin lookup', () => {
|
|
const plate = uniquePlate('LAT')
|
|
const letterText = 'E2E-test: betalar senare från orderhistoriken.'
|
|
|
|
let orderId = ''
|
|
let shortOrderId = ''
|
|
|
|
async function loginAsTestUser(page: import('@playwright/test').Page) {
|
|
await page.goto('/logga-in')
|
|
await page.getByLabel('E-postadress').fill('test@bilhej.se')
|
|
await page.getByLabel('Lösenord').fill('test1234')
|
|
await page.getByRole('button', { name: 'Logga in' }).click()
|
|
await page.waitForURL('/')
|
|
}
|
|
|
|
async function loginAsAdmin(page: import('@playwright/test').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('/')
|
|
}
|
|
|
|
async function completeSwishPayment(page: import('@playwright/test').Page) {
|
|
await page.getByRole('button', { name: 'Jag har betalat' }).click()
|
|
await page.getByRole('button', { name: 'Ja, jag har betalat' }).click()
|
|
}
|
|
|
|
test('user creates order, leaves payment, and pays later from orders', async ({
|
|
page,
|
|
}) => {
|
|
await loginAsTestUser(page)
|
|
|
|
await page.goto(`/compose?plate=${plate}`)
|
|
await page.getByLabel('Ditt meddelande').fill(letterText)
|
|
await page.getByRole('button', { name: 'Fortsätt till betalning' }).click()
|
|
|
|
await page.waitForURL(/\/betalning\/[a-f0-9-]+/i)
|
|
const match = page.url().match(/\/betalning\/([a-f0-9-]+)/i)
|
|
expect(match).not.toBeNull()
|
|
orderId = match![1]
|
|
shortOrderId = orderId.slice(0, 8)
|
|
|
|
await expect(page.locator('.payment__order-id')).toHaveText(orderId)
|
|
|
|
await page.goto('/')
|
|
await page.getByRole('link', { name: 'Mina beställningar' }).click()
|
|
await expect(page).toHaveURL('/orders')
|
|
|
|
const orderCard = page.locator('.orders__card', { hasText: orderId })
|
|
await expect(orderCard.getByText(plate)).toBeVisible()
|
|
await expect(orderCard.locator('.badge')).toHaveText('Väntar på betalning')
|
|
await expect(orderCard.getByRole('link', { name: 'Betala 49 kr' })).toBeVisible()
|
|
|
|
await orderCard.getByRole('link', { name: 'Betala 49 kr' }).click()
|
|
await expect(page).toHaveURL(new RegExp(`/betalning/${orderId}`))
|
|
await completeSwishPayment(page)
|
|
|
|
await expect(page).toHaveURL('/orders')
|
|
await expect(orderCard.locator('.badge')).toHaveText('Hanteras')
|
|
await expect(orderCard.getByRole('link', { name: 'Betala 49 kr' })).not.toBeVisible()
|
|
})
|
|
|
|
test('admin finds paid order under Att göra when searching partial order id', async ({
|
|
page,
|
|
}) => {
|
|
await loginAsAdmin(page)
|
|
await page.goto('/admin')
|
|
|
|
await page.getByRole('button', { name: /Att göra/ }).click()
|
|
await page.locator('#admin-order-search').fill(shortOrderId)
|
|
|
|
const row = page.locator('.admin__row', { hasText: shortOrderId })
|
|
await expect(row).toBeVisible()
|
|
await expect(row.locator('.admin__order-id')).toHaveText(shortOrderId)
|
|
await expect(row.locator('.admin__plate')).toHaveText(plate)
|
|
await expect(row).toHaveClass(/admin__row--todo/)
|
|
})
|
|
|
|
test('admin finds paid order when searching full order id', async ({ page }) => {
|
|
await loginAsAdmin(page)
|
|
await page.goto('/admin')
|
|
|
|
await page.getByRole('button', { name: /Att göra/ }).click()
|
|
await page.locator('#admin-order-search').fill(orderId)
|
|
|
|
const row = page.locator('.admin__row', { hasText: shortOrderId })
|
|
await expect(row).toBeVisible()
|
|
await expect(row.locator('.admin__order-id')).toHaveText(shortOrderId)
|
|
await expect(row.locator('.admin__plate')).toHaveText(plate)
|
|
})
|
|
|
|
test('admin finds paid order when searching registration number', async ({
|
|
page,
|
|
}) => {
|
|
await loginAsAdmin(page)
|
|
await page.goto('/admin')
|
|
|
|
await page.getByRole('button', { name: /Att göra/ }).click()
|
|
await page.locator('#admin-order-search').fill(plate)
|
|
|
|
const row = page.locator('.admin__row', { hasText: shortOrderId })
|
|
await expect(row).toBeVisible()
|
|
await expect(row.locator('.admin__plate')).toHaveText(plate)
|
|
})
|
|
|
|
test('admin does not show unpaid order under Att göra before payment', async ({
|
|
page,
|
|
}) => {
|
|
await loginAsTestUser(page)
|
|
|
|
const unpaidPlate = uniquePlate('UNP')
|
|
await page.goto(`/compose?plate=${unpaidPlate}`)
|
|
await page.getByLabel('Ditt meddelande').fill('E2E-test: ska ligga under Väntar.')
|
|
await page.getByRole('button', { name: 'Fortsätt till betalning' }).click()
|
|
await page.waitForURL(/\/betalning\/([a-f0-9-]+)/i)
|
|
const unpaidMatch = page.url().match(/\/betalning\/([a-f0-9-]+)/i)
|
|
const unpaidOrderId = unpaidMatch![1]
|
|
const unpaidShortId = unpaidOrderId.slice(0, 8)
|
|
await page.goto('/orders')
|
|
|
|
await page.evaluate(() => localStorage.clear())
|
|
await loginAsAdmin(page)
|
|
await page.goto('/admin')
|
|
await page.getByRole('button', { name: /Att göra/ }).click()
|
|
|
|
const unpaidRow = page.locator('.admin__row', { hasText: unpaidShortId })
|
|
await expect(unpaidRow).not.toBeVisible()
|
|
|
|
await page.getByRole('button', { name: /Väntar/ }).click()
|
|
await page.locator('#admin-order-search').fill(unpaidPlate)
|
|
await expect(unpaidRow).toBeVisible()
|
|
await expect(unpaidRow.locator('.admin__plate')).toHaveText(unpaidPlate)
|
|
})
|
|
})
|