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.

Cover the tier editors and the price-list CSV end to end

Damian Legawiec7dd4956f75cd
diff --git a/packages/dashboard/e2e/catalogs.spec.ts b/packages/dashboard/e2e/catalogs.spec.ts
index 7fde15455b..c10c12425c 100644
--- a/packages/dashboard/e2e/catalogs.spec.ts
+++ b/packages/dashboard/e2e/catalogs.spec.ts
@@ -1,5 +1,6 @@
import { expect, type Page, test } from '@playwright/test'
import {
+ addQuantityBreak,
deleteCatalogPickerProducts,
FIXTURE_CATALOG_PICKER_PRODUCT_COUNT,
FIXTURE_CATALOG_PICKER_PRODUCT_PREFIX,
@@ -295,6 +296,85 @@ test.describe('catalogs', () => {
await expect(page.locator('#catalog-minimum-quantity')).toHaveValue('10')
})
+ // A percentage can step by quantity: each band is a row under the
+ // percentage, and the bands are what a reload shows
+ // (docs/plans/6.0-volume-pricing.md).
+ test('keeps the percentage quantity tiers across saves', async ({ page }) => {
+ const creds = await login(page)
+ await gotoIndex(page, CATALOGS_PATH(creds.store_id), CTA)
+
+ const name = `E2E Catalog Bands ${Date.now()}`
+ await createCatalog(page, name)
+
+ await page.locator('#catalog-pricing-mode').click()
+ await page.getByRole('option', { name: /percentage off/i }).click()
+ await page.locator('#catalog-adjustment-magnitude').fill('10')
+ await page.getByRole('button', { name: /^add quantity tier$/i }).click()
+ await page.getByLabel(/^from quantity$/i).fill('50')
+ // `.last()`: the magnitude field above the tiers is a percentage too.
+ await page
+ .getByLabel(/^percentage$/i)
+ .last()
+ .fill('20')
+ await saveCatalog(page)
+
+ await page.reload()
+ await expect(page.getByLabel(/^from quantity$/i)).toHaveValue('50', { timeout: 15_000 })
+ await expect(page.getByLabel(/^percentage$/i).last()).toHaveValue('20')
+ })
+
+ // A variant with quantity breaks says so in the priced assortment: the
+ // count is a badge, the ladder is on hover, and so is the reminder that
+ // fixed tiers set the price whatever the catalog's percentage says.
+ test("shows a variant's ladder on the assortment with the fixed-tiers note", async ({ page }) => {
+ const creds = await login(page)
+ await gotoIndex(page, CATALOGS_PATH(creds.store_id), CTA)
+
+ const name = `E2E Catalog Ladder ${Date.now()}`
+ await createCatalog(page, name)
+
+ await page.getByRole('button', { name: /add products/i }).click()
+ const picker = page.getByRole('dialog')
+ await expect(picker.getByRole('heading', { name: /add products to catalog/i })).toBeVisible()
+ await picker.getByRole('searchbox').fill(FIXTURE_PROMO_PRODUCT)
+ const option = picker
+ .getByRole('button', { name: new RegExp(FIXTURE_PROMO_PRODUCT, 'i') })
+ .first()
+ await expect(option).toBeVisible({ timeout: 15_000 })
+ await option.click()
+ await picker.getByRole('button', { name: /^add 1$/i }).click()
+ await expect(picker).toBeHidden({ timeout: 15_000 })
+
+ await page.locator('#catalog-pricing-mode').click()
+ await page.getByRole('option', { name: /prices i enter for this catalog/i }).click()
+ await saveCatalog(page)
+
+ const openPrices = page.getByRole('button', { name: /^enter prices$/i }).first()
+ await expect(openPrices).toBeVisible({ timeout: 15_000 })
+ await openPrices.click()
+ const grid = page.getByRole('dialog')
+ const cell = grid.getByLabel(/^price for/i).first()
+ await expect(cell).toBeVisible({ timeout: 15_000 })
+ await cell.dblclick()
+ await cell.fill('12.34')
+ await cell.press('Enter')
+
+ await addQuantityBreak(grid, '24', '10.00')
+
+ const savePrices = grid.getByRole('button', { name: /^save prices$/i })
+ await expect(savePrices).toBeEnabled({ timeout: 15_000 })
+ await savePrices.click()
+ await expect(savePrices).toBeDisabled({ timeout: 15_000 })
+ await grid.getByRole('button', { name: /^close$/i }).click()
+ await expect(grid).toBeHidden({ timeout: 15_000 })
+
+ const badge = page.getByRole('button', { name: /\+1 tier$/i })
+ await expect(badge).toBeVisible({ timeout: 15_000 })
+ await badge.hover()
+ await expect(page.getByText('$10.00')).toBeVisible({ timeout: 15_000 })
+ await expect(page.getByText(/percentage adjustment does not apply here/i)).toBeVisible()
+ })
+
// The threshold survives a switch away from automatic pricing, where its
// field is no longer rendered. Judging it then would block Save over
// something the merchant cannot see or correct. The input refuses letters
diff --git a/packages/dashboard/e2e/global-setup.ts b/packages/dashboard/e2e/global-setup.ts
index d76e171dc3..cb426176c0 100644
--- a/packages/dashboard/e2e/global-setup.ts
+++ b/packages/dashboard/e2e/global-setup.ts
@@ -25,6 +25,7 @@ import {
FIXTURE_PROMO_CUSTOMER_FULL_NAME,
FIXTURE_PROMO_CUSTOMER_GROUP,
FIXTURE_PROMO_PRODUCT,
+ FIXTURE_PROMO_SKU,
FIXTURE_PROMO_TAXON,
FIXTURE_PROMO_TAXON_PERMALINK,
} from './helpers'
@@ -59,6 +60,7 @@ const BOOTSTRAP_RUBY = [
`category = s.categories.where(permalink: '${FIXTURE_PROMO_TAXON_PERMALINK}').first_or_create!(name: '${FIXTURE_PROMO_TAXON}', parent: nil)`,
`product = Spree::Product.where(name: '${FIXTURE_PROMO_PRODUCT}').first_or_create!(store: s, status: 'active')`,
`product.default_variant.set_price(s.default_currency, 19.99)`,
+ `product.default_variant.update!(sku: '${FIXTURE_PROMO_SKU}') if product.default_variant.sku != '${FIXTURE_PROMO_SKU}'`,
`product.taxons << category unless product.taxons.include?(category)`,
// Stock the promo product on the store's default stock location so
// order-creation tests can add it to a draft order without the
diff --git a/packages/dashboard/e2e/helpers.ts b/packages/dashboard/e2e/helpers.ts
index 75188da3a9..65e3026aaa 100644
--- a/packages/dashboard/e2e/helpers.ts
+++ b/packages/dashboard/e2e/helpers.ts
@@ -1,7 +1,37 @@
import { readFileSync } from 'node:fs'
-import { expect, type Page } from '@playwright/test'
+import { expect, type Locator, type Page } from '@playwright/test'
import { CREDENTIALS_FILE } from './paths'
+/** A CSV to hand to a file input, one row per entry. */
+export function csvFile(rows: string[]) {
+ return {
+ name: `e2e-import-${Date.now()}.csv`,
+ mimeType: 'text/csv',
+ buffer: Buffer.from(`${rows.join('\n')}\n`),
+ }
+}
+
+/**
+ * Adds a quantity break to the first variant in an open price spreadsheet.
+ * The blank rung under the variant appends a break; its quantity and price
+ * are spreadsheet cells, read-only until double-clicked.
+ */
+export async function addQuantityBreak(grid: Locator, quantity: string, price: string) {
+ await grid
+ .getByRole('button', { name: /^add quantity break$/i })
+ .first()
+ .click()
+ const quantityCell = grid.getByLabel(/^from quantity$/i).first()
+ await quantityCell.dblclick()
+ await quantityCell.fill(quantity)
+ await quantityCell.press('Enter')
+ const rungPrice = grid.getByLabel(new RegExp(`^price for from qty ${quantity}$`, 'i'))
+ await expect(rungPrice).toBeVisible()
+ await rungPrice.dblclick()
+ await rungPrice.fill(price)
+ await rungPrice.press('Enter')
+}
+
/**
* Fixture records seeded once in `global-setup.ts`. Specs that exercise
* resource pickers (promotion rule/action editors, etc.) reference them
@@ -12,6 +42,8 @@ export const FIXTURE_PROMO_TAXON = 'E2E Promo Category'
// permalink so it can never match an unrelated category.
export const FIXTURE_PROMO_TAXON_PERMALINK = 'e2e-promo-category'
export const FIXTURE_PROMO_PRODUCT = 'E2E Promo Product'
+/** The promo product's SKU — what a price-list CSV row names a variant by. */
+export const FIXTURE_PROMO_SKU = 'E2E-PROMO'
/** Name prefix for catalog picker pagination E2E products; each run appends a timestamp. */
export const FIXTURE_CATALOG_PICKER_PRODUCT_PREFIX = 'E2E Catalog Picker Product'
diff --git a/packages/dashboard/e2e/imports.spec.ts b/packages/dashboard/e2e/imports.spec.ts
index 57829de673..c60e6f4cde 100644
--- a/packages/dashboard/e2e/imports.spec.ts
+++ b/packages/dashboard/e2e/imports.spec.ts
@@ -1,16 +1,8 @@
import { expect, type Page, test } from '@playwright/test'
-import { login } from './helpers'
+import { csvFile, login } from './helpers'
const PRODUCTS_PATH = (storeId: string) => `/${storeId}/products`
-function csvFile(rows: string[]) {
- return {
- name: `e2e-import-${Date.now()}.csv`,
- mimeType: 'text/csv',
- buffer: Buffer.from(`${rows.join('\n')}\n`),
- }
-}
-
async function openImportSheet(page: Page, storeId: string) {
await page.goto(PRODUCTS_PATH(storeId))
await page.getByRole('button', { name: /^import$/i }).click()
diff --git a/packages/dashboard/e2e/price-lists.spec.ts b/packages/dashboard/e2e/price-lists.spec.ts
index 57ac7800e5..d1a2220558 100644
--- a/packages/dashboard/e2e/price-lists.spec.ts
+++ b/packages/dashboard/e2e/price-lists.spec.ts
@@ -1,5 +1,15 @@
+import { readFileSync } from 'node:fs'
import { expect, type Page, test } from '@playwright/test'
-import { FIXTURE_PROMO_PRODUCT, gotoIndex, login, openRowMenu, rowButton } from './helpers'
+import {
+ addQuantityBreak,
+ csvFile,
+ FIXTURE_PROMO_PRODUCT,
+ FIXTURE_PROMO_SKU,
+ gotoIndex,
+ login,
+ openRowMenu,
+ rowButton,
+} from './helpers'
const PRICE_LISTS_PATH = (storeId: string) => `/${storeId}/products/price-lists`
const PRODUCTS_PATH = (storeId: string) => `/${storeId}/products`
@@ -312,6 +322,109 @@ test.describe('price lists', () => {
).toHaveValue('33.33')
})
+ // A ladder is edited in the same grid: a variant's row grows a rung per
+ // quantity break, and the rung is what the server holds once saved
+ // (docs/plans/6.0-volume-pricing.md).
+ test('adds a quantity break in the price spreadsheet', async ({ page }) => {
+ const creds = await login(page)
+ await gotoIndex(page, PRICE_LISTS_PATH(creds.store_id), CTA)
+
+ const name = `E2E PL Breaks ${Date.now()}`
+ await startNewPriceList(page, creds.store_id, name)
+ await submitCreate(page, name)
+ await pickProductOnPage(page, FIXTURE_PROMO_PRODUCT)
+ await saveForm(page)
+ await expect(page.getByText(/\d+ price(s)? (is|are) configured/i)).toBeVisible({
+ timeout: 15_000,
+ })
+
+ await openBulkPriceEditor(page)
+ const grid = page.getByRole('dialog')
+ const priceInput = grid.getByLabel(/^price for/i).first()
+ await expect(priceInput).toBeVisible({ timeout: 15_000 })
+ await priceInput.dblclick()
+ await priceInput.fill('30.00')
+ await priceInput.press('Enter')
+
+ // A figure with cents: the grid drops trailing zeros when it reloads.
+ await addQuantityBreak(grid, '24', '25.25')
+
+ await grid.getByRole('button', { name: /^save prices$/i }).click()
+ await expect(grid.getByText(/unsaved change/i)).toBeHidden({ timeout: 15_000 })
+
+ // Reopened, the grid shows what was written rather than what was typed.
+ await grid.getByRole('button', { name: /^close$/i }).click()
+ await expect(grid).toBeHidden({ timeout: 15_000 })
+ await openBulkPriceEditor(page)
+ await expect(page.getByRole('dialog').getByLabel(/^price for from qty 24$/i)).toHaveValue(
+ '25.25',
+ { timeout: 15_000 },
+ )
+ })
+
+ // The list's prices travel as a CSV keyed by SKU, one rung per row: the
+ // import merges the file into the list and reports the rows it could not
+ // place, and the export hands the ladder back in the same shape.
+ test('imports a CSV of prices and exports the list', async ({ page }) => {
+ // Upload + background row processing legitimately take a while.
+ test.setTimeout(180_000)
+
+ const creds = await login(page)
+ await gotoIndex(page, PRICE_LISTS_PATH(creds.store_id), CTA)
+
+ const suffix = Date.now()
+ const name = `E2E PL CSV ${suffix}`
+ await startNewPriceList(page, creds.store_id, name)
+ await submitCreate(page, name)
+
+ await page.getByRole('button', { name: /^import$/i }).click()
+ await expect(page.getByRole('heading', { name: /import from csv/i })).toBeVisible()
+ await page
+ .getByRole('dialog')
+ .locator('input[type="file"]')
+ .setInputFiles(
+ csvFile([
+ 'sku,currency,min_quantity,price,compare_at_price',
+ `${FIXTURE_PROMO_SKU},USD,1,17.25,`,
+ `${FIXTURE_PROMO_SKU},USD,24,15.75,`,
+ // A SKU the store does not have is a row-level failure, not the
+ // import's.
+ `E2E-NOPE-${suffix},USD,1,1.00,`,
+ ]),
+ )
+ await page.getByRole('button', { name: /^continue$/i }).click()
+
+ // The export writes the schema's own header names, so a file in that
+ // shape maps itself.
+ await expect(page.getByText('Map columns')).toBeVisible({ timeout: 15_000 })
+ await page.getByRole('button', { name: /start import/i }).click()
+ await expect(page.getByText(/import completed/i)).toBeVisible({ timeout: 120_000 })
+ await expect(page.getByText(/1 failed/i).first()).toBeVisible()
+ await page
+ .getByRole('dialog')
+ .getByRole('button', { name: /^close$/i })
+ .click()
+
+ // The rows landed on the list: the spreadsheet opens on them.
+ await openBulkPriceEditor(page)
+ const grid = page.getByRole('dialog')
+ await expect(grid.getByLabel(/^price for/i).first()).toHaveValue('17.25', { timeout: 15_000 })
+ await expect(grid.getByLabel(/^price for from qty 24$/i)).toHaveValue('15.75')
+ await grid.getByRole('button', { name: /^close$/i }).click()
+ await expect(grid).toBeHidden({ timeout: 15_000 })
+
+ // One click exports this list — no filtered-or-all dialog, the page
+ // already says which list — and the file carries the ladder.
+ const download = page.waitForEvent('download', { timeout: 60_000 })
+ await page.getByRole('button', { name: /^export$/i }).click()
+ const file = await download
+ expect(file.suggestedFilename()).toMatch(/price_list_prices/)
+ const body = readFileSync((await file.path()) as string, 'utf8')
+ expect(body).toContain(`${FIXTURE_PROMO_SKU},`)
+ expect(body).toContain(',USD,24,15.75,')
+ expect(body).not.toContain(`E2E-NOPE-${suffix}`)
+ })
+
// Multi-currency: the bulk editor scopes its grid to one currency at a time
// via the header currency selector. Edit + save a USD price, switch to EUR,
// edit + save again, then confirm each currency kept its own value. The e2e