Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.
Ruby b2b-commercee-commerceecommerceecommerce-apiecommerce-frameworkecommerce-platformheadlessheadless-commerceheadless-ecommercemarketplacemulti-tenantmulti-vendormulti-vendor-ecommerceopen-sourcespree-commerce
Added end-to-end tests for purchase order costs, stock transfers and stock receipts (#14915)
Damian Legawiecfc4e86b6df7a
diff --git a/CLAUDE.md b/CLAUDE.mdindex 59ba280469..9fea94bb5f 100644--- a/CLAUDE.md+++ b/CLAUDE.md@@ -809,6 +809,8 @@ cd packages/dashboard && pnpm test:e2e # full suitecd packages/dashboard && pnpm test:e2e:ui # Playwright UI mode (debug)```+**Every behaviour change or new feature ships with an E2E test.** If a merchant or seller can see the change in the Admin Dashboard or the Seller Panel, the same change adds or updates a Playwright spec that exercises it there: admin specs as `e2e/<resource>.spec.ts`, seller panel specs as `e2e/seller-<area>.spec.ts`. This applies to backend-only changes too, such as a validation, a status rule or a newly required field. Backend specs and unit tests prove the server refuses bad input; only the E2E test proves the dashboards still let users complete the flow.+The `login(page)` helper authenticates through the API (one POST plants the refresh cookie; the SPA's boot-time silent refresh does the rest) — only `auth.spec.ts` drives the login form itself.**Write UI-only assertions, like Capybara.** Drive the test through user-visible actions (fill labels, click buttons, find by role) and assert on visible UI. **Do not** reach for `page.waitForResponse(/api/...)` to wait for backend completion — it leaks API shape into tests and makes refactors painful. Playwright's `await expect(...).toBeVisible()` auto-polls until the condition is met (same as Capybara's `default_max_wait_time`), which covers virtually all cases.diff --git a/packages/dashboard/e2e/purchase-orders.spec.ts b/packages/dashboard/e2e/purchase-orders.spec.tsindex 3946f06cee..895df5140e 100644--- a/packages/dashboard/e2e/purchase-orders.spec.ts+++ b/packages/dashboard/e2e/purchase-orders.spec.ts@@ -94,13 +94,22 @@ test.describe('purchase orders', () => {await picker.getByRole('button', { name: /^add 1$/i }).click()await expect(picker).toBeHidden()await page.getByRole('spinbutton', { name: /^ordered$/i }).fill('12')++ // A new line starts without a cost: an unpriced order cannot be raised by accident.+ const createDraft = page.getByRole('button', { name: /create draft/i })+ await expect(page.getByLabel(/^unit cost$/i)).toHaveValue('')+ await expect(createDraft).toBeDisabled()await page.getByLabel(/^unit cost$/i).fill('7.50')+ await expect(createDraft).toBeEnabled()- await page.getByRole('button', { name: /create draft/i }).click()+ await createDraft.click()await expect(page).toHaveURL(/\/purchase-orders\/po_/, { timeout: 15_000 })await expect(page.getByText(/^draft$/i).first()).toBeVisible()await expect(page.getByText('0 received of 12 ordered')).toBeVisible()+ const line = page.getByRole('row').filter({ hasText: FIXTURE_TRANSFER_PRODUCT })+ await expect(line).toContainText('7.50')+ await expect(line).toContainText('90.00')await page.getByRole('button', { name: /mark as ordered/i }).click()await expect(page.getByRole('heading', { name: /place this order\?/i })).toBeVisible()@@ -144,7 +153,7 @@ test.describe('purchase orders', () => {await expect(page.getByText('Discontinued by the supplier')).toBeVisible()})- test('corrects a draft', async ({ page }) => {+ test('corrects a draft, but not into a line without a cost', async ({ page }) => {const creds = await login(page)const purchaseOrder = await createPurchaseOrder(page, creds.accessToken, { quantity: 3 })await openPurchaseOrder(page, creds.store_id, purchaseOrder)@@ -156,12 +165,65 @@ test.describe('purchase orders', () => {const reference = `Corrected ${Date.now()}`await page.locator('#reference').fill(reference)- await page.getByRole('button', { name: /^save$/i }).click()++ const unitCost = page.getByLabel(/^unit cost$/i)+ const save = page.getByRole('button', { name: /^save$/i })+ await expect(unitCost).toHaveValue('7.50')+ await unitCost.fill('')+ await expect(save).toBeDisabled()+ await unitCost.fill('8.25')+ await expect(save).toBeEnabled()+ await save.click()await expect(page.getByRole('heading', { name: purchaseOrder.number })).toBeVisible({timeout: 15_000,})await expect(page.getByText(reference)).toBeVisible()+ const line = page.getByRole('row').filter({ hasText: FIXTURE_TRANSFER_PRODUCT })+ await expect(line).toContainText('8.25')+ await expect(line).toContainText('24.75')+ })++ test('books each delivery as its own stock receipt', async ({ page }) => {+ const creds = await login(page)+ const purchaseOrder = await createPurchaseOrder(page, creds.accessToken, {+ quantity: 10,+ ordered: true,+ })+ await openPurchaseOrder(page, creds.store_id, purchaseOrder)+ await expect(page.getByText(/no deliveries yet/i)).toBeVisible()++ // The first delivery: six intact, one of the wrong item.+ const firstNote = `DN-1-${Date.now()}`+ await page.getByLabel(/^delivery note$/i).fill(firstNote)+ await page.getByLabel(/^accepted$/i).fill('6')+ await page.getByLabel(/^rejected$/i).fill('1')+ // A refusal has to say why before the delivery can be booked.+ const receive = page.getByRole('button', { name: /^receive$/i })+ await expect(receive).toBeDisabled()+ await page.getByLabel(/^reason$/i).click()+ await page.getByRole('option', { name: /^wrong item$/i }).click()+ await receive.click()++ await expect(page.getByText(/^partially received$/i).first()).toBeVisible({+ timeout: 15_000,+ })+ await expect(page.getByText('6 received of 10 ordered')).toBeVisible()+ await expect(page.getByText(firstNote)).toBeVisible()+ await expect(page.getByText('6 accepted · 1 rejected')).toBeVisible()+ await expect(page.getByRole('cell', { name: /^wrong item$/i })).toBeVisible()++ // A refused unit is still owed by the supplier, so the second delivery+ // brings its replacement with the rest, and closes the order.+ await page.getByLabel(/^accepted$/i).fill('4')+ await receive.click()++ await expect(page.getByText('10 received of 10 ordered')).toBeVisible({ timeout: 15_000 })+ await expect(page.getByText('4 accepted · 0 rejected')).toBeVisible()+ // Each delivery stays its own record rather than folding into the first.+ await expect(page.getByText(/^\d+ accepted · \d+ rejected$/)).toHaveCount(2)+ await expect(page.getByText('6 accepted · 1 rejected')).toBeVisible()+ await expect(page.getByText(/receive a delivery/i)).toHaveCount(0)})test('cancels a placed order after confirming', async ({ page }) => {diff --git a/packages/dashboard/e2e/stock-transfers.spec.ts b/packages/dashboard/e2e/stock-transfers.spec.tsindex 5904ec1872..0c390cc88a 100644--- a/packages/dashboard/e2e/stock-transfers.spec.ts+++ b/packages/dashboard/e2e/stock-transfers.spec.ts@@ -2,6 +2,7 @@ import { expect, test } from '@playwright/test'import {createInTransitTransfer,FIXTURE_TRANSFER_DESTINATION,+ FIXTURE_TRANSFER_PRODUCT,FIXTURE_TRANSFER_SKU,FIXTURE_TRANSFER_SOURCE,gotoIndex,@@ -44,6 +45,50 @@ test.describe('stock transfers', () => {await expect(page.getByText(/choose the warehouse it leaves from first/i)).toBeVisible()})+ test('raises a draft from the form, packs it and sends it', async ({ page }) => {+ const creds = await login(page)+ await gotoIndex(page, TRANSFERS_PATH(creds.store_id), CTA)+ await page.getByRole('button', { name: CTA }).click()+ await expect(page.getByRole('heading', { name: /new stock transfer/i })).toBeVisible()++ await page.locator('#source').click()+ await page.getByRole('option', { name: FIXTURE_TRANSFER_SOURCE }).click()+ await page.locator('#destination').click()+ await page.getByRole('option', { name: FIXTURE_TRANSFER_DESTINATION }).click()++ await page+ .getByRole('button', { name: /add a product/i })+ .first()+ .click()+ const picker = page.getByRole('dialog')+ await picker.getByRole('searchbox').fill(FIXTURE_TRANSFER_SKU)+ await picker.getByRole('button', { name: new RegExp(FIXTURE_TRANSFER_PRODUCT) }).click()+ await picker.getByRole('button', { name: /^add 1$/i }).click()+ await expect(picker).toBeHidden()+ await page.getByRole('spinbutton', { name: /^shipped$/i }).fill('3')+ // Transfers move stock the merchant already owns, so a line carries no cost.+ await expect(page.getByLabel(/^unit cost$/i)).toHaveCount(0)++ await page.getByRole('button', { name: /create draft/i }).click()++ await expect(page).toHaveURL(/\/transfers\/st_/, { timeout: 15_000 })+ await expect(page.getByText(/^draft$/i).first()).toBeVisible()++ await page.getByRole('button', { name: /mark as ready to ship/i }).click()+ await expect(page.getByText(/^ready to ship$/i).first()).toBeVisible({ timeout: 15_000 })++ await page.getByRole('button', { name: /mark in transit/i }).click()+ await expect(page.getByRole('heading', { name: /send this transfer\?/i })).toBeVisible()+ await page+ .getByRole('dialog')+ .getByRole('button', { name: /mark in transit/i })+ .click()++ await expect(page.getByText(/^in transit$/i).first()).toBeVisible({ timeout: 15_000 })+ await expect(page.getByText('0 received of 3 shipped')).toBeVisible()+ await expect(page.getByText(/no deliveries yet/i)).toBeVisible()+ })+test('sends a draft, then counts in a delivery with damage', async ({ page }) => {const creds = await login(page)const transfer = await createInTransitTransfer(page, creds.accessToken, {@@ -63,15 +108,53 @@ test.describe('stock transfers', () => {// Count in eight of the ten intact; the other two arrived crushed.await page.getByLabel(/^accepted$/i).fill('8')await page.getByLabel(/^rejected$/i).fill('2')+ // A refusal has to say why before the delivery can be booked.+ const receive = page.getByRole('button', { name: /^receive$/i })+ await expect(receive).toBeDisabled()await page.getByLabel(/^reason$/i).click()await page.getByRole('option', { name: /^damaged$/i }).click()- await page.getByRole('button', { name: /^receive$/i }).click()+ await receive.click()// Everything that left has arrived, so the trip is over — with the two// refused units on the delivery's record, not the shelf.await expect(page.getByText(/^received$/i).first()).toBeVisible({ timeout: 15_000 })await expect(page.getByText('8 received of 10 shipped')).toBeVisible()await expect(page.getByText(/8 accepted · 2 rejected/i)).toBeVisible()+ await expect(page.getByRole('cell', { name: /^damaged$/i })).toBeVisible()+ })++ test('counts a transfer in over two deliveries, each its own stock receipt', async ({ page }) => {+ const creds = await login(page)+ const transfer = await createInTransitTransfer(page, creds.accessToken, {+ sku: FIXTURE_TRANSFER_SKU,+ quantity: 6,+ })++ await page.goto(`${TRANSFERS_PATH(creds.store_id)}/${transfer.id}`)+ await expect(page.getByRole('heading', { name: transfer.number })).toBeVisible({+ timeout: 15_000,+ })++ const firstNote = `Van 1 ${Date.now()}`+ await page.getByLabel(/^delivery note$/i).fill(firstNote)+ await page.getByLabel(/^accepted$/i).fill('2')+ await page.getByRole('button', { name: /^receive$/i }).click()++ await expect(page.getByText(/^partially received$/i).first()).toBeVisible({+ timeout: 15_000,+ })+ await expect(page.getByText('2 received of 6 shipped')).toBeVisible()+ await expect(page.getByText(firstNote)).toBeVisible()++ // The rest of the load arrives on a second van.+ await page.getByLabel(/^accepted$/i).fill('4')+ await page.getByRole('button', { name: /^receive$/i }).click()++ await expect(page.getByText('6 received of 6 shipped')).toBeVisible({ timeout: 15_000 })+ await expect(page.getByText(/^\d+ accepted · \d+ rejected$/)).toHaveCount(2)+ await expect(page.getByText('2 accepted · 0 rejected')).toBeVisible()+ await expect(page.getByText('4 accepted · 0 rejected')).toBeVisible()+ await expect(page.getByText(/receive a delivery/i)).toHaveCount(0)})test('a draft can be corrected, a shipped one cannot', async ({ page }) => {