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.

Added end-to-end tests for getting started, the media library and commission rates

Claude6c1ebff6b110
diff --git a/packages/dashboard/e2e/commission-rates.spec.ts b/packages/dashboard/e2e/commission-rates.spec.ts
new file mode 100644
index 0000000000..d3d3234c42
--- /dev/null
+++ b/packages/dashboard/e2e/commission-rates.spec.ts
@@ -0,0 +1,64 @@
+import { expect, type Page, test } from '@playwright/test'
+import { gotoIndex, login, openRowMenu, rowButton, waitForToastsToClear } from './helpers'
+
+const COMMISSION_RATES_PATH = (storeId: string) => `/${storeId}/sellers/commission-rates`
+const CTA = /add commission rate/i
+
+async function createCommissionRate(page: Page, name: string, value: string) {
+ await page.getByRole('button', { name: CTA }).click()
+ await page.locator('#name').fill(name)
+ await page.locator('#value').fill(value)
+ await page.getByRole('button', { name: /create commission rate/i }).click()
+ await expect(rowButton(page, name)).toBeVisible({ timeout: 15_000 })
+}
+
+test.describe('commission rates', () => {
+ test('creates a percentage rate and edits it', async ({ page }) => {
+ const creds = await login(page)
+ await gotoIndex(page, COMMISSION_RATES_PATH(creds.store_id), CTA)
+
+ const name = `E2E Commission ${Date.now()}`
+ await createCommissionRate(page, name, '12')
+
+ const row = page.getByRole('row').filter({ has: rowButton(page, name) })
+ await expect(row.getByText(/^12(\.0+)?%$/)).toBeVisible()
+ // A rate with no conditions matches every sale, and the row says so.
+ await expect(row.getByText(/^every sale$/i)).toBeVisible()
+
+ await rowButton(page, name).click()
+ await expect(page.locator('#value')).toHaveValue(/^12(\.0+)?$/, { timeout: 15_000 })
+ await page.locator('#value').fill('15')
+ await page.getByRole('button', { name: /^save$/i }).click()
+
+ await expect(row.getByText(/^15(\.0+)?%$/)).toBeVisible({ timeout: 15_000 })
+ })
+
+ test('deletes a rate after confirming', async ({ page }) => {
+ const creds = await login(page)
+ await gotoIndex(page, COMMISSION_RATES_PATH(creds.store_id), CTA)
+
+ const name = `E2E Old Commission ${Date.now()}`
+ await createCommissionRate(page, name, '5')
+
+ await waitForToastsToClear(page)
+ await openRowMenu(page, name)
+ await page.getByRole('menuitem', { name: /^delete$/i }).click()
+ await expect(page.getByRole('heading', { name: /delete commission rate\?/i })).toBeVisible()
+ await page
+ .getByRole('dialog')
+ .getByRole('button', { name: /^delete$/i })
+ .click()
+
+ await expect(rowButton(page, name)).toHaveCount(0, { timeout: 15_000 })
+ })
+
+ test('the old settings address opens the commission rates', async ({ page }) => {
+ const creds = await login(page)
+ await page.goto(`/${creds.store_id}/settings/commission-rates`)
+
+ await expect(page).toHaveURL(new RegExp(`${COMMISSION_RATES_PATH(creds.store_id)}(\\?|$)`), {
+ timeout: 15_000,
+ })
+ await expect(page.getByRole('button', { name: CTA })).toBeVisible()
+ })
+})
diff --git a/packages/dashboard/e2e/getting-started.spec.ts b/packages/dashboard/e2e/getting-started.spec.ts
new file mode 100644
index 0000000000..7de16f4c93
--- /dev/null
+++ b/packages/dashboard/e2e/getting-started.spec.ts
@@ -0,0 +1,27 @@
+import { expect, test } from '@playwright/test'
+import { login } from './helpers'
+
+const GETTING_STARTED_PATH = (storeId: string) => `/${storeId}/getting-started`
+
+test.describe('getting started', () => {
+ test('shows setup progress and links each step to where it is done', async ({ page }) => {
+ const creds = await login(page)
+ await page.goto(GETTING_STARTED_PATH(creds.store_id))
+
+ await expect(page.getByRole('heading', { name: /^getting started$/i })).toBeVisible({
+ timeout: 15_000,
+ })
+ await expect(page.getByText(/\d+ of \d+ completed/i)).toBeVisible()
+
+ // The checklist opens on the first unfinished step, and other specs may
+ // have finished this one already — so open it only if it is still shut.
+ const step = page.getByRole('button', { name: /set up taxes collection/i })
+ if ((await step.getAttribute('aria-expanded')) !== 'true') await step.click()
+ await page.getByRole('link', { name: /^tax settings$/i }).click()
+
+ await expect(page).toHaveURL(new RegExp(`/${creds.store_id}/settings/tax-rates`))
+ await expect(page.getByRole('button', { name: /add tax rate/i })).toBeVisible({
+ timeout: 15_000,
+ })
+ })
+})
diff --git a/packages/dashboard/e2e/media-library.spec.ts b/packages/dashboard/e2e/media-library.spec.ts
new file mode 100644
index 0000000000..cb65c3b169
--- /dev/null
+++ b/packages/dashboard/e2e/media-library.spec.ts
@@ -0,0 +1,68 @@
+import { readFileSync } from 'node:fs'
+import { resolve } from 'node:path'
+import { expect, type Page, test } from '@playwright/test'
+import { login } from './helpers'
+import { E2E_DIR } from './paths'
+
+const MEDIA_PATH = (storeId: string) => `/${storeId}/products/media`
+const FIXTURE_IMAGE = readFileSync(resolve(E2E_DIR, 'fixtures/test-image.png'))
+
+/** Uploads the fixture image under a name of its own, so a search finds just this one. */
+async function uploadImage(page: Page, name: string) {
+ await page.locator('input[type="file"]').setInputFiles({
+ name,
+ mimeType: 'image/png',
+ buffer: FIXTURE_IMAGE,
+ })
+ await expect(page.getByText(/1 file uploaded/i)).toBeVisible({ timeout: 20_000 })
+}
+
+async function findTile(page: Page, text: string) {
+ await page.getByRole('searchbox').fill(text)
+ const tile = page.getByRole('listitem').filter({ hasText: text }).getByRole('button')
+ await expect(tile).toBeVisible({ timeout: 15_000 })
+ return tile
+}
+
+test.describe('media library', () => {
+ test('uploads an image and describes it for screen readers', async ({ page }) => {
+ const creds = await login(page)
+ await page.goto(MEDIA_PATH(creds.store_id))
+ await expect(page.getByRole('heading', { name: /^media$/i })).toBeVisible({ timeout: 15_000 })
+
+ const name = `e2e-library-${Date.now()}.png`
+ await uploadImage(page, name)
+
+ await (await findTile(page, name)).click()
+ const sheet = page.getByRole('dialog')
+ await expect(sheet.getByRole('heading', { name })).toBeVisible()
+ // Freshly uploaded, so nothing uses it yet.
+ await expect(sheet.getByText(/not used anywhere/i)).toBeVisible()
+
+ await sheet.locator('#media-alt').fill('A red test swatch')
+ await sheet.getByRole('button', { name: /^save$/i }).click()
+ await expect(page.getByText(/^saved$/i).first()).toBeVisible({ timeout: 15_000 })
+ // The grid captions a file by its description once it has one.
+ await sheet.getByRole('button', { name: /^cancel$/i }).click()
+ await expect(page.getByRole('listitem').filter({ hasText: 'A red test swatch' })).toBeVisible()
+ })
+
+ test('deletes a file from the grid after confirming', async ({ page }) => {
+ const creds = await login(page)
+ await page.goto(MEDIA_PATH(creds.store_id))
+ await expect(page.getByRole('heading', { name: /^media$/i })).toBeVisible({ timeout: 15_000 })
+
+ const name = `e2e-doomed-${Date.now()}.png`
+ await uploadImage(page, name)
+
+ await (await findTile(page, name)).click({ button: 'right' })
+ await page.getByRole('menuitem', { name: /^delete$/i }).click()
+ await expect(page.getByRole('heading', { name: /delete this file\?/i })).toBeVisible()
+ await page
+ .getByRole('dialog')
+ .getByRole('button', { name: /^delete$/i })
+ .click()
+
+ await expect(page.getByText(/no files match your filters/i)).toBeVisible({ timeout: 15_000 })
+ })
+})
diff --git a/packages/dashboard/src/routes/_authenticated/$storeId/getting-started.tsx b/packages/dashboard/src/routes/_authenticated/$storeId/getting-started.tsx
index e74ad3e170..80372e85eb 100644
--- a/packages/dashboard/src/routes/_authenticated/$storeId/getting-started.tsx
+++ b/packages/dashboard/src/routes/_authenticated/$storeId/getting-started.tsx
@@ -24,9 +24,7 @@ const TASK_LINKS: Record<string, string> = {
setup_payment_method: '/$storeId/settings/payment-methods',
add_products: '/$storeId/products',
set_customer_support_email: '/$storeId/settings/emails',
- // setup_taxes_collection has no CTA yet: the task completes on a TaxRate
- // existing, and the dashboard has no tax-rates surface to deep-link — add
- // one here when that settings page lands.
+ setup_taxes_collection: '/$storeId/settings/tax-rates',
}
export const Route = createFileRoute('/_authenticated/$storeId/getting-started')({