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.

Stop pagination from submitting the form it sits in

Damian Legawiecf4910194ce40
diff --git a/packages/dashboard-ui/src/ui/pagination.tsx b/packages/dashboard-ui/src/ui/pagination.tsx
index 11d5e2a8c1..4c730ad031 100644
--- a/packages/dashboard-ui/src/ui/pagination.tsx
+++ b/packages/dashboard-ui/src/ui/pagination.tsx
@@ -75,6 +75,7 @@ export function Pagination({
</span>
<div className="flex items-center gap-1">
<Button
+ type="button"
size="icon-sm"
variant="outline"
className="hidden lg:flex"
@@ -85,6 +86,7 @@ export function Pagination({
<ChevronsLeftIcon />
</Button>
<Button
+ type="button"
size="icon-sm"
variant="outline"
className="size-9 sm:size-8"
@@ -95,6 +97,7 @@ export function Pagination({
<ChevronLeftIcon />
</Button>
<Button
+ type="button"
size="icon-sm"
variant="outline"
className="size-9 sm:size-8"
@@ -105,6 +108,7 @@ export function Pagination({
<ChevronRightIcon />
</Button>
<Button
+ type="button"
size="icon-sm"
className="hidden lg:flex"
variant="outline"
diff --git a/packages/dashboard/e2e/price-lists.spec.ts b/packages/dashboard/e2e/price-lists.spec.ts
index 16eb4f2f0c..f8a7a7dce8 100644
--- a/packages/dashboard/e2e/price-lists.spec.ts
+++ b/packages/dashboard/e2e/price-lists.spec.ts
@@ -3,12 +3,14 @@ import { expect, type Page, test } from '@playwright/test'
import {
addQuantityBreak,
csvFile,
+ deleteCatalogPickerProducts,
FIXTURE_PROMO_PRODUCT,
FIXTURE_PROMO_SKU,
gotoIndex,
login,
openRowMenu,
rowButton,
+ seedCatalogPickerProducts,
} from './helpers'
const PRICE_LISTS_PATH = (storeId: string) => `/${storeId}/products/price-lists`
@@ -322,6 +324,70 @@ test.describe('price lists', () => {
).toHaveValue('33.33')
})
+ // Paging the products card must not write anything. The pagination control
+ // lives inside the price list's own form, so a button without an explicit
+ // type submits it — the page-2 click used to PATCH the whole list
+ // (docs/plans/6.0-volume-pricing.md).
+ test('paging the products card does not save the price list', async ({ page }) => {
+ const creds = await login(page)
+ const prefix = `E2E PL Paging Product ${Date.now()}`
+ // The card holds 25 rows a page, so a second page needs more than that.
+ const seeded = await seedCatalogPickerProducts(
+ page,
+ creds.store_id,
+ prefix,
+ creds.accessToken,
+ 30,
+ )
+
+ try {
+ await gotoIndex(page, PRICE_LISTS_PATH(creds.store_id), CTA)
+ const name = `E2E PL Paging ${Date.now()}`
+ await startNewPriceList(page, creds.store_id, name)
+ await submitCreate(page, name)
+
+ // Attach them through the API: the picker would take 30 clicks, and the
+ // subject here is paging, not membership.
+ const priceListId = page.url().split('/price-lists/')[1]?.split(/[/?]/)[0] ?? ''
+ expect(priceListId).toMatch(/^pl_/)
+ await page.request.post(`/api/v3/admin/price_lists/${priceListId}/products`, {
+ headers: {
+ 'X-Spree-Store-Id': creds.store_id,
+ Authorization: `Bearer ${creds.accessToken}`,
+ },
+ data: { product_ids: seeded },
+ })
+ await page.reload()
+
+ const writes: string[] = []
+ page.on('request', (request) => {
+ if (request.method() === 'PATCH' && /\/price_lists\//.test(request.url())) {
+ writes.push(request.url())
+ }
+ })
+
+ // Unconditional: if there is no second page the seeding is wrong and the
+ // test must say so rather than skip the click it exists to make.
+ const next = page.getByRole('button', { name: /next page/i })
+ await expect(next).toBeVisible({ timeout: 15_000 })
+ await next.click()
+
+ // The page changed, and nothing was written on the way.
+ await expect(page.getByText(/page 2 of/i)).toBeVisible({ timeout: 15_000 })
+ expect(writes).toEqual([])
+ await expect(
+ page
+ .getByRole('main')
+ .getByRole('button', { name: /^save$/i })
+ .first(),
+ ).toBeDisabled()
+ } finally {
+ await deleteCatalogPickerProducts(page, creds.store_id, creds.accessToken, seeded).catch(
+ () => undefined,
+ )
+ }
+ })
+
// 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).