import { test, expect, createItem, uniqueSuffix } from './fixtures'; const DESCRIPTION = 'A preview subject'; test.describe('Admin item preview', () => { test('opens the storefront card from the item name', async ({ page, admin, adminInventory }) => { const name = `Preview p${uniqueSuffix()}`; await createItem(page.request, { name, price: '42', description: DESCRIPTION }); await admin.goto(); await adminInventory.openPreview(name); const drawer = adminInventory.previewDrawer(name); await expect(drawer).toBeVisible(); // The card itself, not just an empty panel: the storefront renders the // price formatted from cents, so this only passes if ItemCard rendered. await expect(drawer.getByText('$42.00')).toBeVisible(); }); // The claim the preview has to make: it looks live, and it is not. The // buttons must keep their normal appearance rather than being disabled, // because showing a customer's view is the entire purpose of the panel. test('shows the Add to Cart button in its normal enabled state', async ({ page, admin, adminInventory }) => { const name = `Preview p${uniqueSuffix()}`; await createItem(page.request, { name, price: '15', description: DESCRIPTION }); await admin.goto(); await adminInventory.openPreview(name); const addToCart = adminInventory.previewDrawer(name).getByRole('button', { name: 'Add to Cart' }); await expect(addToCart).toBeVisible(); await expect(addToCart).toBeEnabled(); }); // The assertion that matters, and the one a reviewer cannot make by looking // at the screen. Signed out, a real Add to Cart opens the sign-in prompt // before it can add anything — so if that modal never appears, the handler // short-circuited before reaching any of its real work. test('does not act when the preview card is clicked', async ({ page, admin, adminInventory }) => { const name = `Preview p${uniqueSuffix()}`; await createItem(page.request, { name, price: '99', description: DESCRIPTION }); await admin.goto(); await adminInventory.openPreview(name); const drawer = adminInventory.previewDrawer(name); await drawer.getByRole('button', { name: 'Add to Cart' }).click(); // Nothing succeeded and nothing prompted. await expect(page.getByText('Added to cart')).toHaveCount(0); await expect(page.getByRole('dialog', { name: /sign in/i })).toHaveCount(0); // And the drawer is still simply sitting there, unchanged. await expect(drawer).toBeVisible(); await expect(drawer.getByRole('button', { name: 'Add to Cart' })).toBeEnabled(); }); // The storefront card must stay live where it is actually used, or this // change would have quietly broken buying things. test('leaves the real storefront card working', async ({ page, storefront }) => { const name = `Live p${uniqueSuffix()}`; await createItem(page.request, { name, price: '20', description: DESCRIPTION }); await storefront.goto(); await expect(storefront.card(name)).toBeVisible(); await storefront.addToCartButton(name).click(); // Signed out, the real card prompts for sign-in — proof the handler ran. await expect(page.getByRole('dialog')).toBeVisible(); }); });