# 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/entity-graph.spec.ts >> entity-graph pop-over >> opens and draws on /candidates/a8897257-430c-2bf3-4498-349021b09ca3/
- Location: tests/ui/entity-graph.spec.ts:62:9

# Error details

```
Test timeout of 30000ms exceeded.
```

```
Error: expect(locator).toBeVisible() failed

Locator: locator('dialog.eg-dialog').locator('.eg-canvas canvas').first()
Expected: visible
Error: element(s) not found

Call log:
  - Expect "toBeVisible" locator('dialog.eg-dialog').locator('.eg-canvas canvas').first() with timeout 60000ms
  - waiting for locator('dialog.eg-dialog').locator('.eg-canvas canvas').first()
  - Test timeout of 30000ms exceeded.

```

```yaml
- banner:
  - heading "HARRIS, KAMALA" [level=1]
  - paragraph: Democratic Party candidate for President of the United States
  - paragraph: "FEC ID: P00009423"
  - button "Graph"
- heading "Profile" [level=2]
- term: Party
- definition:
  - link "Democratic Party":
    - /url: https://us.elect.info/parties/democratic/
- term: Office
- definition:
  - link "President of the United States":
    - /url: https://us.elect.info/offices/president/
- term: Status
- definition: Prior Candidate (Not Current) (Challenger)
- term: Home Location
- definition: PHILADELPHIA, Pennsylvania 19102
- heading "Campaign Timeline" [level=2]
- term: Election Years
- definition:
  - link "2026":
    - /url: https://us.elect.info/elections/2026/
  - text: ","
  - link "2024":
    - /url: https://us.elect.info/elections/2024/
  - text: ","
  - link "2022":
    - /url: https://us.elect.info/elections/2022/
  - text: ","
  - link "2020":
    - /url: https://us.elect.info/elections/2020/
- term: First Campaign
- definition: "2020"
- term: Most Recent
- definition: "2024"
- heading "Campaign Funding" [level=2]
- term: Total Received
- definition:
  - strong: $4.6M
- term: Contributing Committees
- definition: "6715"
- heading "Top Contributors" [level=3]
- group "View":
  - button "Sankey view" [pressed]
  - button "Table view"
- img "Top Contributors as a Sankey diagram. Switch to table view for the list."
- paragraph: Showing top 10 of 78
- heading "Independent Expenditures Supporting" [level=2]
- group "View":
  - button "Sankey view" [pressed]
  - button "Table view"
- paragraph: Spending by outside groups for this candidate, made independently of the campaign. Not a contribution to the campaign.
- img "Independent Expenditures Supporting as a Sankey diagram. Switch to table view for the list."
- paragraph: Showing top 10 of 292
- heading "Independent Expenditures Opposing" [level=2]
- group "View":
  - button "Sankey view" [pressed]
  - button "Table view"
- paragraph: Spending by outside groups against this candidate, made independently of any campaign.
- img "Independent Expenditures Opposing as a Sankey diagram. Switch to table view for the list."
- paragraph: Showing top 10 of 79
- heading "Supporting Committees" [level=2]
- term: Principal Committee
- definition:
  - link "FIGHT FOR THE PEOPLE PAC":
    - /url: https://us.elect.info/committees/fight-for-the-people-pac-c00703975/
- heading "Other Supporting Committees" [level=3]
- list:
  - listitem:
    - link "DEMOCRATIC CLUB OF WEST ORANGE COUNTY":
      - /url: https://us.elect.info/committees/democratic-club-of-west-orange-county-c00444117/
    - text: (PAC - Nonqualified) [2020, 2022, 2024, 2026]
  - listitem:
    - link "LANGEVIN FOR CONGRESS":
      - /url: https://us.elect.info/committees/langevin-for-congress-c00344697/
    - text: (House Campaign) [2020, 2022, 2024, 2026]
  - listitem:
    - link "REPRODUCTIVE FREEDOM FOR ALL PAC":
      - /url: https://us.elect.info/committees/reproductive-freedom-for-all-pac-c00079541/
    - text: (PAC - Qualified) [2020, 2022, 2024, 2026]
  - listitem:
    - link "HUMAN RIGHTS CAMPAIGN PAC":
      - /url: https://us.elect.info/committees/human-rights-campaign-pac-c00235853/
    - text: (PAC - Qualified) [2020, 2022, 2024, 2026]
  - listitem:
    - link "THE MAJORITY RULES":
      - /url: https://us.elect.info/committees/the-majority-rules-c00629063/
    - text: (PAC - Qualified) [2020, 2022, 2024, 2026]
  - listitem:
    - link "LINDA COLEMAN FOR CONGRESS":
      - /url: https://us.elect.info/committees/linda-coleman-for-congress-c00658286/
    - text: (House Campaign) [2020, 2022, 2024, 2026]
  - listitem:
    - link "SIKH PAC":
      - /url: https://us.elect.info/committees/sikh-pac-c00543652/
    - text: (PAC - Qualified) [2020, 2022, 2024, 2026]
  - listitem:
    - link "PEARLPAC":
      - /url: https://us.elect.info/committees/pearlpac-c00803494/
    - text: (PAC - Qualified) [2022, 2024, 2026]
  - listitem:
    - link "ASIAN AMERICAN ACTION FUND":
      - /url: https://us.elect.info/committees/asian-american-action-fund-c00351031/
    - text: (PAC - Qualified) [2020, 2022, 2024, 2026]
  - listitem:
    - link "MOTOR CITY PAC":
      - /url: https://us.elect.info/committees/motor-city-pac-c00507574/
    - text: (PAC - Qualified) [2020, 2022, 2024, 2026]
  - listitem:
    - link "BEND THE ARC JEWISH ACTION INC. PAC":
      - /url: https://us.elect.info/committees/bend-the-arc-jewish-action-inc-pac-c00573253/
    - text: (PAC - Qualified) [2020, 2022, 2024, 2026]
  - listitem:
    - link "CASTOR FOR CONGRESS":
      - /url: https://us.elect.info/committees/castor-for-congress-c00410761/
    - text: (House Campaign) [2020, 2022, 2024, 2026]
  - listitem:
    - link "PROMISE PAC":
      - /url: https://us.elect.info/committees/promise-pac-c00528992/
    - text: (PAC - Nonqualified) [2020, 2022, 2024]
  - listitem:
    - link "ALPHA POLITICAL ACTION COMMITTEE":
      - /url: https://us.elect.info/committees/alpha-political-action-committee-c00747907/
    - text: (PAC - Qualified) [2020, 2022, 2024, 2026]
  - listitem:
    - link "CITY OF ALAMEDA DEMOCRATIC CLUB FEDERAL PAC":
      - /url: https://us.elect.info/committees/city-of-alameda-democratic-club-federal-pac-c00410167/
    - text: (PAC - Nonqualified) [2020, 2022, 2024, 2026]
  - listitem:
    - link "SIERRA CLUB POLITICAL COMMITTEE":
      - /url: https://us.elect.info/committees/sierra-club-political-committee-c00135368/
    - text: (PAC - Qualified) [2020, 2022, 2024, 2026]
  - listitem:
    - link "OCCUPY DEMOCRATS ELECTION FUND":
      - /url: https://us.elect.info/committees/occupy-democrats-election-fund-c00718510/
    - text: (PAC with Non-Contribution Account - Qualified) [2020, 2022, 2024, 2026]
  - listitem:
    - link "ALPHA KAPPA ALPHA SORORITY PAC, INC. (AKA AKA 1908 PAC)":
      - /url: https://us.elect.info/committees/alpha-kappa-alpha-sorority-pac-inc-aka-aka-1908-pac-c00886036/
    - text: (PAC - Qualified) [2024, 2026]
  - listitem:
    - link "INTERNATIONAL LONGSHORE AND WAREHOUSE UNION -- POLITICAL ACTION FUND":
      - /url: https://us.elect.info/committees/international-longshore-and-warehouse-union-political-action-fund-c00176214/
    - text: (PAC - Qualified) [2020, 2022, 2024, 2026]
  - listitem:
    - link "EVERYTOWN FOR GUN SAFETY ACTION FUND, INC. PAC (EVERYTOWN PAC)":
      - /url: https://us.elect.info/committees/everytown-for-gun-safety-action-fund-inc-pac-everytown-pac-c00640086/
    - text: (PAC - Qualified) [2020, 2022, 2024, 2026]
- contentinfo:
  - paragraph:
    - link "elect.info":
      - /url: https://us.elect.info/
    - text: "| Data from"
    - link "Federal Election Commission":
      - /url: https://us.elect.info/datasources/fec_bulk/
    - text: "| Generated 2026-10-09"
- 'dialog "HARRIS, KAMALA: graph of connected entities"':
  - heading "HARRIS, KAMALA — connected entities" [level=2]
  - button "Fit"
  - button "Close graph": Close
  - img "Network graph of HARRIS, KAMALA and its most significant connections": No connected entities to show.
  - text: Committee Candidate Vendor Party State / place Office Cycle Committees and candidates are tinted by party
```

