import { test, expect } from './fixtures'; test.describe('Storefront failure states', () => { test('reports a server failure instead of claiming the store is empty', async ({ page }) => { await page.route('**/api/items*', (route) => route.fulfill({ status: 500, contentType: 'application/json', body: '{"error":"internal error"}' }) ); await page.goto('/'); // Telling a customer "no items yet" when the server is broken is worse than // saying nothing — it reads as an empty catalogue and hides the outage. await expect(page.getByText('No items yet')).toBeHidden(); await expect(page.getByText("Couldn't load items")).toBeVisible(); await expect(page.getByRole('button', { name: 'Retry' })).toBeVisible(); }); test('recovers when the server comes back', async ({ page }) => { let failing = true; await page.route('**/api/items*', (route) => { if (failing) { return route.fulfill({ status: 500, contentType: 'application/json', body: '{"error":"internal error"}' }); } return route.continue(); }); await page.goto('/'); await expect(page.getByRole('button', { name: 'Retry' })).toBeVisible(); failing = false; await page.getByRole('button', { name: 'Retry' }).click(); await expect(page.getByText("Couldn't load items")).toBeHidden(); }); test('a request that never resolves does not render as an empty catalogue', async ({ page }) => { // Mirrors the real incident: an un-migrated database left every item query // hanging with no response at all. await page.route('**/api/items*', () => { /* never fulfilled */ }); await page.goto('/'); await expect(page.getByText('No items yet')).toBeHidden(); }); });