# 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/entities.spec.ts >> entity browse sort order - quantitative fields >> candidates sorted by total contributions descending
- Location: tests/ui/entities.spec.ts:381:7

# Error details

```
TimeoutError: page.waitForResponse: Timeout 15000ms exceeded while waiting for event "response"
```

```
Error: page.goto: net::ERR_ABORTED; maybe frame was detached?
Call log:
  - navigating to "http://10.1.105.75/candidates/", waiting until "load"

```

# Test source

```ts
  272 |     await page.goto(TEXAS_PATH);
  273 |     const response = await responsePromise;
  274 | 
  275 |     const requestBody = JSON.parse(response.request().postData() || '{}');
  276 |     expect(requestBody.variables?.filter).toContain('office_state:TX');
  277 | 
  278 |     const json = await response.json();
  279 |     const results = json.data?.browseEntities?.results || [];
  280 |     expect(results.length).toBeGreaterThan(0);
  281 |   });
  282 | 
  283 |   test('state profile candidates sorted by total contributions descending', async ({ page }) => {
  284 |     const responsePromise = page.waitForResponse(resp => {
  285 |       if (!resp.url().includes('/api/graphql')) return false;
  286 |       if (resp.request().method() !== 'POST') return false;
  287 |       const body = resp.request().postData() || '';
  288 |       return body.includes('browseEntities');
  289 |     }, { timeout: DATA_LOAD_TIMEOUT });
  290 | 
  291 |     await page.goto(TEXAS_PATH);
  292 |     const response = await responsePromise;
  293 | 
  294 |     const json = await response.json();
  295 |     const results = json.data?.browseEntities?.results || [];
  296 |     expect(results.length).toBeGreaterThan(1);
  297 | 
  298 |     const contributions = results.map((r: { metadata?: string }) => {
  299 |       try {
  300 |         const meta = JSON.parse(r.metadata || '{}');
  301 |         return meta.total_contributions || 0;
  302 |       } catch { return 0; }
  303 |     });
  304 | 
  305 |     for (let i = 1; i < contributions.length; i++) {
  306 |       expect(contributions[i - 1]).toBeGreaterThanOrEqual(contributions[i]);
  307 |     }
  308 |   });
  309 | });
  310 | 
  311 | test.describe('district profile - dynamic candidates', () => {
  312 |   const DISTRICT_PATH = '/districts/tx-10/';
  313 | 
  314 |   test('district profile loads candidates filtered to district', async ({ page }) => {
  315 |     const responsePromise = page.waitForResponse(resp => {
  316 |       if (!resp.url().includes('/api/graphql')) return false;
  317 |       if (resp.request().method() !== 'POST') return false;
  318 |       const body = resp.request().postData() || '';
  319 |       return body.includes('browseEntities');
  320 |     }, { timeout: DATA_LOAD_TIMEOUT });
  321 | 
  322 |     await page.goto(DISTRICT_PATH);
  323 |     const response = await responsePromise;
  324 | 
  325 |     const requestBody = JSON.parse(response.request().postData() || '{}');
  326 |     const filter = requestBody.variables?.filter || '';
  327 |     expect(filter).toContain('office:H');
  328 |     expect(filter).toContain('office_state:TX');
  329 |     expect(filter).toContain('office_district:10');
  330 | 
  331 |     const json = await response.json();
  332 |     const results = json.data?.browseEntities?.results || [];
  333 |     expect(results.length).toBeGreaterThan(0);
  334 |   });
  335 | 
  336 |   test('district profile candidates sorted by total contributions descending', async ({ page }) => {
  337 |     const responsePromise = page.waitForResponse(resp => {
  338 |       if (!resp.url().includes('/api/graphql')) return false;
  339 |       if (resp.request().method() !== 'POST') return false;
  340 |       const body = resp.request().postData() || '';
  341 |       return body.includes('browseEntities');
  342 |     }, { timeout: DATA_LOAD_TIMEOUT });
  343 | 
  344 |     await page.goto(DISTRICT_PATH);
  345 |     const response = await responsePromise;
  346 | 
  347 |     const json = await response.json();
  348 |     const results = json.data?.browseEntities?.results || [];
  349 |     expect(results.length).toBeGreaterThan(1);
  350 | 
  351 |     const contributions = results.map((r: { metadata?: string }) => {
  352 |       try {
  353 |         const meta = JSON.parse(r.metadata || '{}');
  354 |         return meta.total_contributions || 0;
  355 |       } catch { return 0; }
  356 |     });
  357 | 
  358 |     for (let i = 1; i < contributions.length; i++) {
  359 |       expect(contributions[i - 1]).toBeGreaterThanOrEqual(contributions[i]);
  360 |     }
  361 |   });
  362 | });
  363 | 
  364 | // Helper to intercept browseEntities GraphQL response and extract score values
  365 | async function getBrowseScores(page: import('@playwright/test').Page, url: string): Promise<number[]> {
  366 |   const responsePromise = page.waitForResponse(resp => {
  367 |     if (!resp.url().includes('/api/graphql')) return false;
  368 |     if (resp.request().method() !== 'POST') return false;
  369 |     const body = resp.request().postData() || '';
  370 |     return body.includes('browseEntities');
  371 |   }, { timeout: DATA_LOAD_TIMEOUT });
> 372 |   await page.goto(url);
      |              ^ Error: page.goto: net::ERR_ABORTED; maybe frame was detached?
  373 |   const response = await responsePromise;
  374 |   const json = await response.json();
  375 |   const results = json.data?.browseEntities?.results || [];
  376 |   return results.map((r: { score?: number }) => r.score || 0);
  377 | }
  378 | 
  379 | test.describe('entity browse sort order - quantitative fields', () => {
  380 | 
  381 |   test('candidates sorted by total contributions descending', async ({ page }) => {
  382 |     const scores = await getBrowseScores(page, '/candidates/');
  383 |     expect(scores.length).toBeGreaterThan(1);
  384 |     for (let i = 1; i < scores.length; i++) {
  385 |       expect(scores[i - 1]).toBeGreaterThanOrEqual(scores[i]);
  386 |     }
  387 |   });
  388 | 
  389 |   test('committees sorted by total receipts descending', async ({ page }) => {
  390 |     const scores = await getBrowseScores(page, '/committees/');
  391 |     expect(scores.length).toBeGreaterThan(1);
  392 |     for (let i = 1; i < scores.length; i++) {
  393 |       expect(scores[i - 1]).toBeGreaterThanOrEqual(scores[i]);
  394 |     }
  395 |   });
  396 | 
  397 |   test('vendors sorted by total received descending', async ({ page }) => {
  398 |     const scores = await getBrowseScores(page, '/vendors/');
  399 |     expect(scores.length).toBeGreaterThan(1);
  400 |     for (let i = 1; i < scores.length; i++) {
  401 |       expect(scores[i - 1]).toBeGreaterThanOrEqual(scores[i]);
  402 |     }
  403 |   });
  404 | 
  405 |   test('individuals sorted by total contributions descending', async ({ page, baseURL }) => {
  406 |     await premiumVisitor(page.context(), baseURL); // donor records are premium (sites#277)
  407 |     const scores = await getBrowseScores(page, '/individuals/');
  408 |     expect(scores.length).toBeGreaterThan(1);
  409 |     // A stale search index scores every donor 0 and the order means nothing.
  410 |     expect(scores[0], 'top individual donor should have contributions').toBeGreaterThan(0);
  411 |     for (let i = 1; i < scores.length; i++) {
  412 |       expect(scores[i - 1]).toBeGreaterThanOrEqual(scores[i]);
  413 |     }
  414 |   });
  415 | 
  416 |   test('employers sorted by total employee contributions descending', async ({ page }) => {
  417 |     const scores = await getBrowseScores(page, '/employers/');
  418 |     expect(scores.length).toBeGreaterThan(1);
  419 |     for (let i = 1; i < scores.length; i++) {
  420 |       expect(scores[i - 1]).toBeGreaterThanOrEqual(scores[i]);
  421 |     }
  422 |   });
  423 | });
  424 | 
  425 | test.describe('us.elect.info entity sections - additional index + detail', () => {
  426 | 
  427 |   test('employers section - index and random pages', async ({ page }) => {
  428 |     const indexResponse = await page.goto('/employers/');
  429 |     expect(indexResponse?.status(), '/employers/ should answer 200').toBe(200);
  430 |     await expect(page.locator('h1')).toContainText(/Employers/i);
  431 | 
  432 |     await expect(page.locator('.entity-search-result').first()).toBeVisible({ timeout: DATA_LOAD_TIMEOUT });
  433 | 
  434 |     const links = await page.locator('.entity-search-result').all();
  435 |     expect(links.length).toBeGreaterThan(0);
  436 | 
  437 |     const hrefs = await Promise.all(links.slice(0, 20).map(l => l.getAttribute('href')));
  438 |     const randomLinks = getRandomItems(hrefs.filter(Boolean) as string[], 3);
  439 | 
  440 |     for (const href of randomLinks) {
  441 |       const entityResponse = await page.goto(toRelativePath(href));
  442 |       expect(entityResponse?.status(), `${toRelativePath(href)} should answer 200`).toBe(200);
  443 |       await expect(page.locator('h1')).toBeVisible();
  444 |     }
  445 |   });
  446 | 
  447 |   test('vendors section - index and random pages', async ({ page }) => {
  448 |     const indexResponse = await page.goto('/vendors/');
  449 |     expect(indexResponse?.status(), '/vendors/ should answer 200').toBe(200);
  450 |     await expect(page.locator('h1')).toContainText(/Vendors/i);
  451 | 
  452 |     await expect(page.locator('.entity-search-result').first()).toBeVisible({ timeout: DATA_LOAD_TIMEOUT });
  453 | 
  454 |     const links = await page.locator('.entity-search-result').all();
  455 |     expect(links.length).toBeGreaterThan(0);
  456 | 
  457 |     const hrefs = await Promise.all(links.slice(0, 20).map(l => l.getAttribute('href')));
  458 |     const randomLinks = getRandomItems(hrefs.filter(Boolean) as string[], 3);
  459 | 
  460 |     for (const href of randomLinks) {
  461 |       const entityResponse = await page.goto(toRelativePath(href));
  462 |       expect(entityResponse?.status(), `${toRelativePath(href)} should answer 200`).toBe(200);
  463 |       await expect(page.locator('h1')).toBeVisible();
  464 |     }
  465 |   });
  466 | 
  467 |   test('counties section - index and random detail pages', async ({ page }) => {
  468 |     await page.goto('/counties/');
  469 | 
  470 |     // Map view is default — verify Leaflet map renders with GeoJSON state shapes
  471 |     await expect(page.locator('#map.leaflet-container')).toBeVisible({ timeout: DATA_LOAD_TIMEOUT });
  472 |     await expect(page.locator('#map .leaflet-interactive').first()).toBeVisible({ timeout: DATA_LOAD_TIMEOUT });
```