Files
redefined-designs/frontend/tests/e2e/pending-publish.spec.ts
T
bermudalamb 549a08038e test(e2e): convert the favorites, availability and orders specs (#137)
favorites, favorites-filter, sold-filter, orders and pending-publish. Five more copies of "register a customer" and three more of the hardcoded base URL go with them.

Two locators that were hiding real knowledge are now named. `gridCell` is the item's whole antd column rather than its card, needed because the SOLD ribbon renders outside the card — three specs reached for `.ant-col` directly to get at it. And `chooseAvailability` goes through the title attribute because antd's Segmented hides the real radio behind a styled label, so the input is found by role and cannot be clicked; that fact was written out twice in comments and is now written once in code.

The favorite control is located page-wide rather than within a card. The storefront paginates as items accumulate and the control is named for its item anyway, so scoping to a card bought nothing and broke whenever the card was on another page.

favorites-filter keeps its local `favorite()` helper. It is genuinely local — decline the opt-in, wait for the fading modal to stop intercepting pointer events, confirm the heart flipped — and belongs to that file's subject rather than to the storefront. It now takes page objects as parameters instead of reaching for locators itself, which is what a spec-level helper should look like.

Two specs still drive the registration form rather than taking the `customer` fixture, and deliberately. Both are about a signed-out visitor being interrupted mid-action — favoriting an item, or switching on the favorites filter — and the claim is that the thing they asked for survives the interruption. Replacing the interruption with an API call would delete the test.

Verified: favorites 6/6, favorites-filter 7/7, sold-filter 6/6, orders and pending-publish 8/8. Notably favorites-filter's "keeps showing a favorite after it sells" passes, which had been failing on a strict-mode violation from two items sharing a name across runs.

Refs #137
2026-08-23 19:43:45 -05:00

92 lines
3.0 KiB
TypeScript

import { test, expect, uniqueSuffix, publishItem } from './fixtures';
/**
* Creates an item and leaves it as it arrives — pending.
*
* Deliberately does not publish, unlike the shared `createItem` helper, because
* the staged state is the thing under test here. The status assertion is the
* whole premise: creating something does not publish it.
*/
async function createStagedItem(
request: import('@playwright/test').APIRequestContext,
name: string
): Promise<number> {
const created = await request.post('/api/admin/items', {
multipart: { name, description: '', price: '55', category_id: '', tags: '[]' }
});
expect(created.ok()).toBeTruthy();
const body = await created.json();
expect(body.status).toBe('pending');
return body.id as number;
}
test.describe('Staging an item until it is published', () => {
test('a new item is held back from the storefront until published', async ({
page,
storefront,
admin,
adminInventory
}) => {
const name = `Staged ${uniqueSuffix()}`;
await createStagedItem(page.request, name);
// Not in the catalogue while pending.
await storefront.goto();
await expect(page.getByText(name)).toHaveCount(0);
// It is in the admin, marked as pending.
await admin.goto();
await expect(adminInventory.row(name)).toBeVisible();
await expect(adminInventory.status(name, 'PENDING')).toBeVisible();
await adminInventory.publishButton(name).click();
await expect(adminInventory.status(name, 'AVAILABLE')).toBeVisible();
// And now a customer can see it.
await storefront.goto();
await expect(page.getByText(name)).toBeVisible();
});
test('publishing can be undone while nobody is holding the item', async ({
page,
storefront,
admin,
adminInventory
}) => {
const name = `Staged ${uniqueSuffix()}`;
const id = await createStagedItem(page.request, name);
await publishItem(page.request, id);
await storefront.goto();
await expect(page.getByText(name)).toBeVisible();
await admin.goto();
await adminInventory.unpublishButton(name).click();
await expect(adminInventory.status(name, 'PENDING')).toBeVisible();
await storefront.goto();
await expect(page.getByText(name)).toHaveCount(0);
});
// The two features together, which is the reason for wanting both: a staged
// item is previewed as it will look once live, because a customer never sees
// the pending state and "how will this look" is the question being asked.
test('a pending item previews as it will look once published', async ({
page,
admin,
adminInventory
}) => {
const name = `Staged ${uniqueSuffix()}`;
await createStagedItem(page.request, name);
await admin.goto();
await adminInventory.openPreview(name);
const drawer = adminInventory.previewDrawer(name);
await expect(drawer).toBeVisible();
await expect(drawer.getByText('$55.00')).toBeVisible();
// The live card's action, not a pending placeholder.
await expect(drawer.getByRole('button', { name: 'Add to Cart' })).toBeVisible();
});
});