# Instructions

- Following Playwright test failed.
- Explain why, be concise, respect Playwright best practices.
- Provide a snippet of code with the fix, if possible.

# Test info

- Name: tests/ui/district-delegates.spec.ts >> PR delegate district has a current00 canonical and historical98 redirect
- Location: tests/ui/district-delegates.spec.ts:11:7

# Error details

```
Error: page.goto: net::ERR_CONNECTION_REFUSED at http://10.1.105.22/districts/?state=PR&tab=congressional
Call log:
  - navigating to "http://10.1.105.22/districts/?state=PR&tab=congressional", waiting until "load"

```

```
Error: page.waitForResponse: Test ended.
```

# Test source

```ts
  1  | import { test, expect } from '@playwright/test';
  2  | import { canonicalPath, toRelativePath } from './helpers';
  3  | 
  4  | // Release contract after the coordinated graph + PagePaths cutover (#462): all six
  5  | // delegates exist as current00 entities; the index and00 alias serve them, their
  6  | // live UUID pages canonicalize to00, and historical98 aliases redirect to00.
  7  | // This is intentionally red on the old98 graph / stale alias snapshot. The local
  8  | // district-categories fixture still proves98 rows keep safe current-UUID links;
  9  | // neither that fixture nor these inventory assertions may be skipped for missing rows.
  10 | for (const state of ['AS', 'GU', 'MP', 'VI', 'DC', 'PR']) {
  11 |   test(`${state} delegate district has a current00 canonical and historical98 redirect`, async ({ page, request }) => {
> 12 |     const dataResponse = page.waitForResponse(response => {
     |                               ^ Error: page.waitForResponse: Test ended.
  13 |       if (!response.url().includes('/api/graphql') || response.request().method() !== 'POST') return false;
  14 |       try {
  15 |         const body = response.request().postDataJSON();
  16 |         const variables = body?.variables;
  17 |         const filters = String(variables?.filter).split(',');
  18 |         return /\bbrowseEntities\s*\(/.test(body?.query || '') && variables?.entityType === 'District' &&
  19 |           filters.includes('district_type:cd') && filters.includes(`state:${state}`);
  20 |       } catch { return false; }
  21 |     });
  22 |     await page.goto(`/districts/?state=${state}&tab=congressional`);
  23 |     const payload = await (await dataResponse).json();
  24 |     expect(payload.errors, `${state}: current inventory query must succeed`).toBeUndefined();
  25 |     const inventory = payload.data?.browseEntities;
  26 |     expect(inventory?.total, `${state}: full congressional inventory must contain exactly one delegate`).toBe(1);
  27 |     expect(inventory?.hasMore, `${state}: delegate inventory must not be truncated`).toBe(false);
  28 |     const rows = inventory?.results;
  29 |     expect(rows, `${state}: exactly one delegate must remain in the graph`).toHaveLength(1);
  30 |     const row = rows[0];
  31 |     expect(row.state).toBe(state);
  32 |     expect(row.district).toBe('00');
  33 |     const metadata = JSON.parse(row.metadata || '{}');
  34 |     expect(metadata.district_type).toBe('cd');
  35 |     expect(metadata.district_slug.toLowerCase()).toBe(`${state.toLowerCase()}-00`);
  36 |     expect(row.id).toMatch(/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i);
  37 | 
  38 |     await expect(page.locator('#district-state-select')).toHaveValue(state);
  39 |     const result = page.locator('.entity-search-result');
  40 |     await expect(result).toHaveCount(1, { timeout: 15000 });
  41 |     await expect(result).toContainText(`${state}-00`);
  42 |     const canonical = `/districts/${state.toLowerCase()}-00/`;
  43 |     await expect(result).toHaveAttribute('href', canonical);
  44 |     const response = await page.goto(canonical);
  45 |     expect(response?.status(), `${state}:00 must serve, not redirect or miss`).toBe(200);
  46 |     await expect(page.locator('h1')).toBeVisible();
  47 |     expect(canonicalPath(await page.content())).toBe(canonical);
  48 | 
  49 |     const storage = await request.get(`/districts/${row.id}/`, { maxRedirects: 0 });
  50 |     expect(storage.status(), `${state}: graph-current UUID page must serve`).toBe(200);
  51 |     expect(canonicalPath(await storage.text()), `${state}: current UUID must share00 canonical`).toBe(canonical);
  52 |     const historical = await request.get(`/districts/${state.toLowerCase()}-98/`, { maxRedirects: 0 });
  53 |     expect(historical.status(), `${state}:98 must redirect rather than retire or retain an old owner`).toBe(301);
  54 |     expect(toRelativePath(historical.headers()['location'] || '')).toBe(canonical);
  55 |   });
  56 | }
  57 | 
```