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 { 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(); }); });