# Test source

```ts
  1  | import { test, expect } from '@playwright/test';
  2  | 
  3  | // Entity graph pop-over (electinfo/sites#249). nginx injects /js/entity-graph.js
  4  | // next to money-flow.js on Candidate and Committee detail pages. The script
  5  | // adds a "Graph" button to the header; opening it fetches entityGraph from
  6  | // /api/graphql, loads /js/entity-graph-view.js (Cytoscape) and draws the node
  7  | // and its most significant neighbours in a modal dialog.
  8  | //
  9  | // Same targets and pages as money-flow.spec.ts.
  10 | 
  11 | const SCRIPT = '<script src="/js/entity-graph.js" defer></script>';
  12 | const DNC = '/committees/a75a9110-f1db-a945-39a8-7503ed3c04da/'; // C00010603
  13 | const HARRIS = '/candidates/a8897257-430c-2bf3-4498-349021b09ca3/'; // P00009423
  14 | const OTHER_PAGES = [
  15 |   '/states/032f8d61-f554-f435-2a6d-50b3c8cc01d7/', // AK
  16 |   '/elections/2024/',
  17 |   '/offices/president/',
  18 | ];
  19 | 
  20 | test.describe('entity-graph script injection', () => {
  21 |   for (const path of [DNC, HARRIS]) {
  22 |     test(`injected once on ${path}`, async ({ request }) => {
  23 |       const res = await request.get(path);
  24 |       expect(res.status()).toBe(200);
  25 |       expect((await res.text()).split(SCRIPT).length - 1).toBe(1);
  26 |     });
  27 |   }
  28 | 
  29 |   for (const path of OTHER_PAGES) {
  30 |     test(`not injected on ${path}`, async ({ request }) => {
  31 |       const res = await request.get(path);
  32 |       expect(res.status()).toBe(200);
  33 |       expect(await res.text()).not.toContain('entity-graph.js');
  34 |     });
  35 |   }
  36 | });
  37 | 
  38 | test.describe('entityGraph API', () => {
  39 |   for (const fecId of ['C00010603', 'P00009423']) {
  40 |     test(`${fecId}: neighbours without individuals, money edges with amounts`, async ({ request }) => {
  41 |       const res = await request.post('/api/graphql', {
  42 |         data: {
  43 |           query: 'query($f: String!) { entityGraph(fecId: $f) { focalId nodes { id label labels focal displayName } edges { type amount } } }',
  44 |           variables: { f: fecId },
  45 |         },
  46 |         timeout: 60000,
  47 |       });
  48 |       expect(res.status()).toBe(200);
  49 |       const g = (await res.json())?.data?.entityGraph;
  50 |       expect(g).toBeTruthy();
  51 |       expect(g.nodes.filter((n: { focal: boolean }) => n.focal)).toHaveLength(1);
  52 |       expect(g.nodes.length).toBeGreaterThan(5);
  53 |       expect(g.nodes.some((n: { labels: string[] }) => n.labels.includes('Individual'))).toBe(false);
  54 |       expect(g.nodes.every((n: { displayName: string }) => !!n.displayName)).toBe(true);
  55 |       expect(g.edges.some((e: { amount: number | null }) => e.amount != null && e.amount > 0)).toBe(true);
  56 |     });
  57 |   }
  58 | });
  59 | 
  60 | test.describe('entity-graph pop-over', () => {
  61 |   for (const path of [DNC, HARRIS]) {
  62 |     test(`opens and draws on ${path}`, async ({ page }) => {
  63 |       const errors: string[] = [];
  64 |       page.on('pageerror', (e) => errors.push(String(e)));
  65 |       await page.goto(path);
  66 |       const button = page.locator('button.eg-open');
  67 |       await expect(button).toHaveCount(1, { timeout: 15000 });
  68 |       await button.click();
  69 |       const dialog = page.locator('dialog.eg-dialog');
  70 |       await expect(dialog).toBeVisible();
> 71 |       await expect(dialog.locator('.eg-canvas canvas').first()).toBeVisible({ timeout: 60000 });
     |                                                                 ^ Error: expect(locator).toBeVisible() failed
  72 |       // centred in the viewport, horizontally and vertically
  73 |       const box = (await dialog.boundingBox())!;
  74 |       const vp = page.viewportSize()!;
  75 |       expect(Math.abs(box.x - (vp.width - box.x - box.width))).toBeLessThanOrEqual(2);
  76 |       expect(Math.abs(box.y - (vp.height - box.y - box.height))).toBeLessThanOrEqual(2);
  77 |       await page.keyboard.press('Escape');
  78 |       await expect(dialog).toBeHidden();
  79 |       expect(errors).toEqual([]);
  80 |     });
  81 |   }
  82 | });
  83 | 
```