import { test, expect, createItem, uniqueSuffix } from './fixtures'; /** * Puts an item in the signed-in customer's cart, which is the only way an item * legitimately reaches 'reserved'. * * The `customer` fixture supplies the session, so this only has to seed the * item and add it — a pending item cannot be reserved, hence publishing first, * which `createItem` does by default. */ async function reserve( request: import('@playwright/test').APIRequestContext, itemName: string ): Promise { const item = await createItem(request, { name: itemName, price: '75' }); expect((await request.post(`/api/cart/items/${item.id}`)).status()).toBe(201); return item.id; } test.describe('Admin reserved items', () => { test('shows a reserved count that opens the held items', async ({ page, customer, admin, adminCustomers }) => { const itemName = `Held r${uniqueSuffix()}`; await reserve(page.request, itemName); await admin.open('Customers'); await expect(adminCustomers.row(customer.email)).toBeVisible(); await adminCustomers.reservedCountButton(customer.email).click(); await expect(adminCustomers.reservedItemsDialog.getByText(itemName)).toBeVisible(); }); test('releasing an item returns it to the storefront as available', async ({ page, customer, admin, adminCustomers }) => { const itemName = `Freed r${uniqueSuffix()}`; const itemId = await reserve(page.request, itemName); await admin.open('Customers'); await adminCustomers.reservedCountButton(customer.email).click(); await adminCustomers.reservedItemsDialog.getByRole('button', { name: 'Release' }).click(); await expect(page.getByText(`Released "${itemName}"`)).toBeVisible(); // The point of releasing is that the item becomes purchasable again. const item = await (await page.request.get(`/api/items/${itemId}`)).json(); expect(item.status).toBe('available'); }); test('the count drops once the item is released', async ({ page, customer, admin, adminCustomers }) => { await reserve(page.request, `Recount r${uniqueSuffix()}`); await admin.open('Customers'); await adminCustomers.reservedCountButton(customer.email).click(); const dialog = adminCustomers.reservedItemsDialog; await dialog.getByRole('button', { name: 'Release' }).click(); await expect(dialog.getByText("This customer isn't holding any items")).toBeVisible(); // The row behind the dialog must agree with the dialog it opened. await dialog.getByRole('button', { name: 'Close' }).click(); await expect(adminCustomers.reservedCountButton(customer.email)).toHaveCount(0); }); test('a customer holding nothing shows no link to click', async ({ customer, admin, adminCustomers }) => { await admin.open('Customers'); await expect(adminCustomers.row(customer.email)).toBeVisible(); await expect(adminCustomers.reservedCountButton(customer.email)).toHaveCount(0); }); });