Skip to content

armgit / spree

Public Imported from GitHub
0

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.

Add more Admin SPA e2e tests (#14039)

Damian Legawiec2a9d0c0a2911
diff --git a/CLAUDE.md b/CLAUDE.md
index fa01453e1e..0f1518ca72 100644
--- a/CLAUDE.md
+++ b/CLAUDE.md
@@ -561,3 +561,38 @@ Re-run `parallel_setup` after schema changes.
```bash
cd packages/sdk && pnpm test # SDK tests (uses MSW for HTTP mocking)
```
+
+### Admin SPA E2E (Playwright)
+
+End-to-end tests for `packages/admin` live in `packages/admin/e2e/`. The global setup boots a real Rails test server (port 3010) + Vite dev (port 5174) once and seeds the DB; specs then exercise the SPA through a browser against that stack.
+
+```bash
+cd packages/admin && pnpm test:e2e # full suite
+cd packages/admin && pnpm test:e2e:ui # Playwright UI mode (debug)
+```
+
+**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.
+
+```ts
+// ✅ Capybara-style: drive the UI, assert on the UI.
+await page.getByLabel(/^label$/i).fill('Color')
+await page.getByRole('button', { name: /create option type/i }).click()
+await expect(page.getByRole('button', { name: 'color' })).toBeVisible({ timeout: 15_000 })
+
+// ❌ Avoid: couples the test to API shape, brittle on refactor.
+await Promise.all([
+ page.waitForResponse((res) => /\/api\/v3\/admin\/option_types/.test(res.url()) && res.status() === 201),
+ page.getByRole('button', { name: /create option type/i }).click(),
+])
+```
+
+The narrow exceptions where API-level waits are justified:
+- **No UI feedback** — a mutation kicks off background work (e.g., a webhook fire-and-forget) and there's nothing visible to assert against.
+- **Optimistic UI** — success state appears in the DOM before the API confirms; a UI-only assertion can't distinguish "rendered and persisted" from "rendered but later failed."
+
+Both are rare in the admin SPA, which renders success states only after mutations resolve.
+
+**Conventions:**
+- Use `Date.now()` suffixes on names so leftover rows from earlier specs don't collide (the suite runs serially — `fullyParallel: false, workers: 1`).
+- Disambiguate duplicate button names (e.g., a "Delete" in the sheet footer + another in a confirm dialog) by scoping: `page.getByRole('dialog').getByRole('button', { name: /^delete$/i })`.
+- Reference: `e2e/option-types.spec.ts`, `e2e/invitation-acceptance.spec.ts`.
diff --git a/packages/admin/e2e/auth.spec.ts b/packages/admin/e2e/auth.spec.ts
index 421c5b5f5b..4f67913501 100644
--- a/packages/admin/e2e/auth.spec.ts
+++ b/packages/admin/e2e/auth.spec.ts
@@ -1,5 +1,5 @@
import { expect, test } from '@playwright/test'
-import { getCredentials } from './fixtures'
+import { getCredentials } from './helpers'
test.describe('admin authentication', () => {
test('signs in via the login form and lands on the dashboard', async ({ page }) => {
diff --git a/packages/admin/e2e/customers.spec.ts b/packages/admin/e2e/customers.spec.ts
new file mode 100644
index 0000000000..02200f67a4
--- /dev/null
+++ b/packages/admin/e2e/customers.spec.ts
@@ -0,0 +1,123 @@
+import { expect, type Page, test } from '@playwright/test'
+import { fillAddressForm, gotoIndex, login } from './helpers'
+
+const CUSTOMERS_PATH = (storeId: string) => `/${storeId}/customers`
+const CTA = /new customer/i
+
+async function createCustomer(page: Page, email: string) {
+ await page.getByRole('button', { name: /new customer/i }).click()
+ await expect(page.getByRole('heading', { name: /^new customer$/i })).toBeVisible()
+ await page.locator('#email').fill(email)
+ await page.getByRole('button', { name: /^create customer$/i }).click()
+ await expect(page.getByRole('heading', { name: email })).toBeVisible({ timeout: 15_000 })
+}
+
+test.describe('customers', () => {
+ test('lists customers', async ({ page }) => {
+ const creds = await login(page)
+ await gotoIndex(page, CUSTOMERS_PATH(creds.store_id), CTA)
+ })
+
+ test('creates a new customer', async ({ page }) => {
+ const creds = await login(page)
+ await gotoIndex(page, CUSTOMERS_PATH(creds.store_id), CTA)
+
+ const email = `e2e-create-${Date.now()}@example.com`
+ await createCustomer(page, email)
+
+ // Back to the index, the row appears.
+ await gotoIndex(page, CUSTOMERS_PATH(creds.store_id), CTA)
+ await expect(page.getByRole('link', { name: email })).toBeVisible({ timeout: 15_000 })
+ })
+
+ test('edits a customer profile', async ({ page }) => {
+ const creds = await login(page)
+ await gotoIndex(page, CUSTOMERS_PATH(creds.store_id), CTA)
+
+ const email = `e2e-edit-${Date.now()}@example.com`
+ await createCustomer(page, email)
+
+ // `<CardTitle>` renders as a `<div>` (not an `<h*>`), so we scope by text
+ // and pick the first Edit button under it.
+ const profileCard = page.locator('div').filter({
+ has: page.getByText('Profile', { exact: true }),
+ })
+ await profileCard
+ .getByRole('button', { name: /^edit$/i })
+ .first()
+ .click()
+ await expect(page.getByRole('heading', { name: /^edit customer$/i })).toBeVisible()
+
+ await page.locator('#first_name').fill('Pat')
+ await page.locator('#last_name').fill('Smith')
+ await page.getByRole('button', { name: /^save$/i }).click()
+
+ await expect(page.getByRole('heading', { name: 'Pat Smith' })).toBeVisible({ timeout: 15_000 })
+ })
+
+ test('adds an address', async ({ page }) => {
+ const creds = await login(page)
+ await gotoIndex(page, CUSTOMERS_PATH(creds.store_id), CTA)
+
+ const email = `e2e-addr-${Date.now()}@example.com`
+ await createCustomer(page, email)
+
+ await page.getByRole('button', { name: /add address/i }).click()
+ await expect(page.getByRole('heading', { name: /^add address$/i })).toBeVisible()
+
+ await fillAddressForm(page, {
+ firstName: 'Pat',
+ lastName: 'Smith',
+ address1: '1 Main St',
+ city: 'Anytown',
+ postalCode: '12345',
+ phone: '555-0100',
+ country: 'United States',
+ state: 'California',
+ })
+ await page.getByRole('button', { name: /^save$/i }).click()
+
+ await expect(page.getByText('1 Main St')).toBeVisible({ timeout: 15_000 })
+ })
+
+ test('issues store credit', async ({ page }) => {
+ const creds = await login(page)
+ await gotoIndex(page, CUSTOMERS_PATH(creds.store_id), CTA)
+
+ const email = `e2e-credit-${Date.now()}@example.com`
+ await createCustomer(page, email)
+
+ await page.getByRole('button', { name: /issue credit/i }).click()
+ await expect(page.getByRole('heading', { name: /issue store credit/i })).toBeVisible()
+
+ await page.locator('#sc-amount').fill('25.00')
+ await page.locator('#sc-memo').fill('E2E test credit')
+ await page.locator('#sc-category').click()
+ await page.getByRole('option').first().click()
+
+ await page.getByRole('button', { name: /^issue credit$/i }).click()
+
+ await expect(page.getByText(/25\.00/).first()).toBeVisible({ timeout: 15_000 })
+ })
+
+ test('deletes a customer', async ({ page }) => {
+ const creds = await login(page)
+ await gotoIndex(page, CUSTOMERS_PATH(creds.store_id), CTA)
+
+ const email = `e2e-delete-${Date.now()}@example.com`
+ await createCustomer(page, email)
+
+ // PageHeader's more-actions dropdown holds the destructive Delete entry.
+ await page.getByRole('button', { name: /more actions/i }).click()
+ await page.getByRole('menuitem', { name: /delete customer/i }).click()
+ await page
+ .getByRole('dialog')
+ .getByRole('button', { name: /delete customer/i })
+ .click()
+
+ await expect(page).toHaveURL(new RegExp(`/${creds.store_id}/customers(?:\\?|$)`), {
+ timeout: 15_000,
+ })
+ await expect(page.getByRole('link', { name: email })).toHaveCount(0, { timeout: 15_000 })
+ })
+})
diff --git a/packages/admin/e2e/fixtures.ts b/packages/admin/e2e/fixtures.ts
deleted file mode 100644
index abbb1ea9a1..0000000000
--- a/packages/admin/e2e/fixtures.ts
+++ /dev/null
@@ -1,19 +0,0 @@
-import { readFileSync } from 'node:fs'
-import { CREDENTIALS_FILE } from './paths'
-
-export interface E2ECredentials {
- api_url: string
- admin_email: string
- admin_password: string
- store_id: string
- store_name: string
-}
-
-let cached: E2ECredentials | null = null
-
-export function getCredentials(): E2ECredentials {
- if (!cached) {
- cached = JSON.parse(readFileSync(CREDENTIALS_FILE, 'utf-8'))
- }
- return cached!
-}
diff --git a/packages/admin/e2e/global-setup.ts b/packages/admin/e2e/global-setup.ts
index 5e9041a353..eac13d4006 100644
--- a/packages/admin/e2e/global-setup.ts
+++ b/packages/admin/e2e/global-setup.ts
@@ -1,6 +1,14 @@
import { type ChildProcess, spawn, spawnSync } from 'node:child_process'
import { unlinkSync, writeFileSync } from 'node:fs'
import { resolve } from 'node:path'
+import {
+ FIXTURE_PROMO_CUSTOMER_EMAIL,
+ FIXTURE_PROMO_CUSTOMER_FIRST_NAME,
+ FIXTURE_PROMO_CUSTOMER_FULL_NAME,
+ FIXTURE_PROMO_CUSTOMER_GROUP,
+ FIXTURE_PROMO_PRODUCT,
+ FIXTURE_PROMO_TAXON,
+} from './helpers'
import { CREDENTIALS_FILE, E2E_DIR, RAILS_PID_FILE } from './paths'
const API_GEM_DIR = resolve(E2E_DIR, '../../../spree/api')
@@ -10,8 +18,13 @@ const TEST_SQLITE = resolve(API_GEM_DIR, 'spec/dummy/db/spree_test.sqlite3')
const RAILS_ENV = { ...process.env, RAILS_ENV: 'test', PORT }
-// One runner invocation pays the Bundler/Rails boot tax once instead of three
-// times. Final `puts` emits the credentials JSON the spec files read.
+// Customer's last name is derived from the full name so the seeder and the
+// matching `full_name` assertion in promotions.spec stay in sync.
+const FIXTURE_PROMO_CUSTOMER_LAST_NAME = FIXTURE_PROMO_CUSTOMER_FULL_NAME.replace(
+ `${FIXTURE_PROMO_CUSTOMER_FIRST_NAME} `,
+ '',
+)
+
const BOOTSTRAP_RUBY = [
"load Rails.root.join('db', 'schema.rb').to_s",
'Spree::Seeds::All.call',
@@ -20,6 +33,15 @@ const BOOTSTRAP_RUBY = [
'admin = Spree.admin_user_class.first || Spree.admin_user_class.create!(email: "[email protected]", password: "spree123", password_confirmation: "spree123")',
'admin.update!(password: "spree123", password_confirmation: "spree123")',
's.add_user(admin, Spree::Role.default_admin_role) unless s.role_users.exists?(user: admin)',
+ // Idempotent fixtures for promotion rule/action editor specs. Customer
+ // groups have no admin UI yet, so this is the only path to seed one.
+ `taxonomy = s.taxonomies.find_or_create_by!(name: 'Categories')`,
+ `category = taxonomy.taxons.where(name: '${FIXTURE_PROMO_TAXON}').first_or_create!(parent: taxonomy.root)`,
+ `shipping_category = Spree::ShippingCategory.first || Spree::ShippingCategory.create!(name: 'Default')`,
+ `product = Spree::Product.where(name: '${FIXTURE_PROMO_PRODUCT}').first_or_create!(price: 19.99, shipping_category: shipping_category, stores: [s], status: 'active')`,
+ `product.taxons << category unless product.taxons.include?(category)`,
+ `Spree.user_class.where(email: '${FIXTURE_PROMO_CUSTOMER_EMAIL}').first_or_create! { |u| u.password = 'customer123'; u.password_confirmation = 'customer123'; u.first_name = '${FIXTURE_PROMO_CUSTOMER_FIRST_NAME}'; u.last_name = '${FIXTURE_PROMO_CUSTOMER_LAST_NAME}' }`,
+ `s.customer_groups.where(name: '${FIXTURE_PROMO_CUSTOMER_GROUP}').first_or_create!`,
'port = ENV.fetch("PORT", 3010)',
'puts JSON.generate(api_url: "http://localhost:#{port}", admin_email: admin.email, admin_password: "spree123", store_id: s.prefixed_id, store_name: s.name)',
].join('; ')
diff --git a/packages/admin/e2e/helpers.ts b/packages/admin/e2e/helpers.ts
new file mode 100644
index 0000000000..546812462f
--- /dev/null
+++ b/packages/admin/e2e/helpers.ts
@@ -0,0 +1,114 @@
+import { readFileSync } from 'node:fs'
+import { expect, type Page } from '@playwright/test'
+import { CREDENTIALS_FILE } from './paths'
+
+/**
+ * Fixture records seeded once in `global-setup.ts`. Specs that exercise
+ * resource pickers (promotion rule/action editors, etc.) reference them
+ * by name to make matching deterministic.
+ */
+export const FIXTURE_PROMO_TAXON = 'E2E Promo Category'
+export const FIXTURE_PROMO_PRODUCT = 'E2E Promo Product'
+export const FIXTURE_PROMO_CUSTOMER_EMAIL = '[email protected]'
+export const FIXTURE_PROMO_CUSTOMER_FIRST_NAME = 'Promo'
+export const FIXTURE_PROMO_CUSTOMER_FULL_NAME = 'Promo Customer'
+export const FIXTURE_PROMO_CUSTOMER_GROUP = 'E2E Promo Group'
+export const FIXTURE_PROMO_COUNTRY = 'United States'
+
+export interface E2ECredentials {
+ api_url: string
+ admin_email: string
+ admin_password: string
+ store_id: string
+ store_name: string
+}
+
+let cached: E2ECredentials | null = null
+
+export function getCredentials(): E2ECredentials {
+ if (!cached) {
+ cached = JSON.parse(readFileSync(CREDENTIALS_FILE, 'utf-8'))
+ }
+ return cached
+}
+
+/**
+ * Drive the admin login flow as a precondition for any spec that needs an
+ * authenticated session. Returns the credentials so callers can immediately
+ * navigate into a specific store (e.g. `/${creds.store_id}/products/options`).
+ *
+ * Not used by `auth.spec.ts` — that spec exercises the login flow itself.
+ */
+export async function login(page: Page): Promise<E2ECredentials> {
+ const creds = getCredentials()
+ await page.goto('/login')
+ await page.getByLabel(/email/i).fill(creds.admin_email)
+ await page.getByLabel(/password/i).fill(creds.admin_password)
+ await page.getByRole('button', { name: /^login$/i }).click()
+ await expect(page).not.toHaveURL(/\/login/, { timeout: 15_000 })
+ return creds
+}
+
+/**
+ * Navigate to a resource index page and wait for it to settle. Every new
+ * spec needs the same shape: visit the URL, wait for the page's primary
+ * call-to-action button to appear (proves auth + data have loaded).
+ */
+export async function gotoIndex(page: Page, path: string, ctaButtonName: RegExp) {
+ await page.goto(path)
+ await expect(page.getByRole('button', { name: ctaButtonName })).toBeVisible({ timeout: 15_000 })
+}
+
+/**
+ * Locator for the `<ResourceNameCell>` button on a resource index table.
+ * The cell's accessible name is `"<name> <secondary?>"` and a sibling icon
+ * `<Button aria-label="Edit <name>">` may exist, so we anchor with `^` plus
+ * a word-boundary follow-up to disambiguate. `escapeRegex` keeps dynamic
+ * test names (`"E2E Foo (updated)"`) from being parsed as regex syntax.
+ */
+export function rowButton(page: Page, name: string) {
+ return page.getByRole('button', { name: new RegExp(`^${escapeRegex(name)}(\\s|$)`) })
+}
+
+function escapeRegex(s: string) {
+ return s.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')
+}
+
+export interface AddressInput {
+ firstName?: string
+ lastName?: string
+ address1?: string
+ city?: string
+ postalCode?: string
+ phone?: string
+ /** Custom label shown when the address-form-dialog renders one (only on some surfaces). */
+ label?: string
+ /** Country name to pick in the `<CountryCombobox>`. Server requires it. */
+ country?: string
+ /** State name to pick when the country has a state list. Omit for countries without one. */
+ state?: string
+}
+
+/**
+ * Fill the shared `<AddressFormDialog>` Sheet ("Add address" / "Edit address").
+ * The country picker is a Base UI Combobox; we drive it by typing into the
+ * input (placeholder "Search countries...") and clicking the matching option.
+ * Same pattern for the state combobox when the country needs one.
+ */
+export async function fillAddressForm(page: Page, address: AddressInput) {
+ if (address.label !== undefined) await page.locator('#addr-label').fill(address.label)
+ if (address.firstName !== undefined) await page.locator('#addr-fn').fill(address.firstName)
+ if (address.lastName !== undefined) await page.locator('#addr-ln').fill(address.lastName)
+ if (address.address1 !== undefined) await page.locator('#addr-a1').fill(address.address1)
+ if (address.city !== undefined) await page.locator('#addr-city').fill(address.city)
+ if (address.postalCode !== undefined) await page.locator('#addr-zip').fill(address.postalCode)
+ if (address.phone !== undefined) await page.locator('#addr-phone').fill(address.phone)
+ if (address.country) {
+ await page.getByPlaceholder('Search countries...').fill(address.country)
+ await page.getByRole('option', { name: address.country }).first().click()
+ }
+ if (address.state) {
+ await page.getByPlaceholder('Search states...').fill(address.state)
+ await page.getByRole('option', { name: address.state }).first().click()
+ }
+}
diff --git a/packages/admin/e2e/invitation-acceptance.spec.ts b/packages/admin/e2e/invitation-acceptance.spec.ts
index ad910de4ce..b9802eb382 100644
--- a/packages/admin/e2e/invitation-acceptance.spec.ts
+++ b/packages/admin/e2e/invitation-acceptance.spec.ts
@@ -1,20 +1,14 @@
import { expect, test } from '@playwright/test'
-import { getCredentials } from './fixtures'
+import { login } from './helpers'
test.describe('invitation lifecycle', () => {
test('admin invites a teammate and the invitee signs up via the link', async ({
page,
browser,
}) => {
- const creds = getCredentials()
+ const creds = await login(page)
const inviteeEmail = `e2e-invitee-${Date.now()}@example.com`
- await page.goto('/login')
- await page.getByLabel(/email/i).fill(creds.admin_email)
- await page.getByLabel(/password/i).fill(creds.admin_password)
- await page.getByRole('button', { name: /^login$/i }).click()
- await expect(page).not.toHaveURL(/\/login/, { timeout: 15_000 })
-
await page.goto(`/${creds.store_id}/settings/staff`)
await expect(page.getByText(/^staff$/i).first()).toBeVisible({ timeout: 15_000 })
@@ -25,6 +19,9 @@ test.describe('invitation lifecycle', () => {
await page.getByLabel(/role/i).click()
await page.getByRole('option').first().click()
+ // API wait justified per CLAUDE.md: `acceptance_url` is normally
+ // emailed, not surfaced in the admin UI, so there's no DOM signal to
+ // pull the link from.
const [createResponse] = await Promise.all([
page.waitForResponse(
(res) =>
diff --git a/packages/admin/e2e/option-types.spec.ts b/packages/admin/e2e/option-types.spec.ts
new file mode 100644
index 0000000000..5d25b70552
--- /dev/null
+++ b/packages/admin/e2e/option-types.spec.ts
@@ -0,0 +1,118 @@
+import { expect, type Page, test } from '@playwright/test'
+import { gotoIndex, login, rowButton } from './helpers'
+
+const OPTIONS_PATH = (storeId: string) => `/${storeId}/products/options`
+const CTA = /add option type/i
+
+async function createOptionType(
+ page: Page,
+ attrs: { internalName: string; label: string; values?: Array<{ name: string; label: string }> },
+) {
+ await page.getByRole('button', { name: /add option type/i }).click()
+ await expect(page.getByRole('heading', { name: /add option type/i })).toBeVisible()
+
+ // Use `#label` / `#name` directly — row-level option-value inputs also
+ // expose accessible names of "Label" / "Internal name", and `getByLabel`'s
+ // strict mode rejects ambiguous matches once a value row exists.
+ await page.locator('#label').fill(attrs.label)
+ await page.locator('#name').fill(attrs.internalName)
+
+ for (const [i, value] of (attrs.values ?? []).entries()) {
+ await page.getByRole('button', { name: /add option value/i }).click()
+ const row = page
+ .locator('tbody tr')
+ .filter({ has: page.getByLabel('Internal name') })
+ .nth(i)
+ await row.getByLabel('Internal name').fill(value.name)
+ await row.getByLabel('Label').fill(value.label)
+ }
+
+ await page.getByRole('button', { name: /create option type/i }).click()
+}
+
+test.describe('option types', () => {
+ test('lists option types', async ({ page }) => {
+ const creds = await login(page)
+ await gotoIndex(page, OPTIONS_PATH(creds.store_id), CTA)
+ })
+
+ test('creates a new option type with option values', async ({ page }) => {
+ const creds = await login(page)
+ await gotoIndex(page, OPTIONS_PATH(creds.store_id), CTA)
+
+ const suffix = Date.now()
+ const internalName = `e2e-size-${suffix}`
+ const label = `E2E Size ${suffix}`
+
+ await createOptionType(page, {
+ internalName,
+ label,
+ values: [
+ { name: 'small', label: 'Small' },
+ { name: 'medium', label: 'Medium' },
+ ],
+ })
+
+ await expect(rowButton(page, internalName)).toBeVisible({ timeout: 15_000 })
+ await expect(page.getByText(label)).toBeVisible()
+ })
+
+ test('edits an option type with option values', async ({ page }) => {
+ const creds = await login(page)
+ await gotoIndex(page, OPTIONS_PATH(creds.store_id), CTA)
+
+ const suffix = Date.now()
+ const internalName = `e2e-edit-${suffix}`
+ const originalLabel = `E2E Edit ${suffix}`
+ const updatedLabel = `${originalLabel} (updated)`
+
+ await createOptionType(page, {
+ internalName,
+ label: originalLabel,
+ values: [{ name: 'one', label: 'One' }],
+ })
+ await expect(rowButton(page, internalName)).toBeVisible({ timeout: 15_000 })
+
+ await rowButton(page, internalName).click()
+ await expect(page.getByRole('heading', { name: internalName })).toBeVisible({ timeout: 15_000 })
+ await expect(page.locator('#label')).toHaveValue(originalLabel)
+
+ await page.locator('#label').fill(updatedLabel)
+
+ await page.getByRole('button', { name: /add option value/i }).click()
+ const secondRow = page
+ .locator('tbody tr')
+ .filter({ has: page.getByLabel('Internal name') })
+ .nth(1)
+ await secondRow.getByLabel('Internal name').fill('two')
+ await secondRow.getByLabel('Label').fill('Two')
+
+ await page.getByRole('button', { name: /^save$/i }).click()
+
+ await expect(page.getByText(updatedLabel)).toBeVisible({ timeout: 15_000 })
+ })
+
+ test('deletes an option type', async ({ page }) => {
+ const creds = await login(page)
+ await gotoIndex(page, OPTIONS_PATH(creds.store_id), CTA)
+
+ const suffix = Date.now()
+ const internalName = `e2e-delete-${suffix}`
+ const label = `E2E Delete ${suffix}`
+
+ await createOptionType(page, { internalName, label })
+ await expect(rowButton(page, internalName)).toBeVisible({ timeout: 15_000 })
+
+ await rowButton(page, internalName).click()
+ await expect(page.getByRole('heading', { name: internalName })).toBeVisible({ timeout: 15_000 })
+
+ await page.getByRole('button', { name: /^delete$/i }).click()
+ await expect(page.getByRole('heading', { name: /delete option type\?/i })).toBeVisible()
+ await page
+ .getByRole('dialog')
+ .getByRole('button', { name: /^delete$/i })
+ .click()
+
+ await expect(rowButton(page, internalName)).toHaveCount(0, { timeout: 15_000 })
+ })
+})
diff --git a/packages/admin/e2e/payment-methods.spec.ts b/packages/admin/e2e/payment-methods.spec.ts
new file mode 100644
index 0000000000..817e469cfb
--- /dev/null
+++ b/packages/admin/e2e/payment-methods.spec.ts
@@ -0,0 +1,109 @@
+import { expect, type Page, test } from '@playwright/test'
+import { gotoIndex, login, rowButton } from './helpers'
+
+const PAYMENT_METHODS_PATH = (storeId: string) => `/${storeId}/settings/payment-methods`
+const CTA = /add payment method/i
+
+async function selectProvider(page: Page, label: string) {
+ await page.locator('#type').click()
+ await page.getByRole('option', { name: label }).click()
+}
+
+// Each provider can only be installed once per store (the "types" endpoint
+// filters out already-installed providers from the picker). Tests run
+// serially against a shared DB, so each lifecycle test claims a different
+// provider so they don't starve each other.
+test.describe.configure({ mode: 'serial' })
+
+test.describe('payment methods', () => {
+ test('lists payment methods', async ({ page }) => {
+ const creds = await login(page)
+ await gotoIndex(page, PAYMENT_METHODS_PATH(creds.store_id), CTA)
+ })
+
+ // Runs BEFORE the lifecycle tests so both providers it switches between are
+ // still in the dropdown (the lifecycle tests below consume them).
+ test('swaps the preferences editor when the provider changes', async ({ page }) => {
+ const creds = await login(page)
+ await gotoIndex(page, PAYMENT_METHODS_PATH(creds.store_id), CTA)
+
+ await page.getByRole('button', { name: /add payment method/i }).click()
+ await expect(page.getByRole('heading', { name: /add payment method/i })).toBeVisible()
+
+ // Bogus has two `preference` fields (`dummy_key` + `dummy_secret_key`).
+ // Check has none. Picking each in turn proves the preferences panel
+ // swaps with the provider — the core UX promise of the create flow.
+ await selectProvider(page, 'Bogus')
+ await expect(page.getByText(/dummy key/i).first()).toBeVisible({ timeout: 5_000 })
+ await expect(page.getByText(/dummy secret key/i).first()).toBeVisible()
+
+ await selectProvider(page, 'Check')
+ await expect(page.getByText(/dummy key/i)).toHaveCount(0)
+ await expect(page.getByText(/dummy secret key/i)).toHaveCount(0)
+ })
+
+ test('creates a new payment method (Bogus provider)', async ({ page }) => {
+ const creds = await login(page)
+ await gotoIndex(page, PAYMENT_METHODS_PATH(creds.store_id), CTA)
+
+ const name = `E2E Bogus ${Date.now()}`
+
+ await page.getByRole('button', { name: /add payment method/i }).click()
+ await expect(page.getByRole('heading', { name: /add payment method/i })).toBeVisible()
+
+ await selectProvider(page, 'Bogus')
+ await page.locator('#name').fill(name)
+ await page.getByRole('button', { name: /create payment method/i }).click()
+
+ await expect(rowButton(page, name)).toBeVisible({ timeout: 15_000 })
+ })
+
+ test('edits a payment method', async ({ page }) => {
+ const creds = await login(page)
+ await gotoIndex(page, PAYMENT_METHODS_PATH(creds.store_id), CTA)
+
+ const suffix = Date.now()
+ const original = `E2E Edit PM ${suffix}`
+ const updated = `${original} (updated)`
+
+ await page.getByRole('button', { name: /add payment method/i }).click()
+ await selectProvider(page, 'Check')
+ await page.locator('#name').fill(original)
+ await page.getByRole('button', { name: /create payment method/i }).click()
+ await expect(rowButton(page, original)).toBeVisible({ timeout: 15_000 })
+
+ await rowButton(page, original).click()
+ await expect(page.getByRole('heading', { name: original })).toBeVisible({ timeout: 15_000 })
+ await expect(page.locator('#name')).toHaveValue(original)
+
+ await page.locator('#name').fill(updated)
+ await page.getByRole('button', { name: /^save$/i }).click()
+
+ await expect(rowButton(page, updated)).toBeVisible({ timeout: 15_000 })
+ })
+
+ test('deletes a payment method', async ({ page }) => {
+ const creds = await login(page)
+ await gotoIndex(page, PAYMENT_METHODS_PATH(creds.store_id), CTA)
+
+ const name = `E2E Delete PM ${Date.now()}`
+
+ await page.getByRole('button', { name: /add payment method/i }).click()
+ await selectProvider(page, 'Custom Payment Source Method')
+ await page.locator('#name').fill(name)
+ await page.getByRole('button', { name: /create payment method/i }).click()
+ await expect(rowButton(page, name)).toBeVisible({ timeout: 15_000 })
+
+ await rowButton(page, name).click()
+ await expect(page.getByRole('heading', { name })).toBeVisible({ timeout: 15_000 })
+
+ await page.getByRole('button', { name: /^delete$/i }).click()
+ await expect(page.getByRole('heading', { name: /delete payment method\?/i })).toBeVisible()
+ await page
+ .getByRole('dialog')
+ .getByRole('button', { name: /^delete$/i })
+ .click()
+
+ await expect(rowButton(page, name)).toHaveCount(0, { timeout: 15_000 })
+ })
+})
diff --git a/packages/admin/e2e/promotions.spec.ts b/packages/admin/e2e/promotions.spec.ts
new file mode 100644
index 0000000000..9eb2ec25dc
--- /dev/null
+++ b/packages/admin/e2e/promotions.spec.ts
@@ -0,0 +1,324 @@
+import { expect, type Page, test } from '@playwright/test'
+import {
+ FIXTURE_PROMO_COUNTRY,
+ FIXTURE_PROMO_CUSTOMER_FIRST_NAME,
+ FIXTURE_PROMO_CUSTOMER_FULL_NAME,
+ FIXTURE_PROMO_CUSTOMER_GROUP,
+ FIXTURE_PROMO_PRODUCT,
+ FIXTURE_PROMO_TAXON,
+ gotoIndex,
+ login,
+ rowButton,
+} from './helpers'
+
+async function startNewPromotion(page: Page, storeId: string, name: string) {
+ await page.getByRole('button', { name: /new promotion/i }).click()
+ await expect(page).toHaveURL(new RegExp(`/${storeId}/promotions/new`), { timeout: 15_000 })
+ await expect(page.getByRole('heading', { name: /^new promotion$/i })).toBeVisible({
+ timeout: 15_000,
+ })
+ await page.locator('#name').fill(name)
+ // Kind defaults to "Coupon code"; switch to automatic so we don't have to
+ // generate a code each time.
+ await page.locator('#kind').click()
+ await page.getByRole('option', { name: /automatic/i }).click()
+}
+
+async function pickRule(page: Page, ruleLabel: RegExp) {
+ await page.getByRole('button', { name: /^add rule$/i }).click()
+ await expect(page.getByRole('heading', { name: /^add rule$/i })).toBeVisible()
+ await page.getByRole('button', { name: ruleLabel }).click()
+}
+
+async function pickAction(page: Page, actionLabel: RegExp) {
+ await page.getByRole('button', { name: /^add action$/i }).click()
+ await expect(page.getByRole('heading', { name: /^add action$/i })).toBeVisible()
+ await page.getByRole('button', { name: actionLabel }).click()
+}
+
+async function cancelEditor(page: Page) {
+ await page
+ .getByRole('dialog')
+ .getByRole('button', { name: /^cancel$/i })
+ .click()
+}
+
+async function saveEditor(page: Page) {
+ await page
+ .getByRole('dialog')
+ .getByRole('button', { name: /^save$/i })
+ .click()
+}
+
+// Base UI's Combobox closes the dropdown on select; don't press Escape because
+// the keydown bubbles up to the Sheet and dismisses the entire editor.
+async function pickAutocompleteOption(page: Page, placeholderRegex: RegExp, optionLabel: string) {
+ const input = page.getByRole('dialog').getByPlaceholder(placeholderRegex)
+ await input.fill(optionLabel)
+ await page
+ .getByRole('option', { name: new RegExp(optionLabel, 'i') })
+ .first()
+ .click()
+}
+
+async function submitCreate(page: Page, name: string) {
+ await page.getByRole('button', { name: /^create promotion$/i }).click()
+ await expect(page.getByRole('heading', { name })).toBeVisible({ timeout: 15_000 })
+}
+
+const PROMOTIONS_PATH = (storeId: string) => `/${storeId}/promotions`
+const CTA = /new promotion/i
+
+test.describe('promotions', () => {
+ test('lists promotions', async ({ page }) => {
+ const creds = await login(page)
+ await gotoIndex(page, PROMOTIONS_PATH(creds.store_id), CTA)
+ })
+
+ test('creates an automatic promotion with a rule and an action', async ({ page }) => {
+ const creds = await login(page)
+ await gotoIndex(page, PROMOTIONS_PATH(creds.store_id), CTA)
+
+ const name = `E2E Promo ${Date.now()}`
+
+ await startNewPromotion(page, creds.store_id, name)
+
+ // No-preference rule + action: pick the type to append the draft, then
+ // cancel to close the editor (Save is disabled when there's nothing to
+ // configure).
+ await pickRule(page, /^first order$/i)
+ await expect(page.getByRole('heading', { name: /^first order$/i })).toBeVisible({
+ timeout: 5_000,
+ })
+ await cancelEditor(page)
+
+ await pickAction(page, /^free shipping$/i)
+ await cancelEditor(page)
+
+ await submitCreate(page, name)
+ })
+
+ test('removes a rule and an action while editing', async ({ page }) => {
+ const creds = await login(page)
+ await gotoIndex(page, PROMOTIONS_PATH(creds.store_id), CTA)
+
+ const name = `E2E Promo Edit ${Date.now()}`
+
+ await startNewPromotion(page, creds.store_id, name)
+
+ await pickRule(page, /^first order$/i)
+ await cancelEditor(page)
+
+ await pickAction(page, /^free shipping$/i)
+ await cancelEditor(page)
+
+ await submitCreate(page, name)
+
+ await expect(page.getByText(/^first order$/i).first()).toBeVisible()
+ await expect(page.getByText(/^free shipping$/i).first()).toBeVisible()
+
+ // Rule/action rows are flex containers holding an edit button (with the
+ // rule label) and a trash button. Scope by the row's class so we don't
+ // pick up unrelated buttons in ancestor wrappers.
+ const ruleRow = page.locator('div.items-stretch').filter({ hasText: 'First order' }).first()
+ await ruleRow.getByRole('button').last().click()
+ await expect(page.getByRole('heading', { name: /remove rule\?/i })).toBeVisible()
+ await page
+ .getByRole('dialog')
+ .getByRole('button', { name: /^remove$/i })
+ .click()
+ await expect(page.getByText(/^first order$/i)).toHaveCount(0, { timeout: 5_000 })
+
+ const actionRow = page.locator('div.items-stretch').filter({ hasText: 'Free shipping' }).first()
+ await actionRow.getByRole('button').last().click()
+ await expect(page.getByRole('heading', { name: /remove action\?/i })).toBeVisible()
+ await page
+ .getByRole('dialog')
+ .getByRole('button', { name: /^remove$/i })
+ .click()
+ await expect(page.getByText(/^free shipping$/i)).toHaveCount(0, { timeout: 5_000 })
+
+ await page.getByRole('button', { name: /^save$/i }).click()
+ })
+
+ // Each test below exercises one custom rule/action editor end-to-end: the
+ // editor opens, the resource picker resolves a fixture record (seeded in
+ // global-setup.ts), and Save round-trips through the server.
+
+ test('creates a promotion with a Country rule', async ({ page }) => {
+ const creds = await login(page)
+ await gotoIndex(page, PROMOTIONS_PATH(creds.store_id), CTA)
+
+ const name = `E2E Country Promo ${Date.now()}`
+ await startNewPromotion(page, creds.store_id, name)
+
+ await pickRule(page, /^country$/i)
+ await expect(page.getByRole('heading', { name: /^country$/i })).toBeVisible({
+ timeout: 5_000,
+ })
+ await pickAutocompleteOption(page, /search countries/i, FIXTURE_PROMO_COUNTRY)
+ await saveEditor(page)
+
+ await expect(page.getByText(FIXTURE_PROMO_COUNTRY).first()).toBeVisible({ timeout: 5_000 })
+
+ await submitCreate(page, name)
+ })
+
+ test('creates a promotion with a Product rule', async ({ page }) => {
+ const creds = await login(page)
+ await gotoIndex(page, PROMOTIONS_PATH(creds.store_id), CTA)
+
+ const name = `E2E Product Promo ${Date.now()}`
+ await startNewPromotion(page, creds.store_id, name)
+
+ // Rule labels come from `Spree.t("promotion_rule_types.*.name")`.
+ await pickRule(page, /^product\(s\)$/i)
+ await expect(page.getByRole('heading', { name: /^product\(s\)$/i })).toBeVisible({
+ timeout: 5_000,
+ })
+ await page.getByRole('button', { name: /all of these products/i }).click()
+ await pickAutocompleteOption(page, /search products by name/i, FIXTURE_PROMO_PRODUCT)
+ await saveEditor(page)
+
+ await expect(page.getByText(FIXTURE_PROMO_PRODUCT).first()).toBeVisible({ timeout: 5_000 })
+
+ await submitCreate(page, name)
+ })
+
+ test('creates a promotion with a Category rule', async ({ page }) => {
+ const creds = await login(page)
+ await gotoIndex(page, PROMOTIONS_PATH(creds.store_id), CTA)
+
+ const name = `E2E Category Promo ${Date.now()}`
+ await startNewPromotion(page, creds.store_id, name)
+
+ // Class is `Spree::Promotion::Rules::Taxon`; the translated label is
+ // "Categories" per the 6.0 Taxon→Category rename.
+ await pickRule(page, /^categories$/i)
+ await expect(page.getByRole('heading', { name: /^categories$/i })).toBeVisible({
+ timeout: 5_000,
+ })
+ await page.getByRole('button', { name: /any of these categories/i }).click()
+ await pickAutocompleteOption(page, /search categories/i, FIXTURE_PROMO_TAXON)
+ await saveEditor(page)
+
+ await expect(page.getByText(FIXTURE_PROMO_TAXON).first()).toBeVisible({ timeout: 5_000 })
+
+ await submitCreate(page, name)
+ })
+
+ test('creates a promotion with a Customer rule', async ({ page }) => {
+ const creds = await login(page)
+ await gotoIndex(page, PROMOTIONS_PATH(creds.store_id), CTA)
+
+ const name = `E2E Customer Promo ${Date.now()}`
+ await startNewPromotion(page, creds.store_id, name)
+
+ // Class is `Rules::User`; translated label is "Customers" because the
+ // rule keys off `Spree::Order#user_id`.
+ await pickRule(page, /^customers$/i)
+ await expect(page.getByRole('heading', { name: /^customers$/i })).toBeVisible({
+ timeout: 5_000,
+ })
+
+ // `Spree.user_class.search` matches first_name/last_name (LIKE) and email
+ // (exact). Search by first name; the row summary renders `full_name`.
+ await pickAutocompleteOption(
+ page,
+ /search customers by name or email/i,
+ FIXTURE_PROMO_CUSTOMER_FIRST_NAME,
+ )
+ await saveEditor(page)
+
+ await expect(page.getByText(FIXTURE_PROMO_CUSTOMER_FULL_NAME).first()).toBeVisible({
+ timeout: 5_000,
+ })
+
+ await submitCreate(page, name)
+ })
+
+ test('creates a promotion with a Customer Group rule', async ({ page }) => {
+ const creds = await login(page)
+ await gotoIndex(page, PROMOTIONS_PATH(creds.store_id), CTA)
+
+ const name = `E2E Group Promo ${Date.now()}`
+ await startNewPromotion(page, creds.store_id, name)
+
+ await pickRule(page, /^customer group\(s\)$/i)
+ await expect(page.getByRole('heading', { name: /^customer group\(s\)$/i })).toBeVisible({
+ timeout: 5_000,
+ })
+ await pickAutocompleteOption(page, /search customer groups/i, FIXTURE_PROMO_CUSTOMER_GROUP)
+ await saveEditor(page)
+
+ await expect(page.getByText(FIXTURE_PROMO_CUSTOMER_GROUP).first()).toBeVisible({
+ timeout: 5_000,
+ })
+
+ await submitCreate(page, name)
+ })
+
+ test('creates a promotion with a Create Adjustment action', async ({ page }) => {
+ const creds = await login(page)
+ await gotoIndex(page, PROMOTIONS_PATH(creds.store_id), CTA)
+
+ const name = `E2E Adjustment Promo ${Date.now()}`
+ await startNewPromotion(page, creds.store_id, name)
+
+ await pickAction(page, /^create whole-order adjustment$/i)
+ await expect(
+ page.getByRole('heading', { name: /^create whole-order adjustment$/i }),
+ ).toBeVisible({ timeout: 5_000 })
+
+ // Calculator defaults to the first entry once the catalog arrives; wait
+ // for the trigger to enable before saving.
+ await expect(page.locator('#calculator-type')).toBeEnabled({ timeout: 10_000 })
+ await saveEditor(page)
+
+ await expect(page.getByText(/^create whole-order adjustment$/i).first()).toBeVisible()
+
+ await submitCreate(page, name)
+ })
+
+ test('creates a promotion with a Create Item Adjustments action', async ({ page }) => {
+ const creds = await login(page)
+ await gotoIndex(page, PROMOTIONS_PATH(creds.store_id), CTA)
+
+ const name = `E2E Item Adjustments Promo ${Date.now()}`
+ await startNewPromotion(page, creds.store_id, name)
+
+ await pickAction(page, /^create per-line-item adjustment$/i)
+ await expect(
+ page.getByRole('heading', { name: /^create per-line-item adjustment$/i }),
+ ).toBeVisible({ timeout: 5_000 })
+
+ await expect(page.locator('#calculator-type')).toBeEnabled({ timeout: 10_000 })
+ await saveEditor(page)
+
+ await expect(page.getByText(/^create per-line-item adjustment$/i).first()).toBeVisible()
+
+ await submitCreate(page, name)
+ })
+
+ test('deletes a promotion', async ({ page }) => {
+ const creds = await login(page)
+ await gotoIndex(page, PROMOTIONS_PATH(creds.store_id), CTA)
+
+ const name = `E2E Promo Delete ${Date.now()}`
+
+ await startNewPromotion(page, creds.store_id, name)
+ await submitCreate(page, name)
+
+ await page.getByRole('button', { name: /^delete$/i }).click()
+ await expect(page.getByRole('heading', { name: /delete promotion\?/i })).toBeVisible()
+ await page
+ .getByRole('dialog')
+ .getByRole('button', { name: /^delete$/i })
+ .click()
+
+ await expect(page).toHaveURL(new RegExp(`/${creds.store_id}/promotions(?:\\?|$)`), {
+ timeout: 15_000,
+ })
+ await expect(rowButton(page, name)).toHaveCount(0, { timeout: 15_000 })
+ })
+})
diff --git a/packages/admin/e2e/stock-locations.spec.ts b/packages/admin/e2e/stock-locations.spec.ts
new file mode 100644
index 0000000000..a0af9f76b1
--- /dev/null
+++ b/packages/admin/e2e/stock-locations.spec.ts
@@ -0,0 +1,71 @@
+import { expect, type Page, test } from '@playwright/test'
+import { gotoIndex, login, rowButton } from './helpers'
+
+const STOCK_LOCATIONS_PATH = (storeId: string) => `/${storeId}/settings/stock-locations`
+const CTA = /add stock location/i
+
+async function createStockLocation(page: Page, name: string) {
+ await page.getByRole('button', { name: /add stock location/i }).click()
+ await expect(page.getByRole('heading', { name: /add stock location/i })).toBeVisible()
+ await page.locator('#name').fill(name)
+ await page.getByRole('button', { name: /create stock location/i }).click()
+}
+
+test.describe('stock locations', () => {
+ test('lists stock locations', async ({ page }) => {
+ const creds = await login(page)
+ await gotoIndex(page, STOCK_LOCATIONS_PATH(creds.store_id), CTA)
+ })
+
+ test('creates a new stock location', async ({ page }) => {
+ const creds = await login(page)
+ await gotoIndex(page, STOCK_LOCATIONS_PATH(creds.store_id), CTA)
+
+ const name = `E2E Warehouse ${Date.now()}`
+ await createStockLocation(page, name)
+
+ await expect(rowButton(page, name)).toBeVisible({ timeout: 15_000 })
+ })
+
+ test('edits a stock location', async ({ page }) => {
+ const creds = await login(page)
+ await gotoIndex(page, STOCK_LOCATIONS_PATH(creds.store_id), CTA)
+
+ const suffix = Date.now()
+ const original = `E2E Edit Loc ${suffix}`
+ const updated = `${original} (updated)`
+
+ await createStockLocation(page, original)
+ await expect(rowButton(page, original)).toBeVisible({ timeout: 15_000 })
+
+ await rowButton(page, original).click()
+ await expect(page.getByRole('heading', { name: original })).toBeVisible({ timeout: 15_000 })
+ await expect(page.locator('#name')).toHaveValue(original)
+
+ await page.locator('#name').fill(updated)
+ await page.getByRole('button', { name: /^save$/i }).click()
+
+ await expect(rowButton(page, updated)).toBeVisible({ timeout: 15_000 })
+ })
+
+ test('deletes a stock location', async ({ page }) => {
+ const creds = await login(page)
+ await gotoIndex(page, STOCK_LOCATIONS_PATH(creds.store_id), CTA)
+
+ const name = `E2E Delete Loc ${Date.now()}`
+ await createStockLocation(page, name)
+ await expect(rowButton(page, name)).toBeVisible({ timeout: 15_000 })
+
+ await rowButton(page, name).click()
+ await expect(page.getByRole('heading', { name })).toBeVisible({ timeout: 15_000 })
+
+ await page.getByRole('button', { name: /^delete$/i }).click()
+ await expect(page.getByRole('heading', { name: /delete stock location\?/i })).toBeVisible()
+ await page
+ .getByRole('dialog')
+ .getByRole('button', { name: /^delete$/i })
+ .click()
+
+ await expect(rowButton(page, name)).toHaveCount(0, { timeout: 15_000 })
+ })
+})
diff --git a/packages/admin/e2e/stock-transfers.spec.ts b/packages/admin/e2e/stock-transfers.spec.ts
new file mode 100644
index 0000000000..e352b3fd48
--- /dev/null
+++ b/packages/admin/e2e/stock-transfers.spec.ts
@@ -0,0 +1,26 @@
+import { expect, test } from '@playwright/test'
+import { gotoIndex, login } from './helpers'
+
+const TRANSFERS_PATH = (storeId: string) => `/${storeId}/products/transfers`
+const CTA = /new transfer/i
+
+test.describe('stock transfers', () => {
+ test('lists stock transfers', async ({ page }) => {
+ const creds = await login(page)
+ await gotoIndex(page, TRANSFERS_PATH(creds.store_id), CTA)
+ })
+
+ // The "new transfer" Sheet requires picking a stocked variant. We only
+ // assert the sheet opens; a full create needs a product + variant with
+ // stock items, which the dummy app's seed pipeline doesn't provision.
+ test('opens the new transfer sheet', async ({ page }) => {
+ const creds = await login(page)
+ await gotoIndex(page, TRANSFERS_PATH(creds.store_id), CTA)
+
+ await page.getByRole('button', { name: /new transfer/i }).click()
+ await expect(page.getByRole('heading', { name: /new stock transfer/i })).toBeVisible({
+ timeout: 15_000,
+ })
+ await expect(page.locator('#destination')).toBeVisible()
+ })
+})
diff --git a/packages/admin/e2e/tax-categories.spec.ts b/packages/admin/e2e/tax-categories.spec.ts
new file mode 100644
index 0000000000..7edbb813d4
--- /dev/null
+++ b/packages/admin/e2e/tax-categories.spec.ts
@@ -0,0 +1,82 @@
+import { expect, type Page, test } from '@playwright/test'
+import { gotoIndex, login, rowButton } from './helpers'
+
+const TAX_CATEGORIES_PATH = (storeId: string) => `/${storeId}/settings/tax-categories`
+const CTA = /add tax category/i
+
+async function createTaxCategory(
+ page: Page,
+ attrs: { name: string; taxCode?: string; description?: string },
+) {
+ await page.getByRole('button', { name: /add tax category/i }).click()
+ await expect(page.getByRole('heading', { name: /add tax category/i })).toBeVisible()
+
+ await page.locator('#name').fill(attrs.name)
+ if (attrs.taxCode) await page.locator('#tax_code').fill(attrs.taxCode)
+ if (attrs.description) await page.locator('#description').fill(attrs.description)
+
+ await page.getByRole('button', { name: /create tax category/i }).click()
+}
+
+test.describe('tax categories', () => {
+ test('lists tax categories', async ({ page }) => {
+ const creds = await login(page)
+ await gotoIndex(page, TAX_CATEGORIES_PATH(creds.store_id), CTA)
+ })
+
+ test('creates a new tax category', async ({ page }) => {
+ const creds = await login(page)
+ await gotoIndex(page, TAX_CATEGORIES_PATH(creds.store_id), CTA)
+
+ const suffix = Date.now()
+ const name = `E2E Tax ${suffix}`
+
+ await createTaxCategory(page, { name, taxCode: `TX${suffix}`, description: 'For E2E test.' })
+
+ await expect(rowButton(page, name)).toBeVisible({ timeout: 15_000 })
+ })
+
+ test('edits a tax category', async ({ page }) => {
+ const creds = await login(page)
+ await gotoIndex(page, TAX_CATEGORIES_PATH(creds.store_id), CTA)
+
+ const suffix = Date.now()
+ const original = `E2E Edit Tax ${suffix}`
+ const updated = `${original} (updated)`
+
+ await createTaxCategory(page, { name: original })
+ await expect(rowButton(page, original)).toBeVisible({ timeout: 15_000 })
+
+ await rowButton(page, original).click()
+ await expect(page.getByRole('heading', { name: original })).toBeVisible({ timeout: 15_000 })
+ await expect(page.locator('#name')).toHaveValue(original)
+
+ await page.locator('#name').fill(updated)
+ await page.getByRole('button', { name: /^save$/i }).click()
+
+ await expect(rowButton(page, updated)).toBeVisible({ timeout: 15_000 })
+ })
+
+ test('deletes a tax category', async ({ page }) => {
+ const creds = await login(page)
+ await gotoIndex(page, TAX_CATEGORIES_PATH(creds.store_id), CTA)
+
+ const suffix = Date.now()
+ const name = `E2E Delete Tax ${suffix}`
+
+ await createTaxCategory(page, { name })
+ await expect(rowButton(page, name)).toBeVisible({ timeout: 15_000 })
+
+ await rowButton(page, name).click()
+ await expect(page.getByRole('heading', { name })).toBeVisible({ timeout: 15_000 })
+
+ await page.getByRole('button', { name: /^delete$/i }).click()
+ await expect(page.getByRole('heading', { name: /delete tax category\?/i })).toBeVisible()
+ await page
+ .getByRole('dialog')
+ .getByRole('button', { name: /^delete$/i })
+ .click()
+
+ await expect(rowButton(page, name)).toHaveCount(0, { timeout: 15_000 })
+ })
+})