# 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/cycle-index.spec.ts >> homepage never waits or displays zero for pending heavy counts, and fills them on the next visit without polling
- Location: tests/ui/cycle-index.spec.ts:223:5

# Error details

```
Error: page.goto: net::ERR_CONNECTION_REFUSED at http://10.1.105.22/?cycle=2024
Call log:
  - navigating to "http://10.1.105.22/?cycle=2024", waiting until "load"

```

# Test source

```ts
  130 |     await expect.poll(() => requests.some(request => request.query.includes('query Counties'))).toBe(true);
  131 |     const counties = requests.filter(request => request.query.includes('query Counties')).at(-1);
  132 |     expect(counties).toBeTruthy();
  133 |     expect(counties!.query).not.toContain('Cycle');
  134 |     expect(counties!.variables?.cycle).toBeUndefined();
  135 |   });
  136 | 
  137 |   test('individual global cycle facet is passed to the API independently of lifetime/profile data', async ({ page, request }) => {
  138 |     await skipIfPremiumGated(request, '/individuals/');
  139 |     const requests = await mockAnonymousGraphQL(page, entityResponse);
  140 |     await page.goto('/individuals/?cycle=2024&f_state=TX');
  141 |     await expect(page.locator('.ei-cycle-notice')).toContainText(/2024.*all cycles|all cycles.*2024/i);
  142 |     await expect(page.locator('.entity-search-result').first()).toBeVisible();
  143 |     const browse = requests.find(request => request.query.includes('browseEntities('));
  144 |     expect(browse!.variables?.cycle).toBe(2024);
  145 |     expect(browse!.query).toContain('CycleBrowseEntities');
  146 |     await expect(page.locator('.entity-results-count, #entity-results-count')).toBeVisible();
  147 |     await expect.poll(() => requests.some(request => request.query.includes('CycleEntityFacets'))).toBe(true);
  148 |     const facets = requests.filter(request => request.query.includes('CycleEntityFacets'));
  149 |     for (const facet of facets) expect(facet.variables?.cycle).toBe(2024);
  150 |     expect(browse!.variables?.filters).toContainEqual({ field: 'state', values: ['TX'] });
  151 |   });
  152 | });
  153 | 
  154 | 
  155 | // Captured from pre-change persisted documents (baseline 1c2ed79). Pin the
  156 | // browser's legacy documents in addition to the API's Cypher fingerprints.
  157 | const legacyBrowseHash = '6cf0d0346d4ad92ee6ac58bb6bdd1c7109e80031f9770a285584fcd11c4beaa3';
  158 | const legacySearchHash = '1cc10eb69065f4bada75f2618cb56f3d2b40bc56d591f5cbd29bf1bd93c2509e';
  159 | const hashDocument = (query: string) => createHash('sha256').update(query.replace(/\s+/g, ' ').trim()).digest('hex');
  160 | 
  161 | for (const [collection, entityType, sortField] of [
  162 |   ['candidates', 'Politician', 'total_contributions'], ['committees', 'Committee', 'total_dollars'],
  163 | ]) {
  164 |   for (const suffix of ['', '?cycle=2023']) {
  165 |     test(`${collection}: legacy requests/rendering unchanged ${suffix || 'without cycle'}`, async ({ page }) => {
  166 |       const requests = await mockAnonymousGraphQL(page, entityResponse);
  167 |       await page.goto(`/${collection}/${suffix}`);
  168 |       await expect(page.locator('.entity-search-result').first()).toBeVisible();
  169 |       const browse = requests.find(r => r.query.includes('browseEntities('))!;
  170 |       expect(hashDocument(browse.query)).toBe(legacyBrowseHash);
  171 |       expect(browse.variables).toEqual({ entityType, page: 1, sortOrder: 'DESC', sortField });
  172 |       await expect(page.locator('.ei-cycle-notice')).toHaveCount(0);
  173 |       await expect(page.locator('#entity-results-count')).toHaveCount(0);
  174 |       await page.locator('#entity-search-input').fill('Smith');
  175 |       await page.locator('#entity-search-form').evaluate(form => (form as HTMLFormElement).requestSubmit());
  176 |       await expect.poll(() => requests.some(r => r.query.includes('searchEntities('))).toBe(true);
  177 |       const search = requests.find(r => r.query.includes('searchEntities('))!;
  178 |       expect(hashDocument(search.query)).toBe(legacySearchHash);
  179 |       expect(search.variables).toEqual({ entityType, page: 1, sortOrder: 'DESC', query: 'Smith', sortField });
  180 |     });
  181 |   }
  182 | }
  183 | 
  184 | const yearWhere = { OR: [
  185 |   { cycles: { eq: '2024' } }, { cycles: { startsWith: '2024,' } },
  186 |   { cycles: { endsWith: ',2024' } }, { cycles: { contains: ',2024,' } },
  187 | ] };
  188 | 
  189 | test('specialized state search and district selector scope their results and counts using exact CSV year tokens', async ({ page }) => {
  190 |   const requests = await mockAnonymousGraphQL(page, request => {
  191 |     if (request.query.includes('browseEntities(') || request.query.includes('searchEntities(')) return entityResponse(request);
  192 |     return { states: [{ id: 'state-1', name: 'Texas', state: 'TX' }], statesConnection: { totalCount: 1 } };
  193 |   });
  194 |   await page.goto('/states/?cycle=2024&q=Tex');
  195 |   await expect(page.locator('.state-result')).toContainText('Texas');
  196 |   await expect(page.locator('.ei-cycle-notice')).toContainText('2024');
  197 |   await expect(page.locator('.state-pagination-info')).toHaveText('Showing all 1 states');
  198 |   const states = requests.find(r => r.query.includes('query CycleStates'))!;
  199 |   expect(states.variables).toEqual({ offset: 0, where: { AND: [yearWhere, { name: { contains: 'Tex' } }] } });
  200 |   await page.goto('/districts/?cycle=2024&state=TX');
  201 |   await expect(page.locator('.entity-search-result').first()).toBeVisible({ timeout: 10000 });
  202 |   await expect(page.locator('.ei-cycle-notice')).toContainText('2024');
  203 |   const districts = requests.find(r => r.query.includes('CycleBrowseEntities') && r.variables?.entityType === 'District')!;
  204 |   expect(districts).toBeTruthy();
  205 |   expect(districts.variables?.cycle).toBe(2024);
  206 |   expect(String(districts.variables?.filter ?? '')).toContain('state:TX');
  207 |   const priorRequests = requests.length;
  208 |   await page.goto('/states/');
  209 |   await page.getByRole('button', { name: 'Grid', exact: true }).click();
  210 |   await expect(page.locator('.state-chip')).toHaveCount(52); // 50 states, DC and PR (rundeck#852)
  211 |   await expect(page.locator('.ei-cycle-notice')).toHaveCount(0);
  212 |   expect(requests.length).toBe(priorRequests); // The original timeless grid makes no GraphQL request.
  213 | });
  214 | 
  215 | test('catalog datasource list explicitly remains all cycles without changing its CMS request', async ({ page }) => {
  216 |   await mockAnonymousGraphQL(page);
  217 |   await page.goto('/datasources/?cycle=2024&q=FEC');
  218 |   await expect(page.locator('.ei-cycle-notice')).toContainText('Data sources cover all cycles');
  219 |   await page.goto('/datasources/?q=FEC');
  220 |   await expect(page.locator('.ei-cycle-notice')).toHaveCount(0);
  221 | });
  222 | 
  223 | test('homepage never waits or displays zero for pending heavy counts, and fills them on the next visit without polling', async ({ page }) => {
  224 |   let warm = false;
  225 |   const requests = await mockAnonymousGraphQL(page, () => ({ cycleEntityCounts: {
  226 |     counts: { ...Object.fromEntries(legacyCountFields.map(field => [field, 7])),
  227 |       individuals: warm ? 5999507 : null, employers: warm ? 929936 : null, vendors: warm ? 156307 : null },
  228 |     allCycles: ['blocks', 'counties'], pending: warm ? [] : ['individuals', 'employers', 'vendors'],
  229 |   } }));
> 230 |   await page.goto('/?cycle=2024');
      |              ^ Error: page.goto: net::ERR_CONNECTION_REFUSED at http://10.1.105.22/?cycle=2024
  231 |   await expect(page.locator('#count-politicians')).toHaveText('7');
  232 |   for (const field of ['individuals', 'employers', 'vendors']) {
  233 |     await expect(page.locator(`#count-${field}`)).toHaveText('…');
  234 |     await expect(page.locator(`#count-${field}`)).toHaveAttribute('title', /background/);
  235 |   }
  236 |   await expect(page.locator('.ei-cycle-notice')).toContainText('revisit');
  237 |   // One counts document and one voter-count document (sites#355) per visit: no polling.
  238 |   const counted = (operation: string) => requests.filter(r => r.query.includes(`query ${operation}(`)).length;
  239 |   expect(counted('CycleEntityCounts')).toBe(1);
  240 |   expect(counted('CycleVoterCount')).toBe(1);
  241 |   warm = true;
  242 |   await page.reload();
  243 |   await expect(page.locator('#count-individuals')).toHaveText('5,999,507');
  244 |   await expect(page.locator('#count-employers')).toHaveText('929,936');
  245 |   await expect(page.locator('#count-vendors')).toHaveText('156,307');
  246 |   expect(counted('CycleEntityCounts')).toBe(2);
  247 |   expect(counted('CycleVoterCount')).toBe(2);
  248 | });
  249 | 
  250 | test('slow Employer directory explicitly stays all cycles, while measured-fast Vendor lists retain the cycle', async ({ page }) => {
  251 |   const requests = await mockAnonymousGraphQL(page, entityResponse);
  252 |   await page.goto('/employers/?cycle=2024');
  253 |   await expect(page.locator('.entity-search-result').first()).toBeVisible();
  254 |   await expect(page.locator('.ei-cycle-notice')).toContainText('all cycles');
  255 |   await expect(page.locator('.ei-cycle-notice')).toContainText('slow graph scans');
  256 |   const employer = requests.find(r => r.variables?.entityType === 'Employer')!;
  257 |   expect(employer.variables?.cycle).toBeUndefined();
  258 |   expect(hashDocument(employer.query)).toBe(legacyBrowseHash);
  259 |   await page.goto('/vendors/?cycle=2024');
  260 |   await expect(page.locator('.entity-search-result').first()).toBeVisible();
  261 |   await expect(page.locator('.ei-cycle-notice')).toContainText('2024');
  262 |   const vendor = requests.find(r => r.variables?.entityType === 'Vendor')!;
  263 |   expect(vendor.variables?.cycle).toBe(2024);
  264 |   expect(vendor.query).toContain('CycleBrowseEntities');
  265 | });
  266 | 
```