# 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: src/manager/tests/e2e/invoice/invoice-download.spec.ts >> downloads the invoice pdf from the details page
- Location: src/manager/tests/e2e/invoice/invoice-download.spec.ts:60:5

# Error details

```
Test timeout of 120000ms exceeded.
```

```
Error: page.waitForEvent: Test timeout of 120000ms exceeded.
=========================== logs ===========================
waiting for event "download"
============================================================
```

# Page snapshot

```yaml
- generic [ref=e1]:
  - generic [ref=e6]:
    - navigation [ref=e7]:
      - generic [ref=e9]:
        - link [ref=e10] [cursor=pointer]:
          - /url: /
        - generic [ref=e11]:
          - generic [ref=e12]: KINNOVIS
          - generic [ref=e13]: Manager
        - button [ref=e15] [cursor=pointer]
      - list [ref=e19]:
        - generic [ref=e21]: Dashboard
        - link "Tasks" [ref=e23] [cursor=pointer]:
          - /url: /tasks
        - link "Facility maps" [ref=e30] [cursor=pointer]:
          - /url: /facility-map
          - generic [ref=e31]: 󰧾
        - link "Analytics" [ref=e35] [cursor=pointer]:
          - /url: /dashboard
          - generic [ref=e36]: 󱖶
        - generic [ref=e40]: Sales
        - link "Bookings" [ref=e42] [cursor=pointer]:
          - /url: /bookings
          - generic [ref=e43]: 󰇡
        - link "Customers" [ref=e47] [cursor=pointer]:
          - /url: /customers
          - generic [ref=e48]: 󰀏
        - link "Invoices" [ref=e52] [cursor=pointer]:
          - /url: /invoices
          - generic [ref=e53]: 󰷉
        - link "Credit notes" [ref=e57] [cursor=pointer]:
          - /url: /credit-notes
        - link "Units" [ref=e64] [cursor=pointer]:
          - /url: /units
          - generic [ref=e65]: 󰍀
        - generic [ref=e69]: Site management
        - link "Locations" [ref=e71] [cursor=pointer]:
          - /url: /locations
          - generic [ref=e72]: 󰟙
        - link "Unit types" [ref=e76] [cursor=pointer]:
          - /url: /unit-types
          - generic [ref=e77]: 󰆧
        - link "Protection Plans" [ref=e81] [cursor=pointer]:
          - /url: /insurances
          - generic [ref=e82]: 󰳌
        - link "Deposits" [ref=e86] [cursor=pointer]:
          - /url: /deposits
          - generic [ref=e87]: 󱙆
        - link "Products" [ref=e91] [cursor=pointer]:
          - /url: /products
          - generic [ref=e92]: 󰄑
        - link "Discounts" [ref=e96] [cursor=pointer]:
          - /url: /discounts
          - generic [ref=e97]: 󰓼
        - generic [ref=e101]:
          - option "Emails" [ref=e102] [cursor=pointer]:
            - generic [ref=e103]: 󰻨
            - generic [ref=e107]: 󰅀
          - text: 󱡰 󰁥
        - generic [ref=e111]: Admin
        - link "Integrations" [ref=e113] [cursor=pointer]:
          - /url: /connected-apps
          - generic [ref=e114]: 󱘖
        - link "User & Roles" [ref=e118] [cursor=pointer]:
          - /url: /users
          - generic [ref=e119]: 󰭘
        - generic [ref=e123]:
          - option "Booking Portal" [ref=e124] [cursor=pointer]:
            - generic [ref=e125]: 󱃁
            - generic [ref=e129]: 󰅀
          - text: 󰖟 󰟙
        - link "Public API" [ref=e133] [cursor=pointer]:
          - /url: /public-api
          - generic [ref=e134]: 󱂛
        - generic [ref=e138]: Feedback
        - link "Voting Portal" [ref=e140] [cursor=pointer]:
          - /url: /voting-portal
          - generic [ref=e141]: 󰔔
      - generic [ref=e147]:
        - button "AS Andreas Stadler andreas.stadler@storeroom.at" [ref=e150] [cursor=pointer]:
          - generic [ref=e151]: AS
          - generic [ref=e154]:
            - generic [ref=e155]: Andreas Stadler
            - generic "andreas.stadler@storeroom.at" [ref=e156]
          - generic [ref=e157]: 󰇙
          - generic: 󰗊 󰅀 󰷖 󰍃
        - button [ref=e158] [cursor=pointer]:
          - generic [ref=e159]: 󰋽
    - main [ref=e161]:
      - generic [ref=e163]:
        - generic [ref=e165]:
          - generic [ref=e166]:
            - link "Invoices" [ref=e167] [cursor=pointer]:
              - /url: /invoices
            - generic [ref=e169]: 󰅂
            - generic [ref=e170]: INV-2201425
            - generic [ref=e171]: Open
          - button "Actions Download invoice PDF Send invoice again Issue credit note Charge customer for invoice Pay with balance Change status Mark as Paid Mark as Voided" [expanded] [active] [ref=e177] [cursor=pointer]:
            - generic [ref=e178]:
              - text: Actions
              - generic [ref=e179]: 󱨉
            - list [ref=e182]:
              - generic [ref=e183]:
                - listitem:
                  - generic:
                    - generic:
                      - generic: 󰇚
                      - generic: Download invoice PDF
              - listitem [ref=e184]:
                - generic [ref=e186]:
                  - generic [ref=e187]: 󱴆
                  - generic [ref=e188]: Send invoice again
              - link "Issue credit note" [ref=e190]:
                - /url: /invoices/1959339358/issue-credit-note
                - generic [ref=e192]:
                  - generic [ref=e193]: 󱳱
                  - generic [ref=e194]: Issue credit note
              - listitem [ref=e196]:
                - generic [ref=e198]:
                  - generic [ref=e199]: 󱤒
                  - generic [ref=e200]: Charge customer for invoice
              - generic [ref=e201]:
                - listitem:
                  - generic:
                    - generic:
                      - generic: 󰆛
                      - generic: Pay with balance
              - generic [ref=e202]:
                - generic [ref=e204]: Change status
                - listitem [ref=e206]:
                  - generic [ref=e208]:
                    - generic [ref=e209]: 󰗡
                    - generic [ref=e210]: Mark as Paid
                - listitem [ref=e213]:
                  - generic [ref=e215]:
                    - generic [ref=e216]: 󱈎
                    - generic [ref=e217]: Mark as Voided
        - generic [ref=e219]:
          - generic [ref=e221]:
            - heading "General" [level=3] [ref=e225]
            - table [ref=e228]:
              - rowgroup [ref=e229]:
                - row [ref=e230]:
                  - rowheader "Location" [ref=e231]
                  - cell "Vienna South" [ref=e232]
                - row [ref=e235]:
                  - rowheader "Issue date" [ref=e236]
                  - cell "5 Oct 2026" [ref=e237]
                - row [ref=e240]:
                  - rowheader "Due date" [ref=e241]
                  - cell "7 Oct 2026" [ref=e242]
                - row [ref=e245]:
                  - rowheader "Total" [ref=e246]
                  - cell "€1,105.20" [ref=e247]
                - row [ref=e250]:
                  - rowheader "Amount due" [ref=e251]
                  - cell "€1,105.20" [ref=e252]
                - row [ref=e255]:
                  - rowheader "Period" [ref=e256]
                  - cell "-" [ref=e257]
                - row [ref=e260]:
                  - rowheader "Payment option" [ref=e261]
                  - cell "Manual" [ref=e262]
                - row [ref=e265]:
                  - rowheader "Payment link" [ref=e266]
                  - cell "https://invoice.stripe.com/i/acct_1MeJfDB0vsavZFES/test_YWNjdF8xTWVKZkRCMHZzYXZaRkVTLF9WTmxDRFNOTjE5Y1JaYmFWU2h1d1JEcTFpTzQ4YXZHLDE4MTcwMDU5MQ0200jVYQvqDK?s=ap" [ref=e267]:
                    - generic [ref=e268]:
                      - generic [ref=e269]: https://invoice.stripe.com/i/acct_1MeJfDB0vsavZFES/test_YWNjdF8xTWVKZkRCMHZzYXZaRkVTLF9WTmxDRFNOTjE5Y1JaYmFWU2h1d1JEcTFpTzQ4YXZHLDE4MTcwMDU5MQ0200jVYQvqDK?s=ap
                      - button [ref=e273] [cursor=pointer]:
                        - generic [ref=e274]: 󰏌
          - generic [ref=e277]:
            - heading "Customer details" [level=3] [ref=e281]
            - table [ref=e284]:
              - rowgroup [ref=e285]:
                - row [ref=e286]:
                  - rowheader "Name" [ref=e287]
                  - cell [ref=e288]:
                    - link "Stevie Kuhlman" [ref=e291] [cursor=pointer]:
                      - /url: /customers/1193284647
                - row [ref=e294]:
                  - rowheader "Customer type" [ref=e295]
                  - cell "Private" [ref=e296]
                - row [ref=e299]:
                  - rowheader "Email" [ref=e300]
                  - cell [ref=e301]:
                    - link "alva.fisher-monahan@gmail.com" [ref=e304] [cursor=pointer]:
                      - /url: mailto:alva.fisher-monahan@gmail.com
                - row [ref=e305]:
                  - rowheader "Phone number" [ref=e306]
                  - cell "+43 58 6724 9391" [ref=e307]
                - row [ref=e310]:
                  - rowheader "Billing address" [ref=e311]
                  - cell "Samara Trafficway 18928 East Colt Austria" [ref=e312]
          - generic [ref=e316]:
            - heading "Payments" [level=3] [ref=e320]
            - generic [ref=e324]:
              - table [ref=e328]:
                - rowgroup [ref=e329]:
                  - row [ref=e330]:
                    - columnheader [ref=e331]:
                      - button "Total" [ref=e332] [cursor=pointer]:
                        - generic [ref=e335]: 󰁝
                    - columnheader [ref=e338]:
                      - button "Status" [ref=e339] [cursor=pointer]:
                        - generic [ref=e342]: 󰁝
                    - columnheader [ref=e345]:
                      - button "Invoice no." [ref=e346] [cursor=pointer]:
                        - generic [ref=e349]: 󰁝
                    - columnheader [ref=e352]:
                      - button "Date" [ref=e353] [cursor=pointer]:
                        - generic [ref=e356]: 󰁝
                    - columnheader [ref=e359]:
                      - button "Payment method" [ref=e360] [cursor=pointer]:
                        - generic [ref=e363]: 󰁝
                  - row [ref=e366]:
                    - columnheader [ref=e367]
                - rowgroup [ref=e368]:
                  - row [ref=e369]:
                    - cell "No data yet" [ref=e370]
              - generic [ref=e374]:
                - generic [ref=e375]:
                  - generic [ref=e376]: "Items per page:"
                  - combobox [ref=e379]:
                    - generic [ref=e381] [cursor=pointer]:
                      - generic [ref=e382]: "10"
                      - combobox "Items per page:": "10"
                    - generic [ref=e384]: 󰍝
                - generic [ref=e386]: 0-0 of 0
                - generic [ref=e387]:
                  - button [disabled]:
                    - generic: 󰘀
                  - button [disabled]:
                    - generic: 󰅁
                  - button [disabled]:
                    - generic: 󰅂
                  - button [disabled]:
                    - generic: 󰘁
          - generic [ref=e390]:
            - heading "Late Fees" [level=3] [ref=e395]
            - generic [ref=e399]:
              - table [ref=e403]:
                - rowgroup [ref=e404]:
                  - row [ref=e405]:
                    - columnheader "Invoice no." [ref=e406]
                    - columnheader "Invoice note" [ref=e410]
                    - columnheader "Created by" [ref=e414]
                    - columnheader "Total" [ref=e418]
                    - columnheader "Status" [ref=e422]
                    - columnheader "Issue date" [ref=e426]
                    - columnheader "Due date" [ref=e430]
                  - row [ref=e434]:
                    - columnheader [ref=e435]
                - rowgroup [ref=e436]:
                  - row [ref=e437]:
                    - cell "No data yet" [ref=e438]
              - generic [ref=e442]:
                - generic [ref=e443]:
                  - generic [ref=e444]: "Items per page:"
                  - combobox [ref=e447]:
                    - generic [ref=e449] [cursor=pointer]:
                      - generic [ref=e450]: "10"
                      - combobox "Items per page:": "10"
                    - generic [ref=e452]: 󰍝
                - generic [ref=e454]: 0-0 of 0
                - generic [ref=e455]:
                  - button [disabled]:
                    - generic: 󰘀
                  - button [disabled]:
                    - generic: 󰅁
                  - button [disabled]:
                    - generic: 󰅂
                  - button [disabled]:
                    - generic: 󰘁
  - generic:
    - tooltip
    - tooltip
    - tooltip
    - tooltip
    - tooltip
    - tooltip
    - tooltip
    - tooltip
    - tooltip
    - tooltip
    - tooltip
    - tooltip
    - tooltip
    - tooltip
    - tooltip
    - tooltip
    - tooltip
    - tooltip
    - tooltip
    - tooltip
    - tooltip
    - tooltip
    - tooltip
    - tooltip
    - tooltip
    - tooltip
    - tooltip
    - tooltip
    - tooltip
    - tooltip
    - tooltip
    - tooltip
    - tooltip
    - tooltip
    - tooltip
    - tooltip
    - tooltip
    - tooltip
```

# Test source

```ts
  1  | import { test } from '@/manager/modules/invoice/invoice-fixtures';
  2  | import { getCustomerDisplayName } from '@/manager/modules/customer/customer-utils';
  3  | import { toInvoiceCreateTotalsSummary } from '@/manager/modules/invoice/invoice-mappers';
  4  | import { formatCurrency } from '@/shared/utils/formatters';
  5  | import { expect } from '@/shared/utils/matchers';
  6  | import { readPdfText, toPdfText } from '@/shared/utils/pdf-utils';
  7  | import { pollOrSkip } from '@/shared/utils/poll-utils';
  8  | 
  9  | test.describe.configure({ mode: 'default', timeout: 120_000 });
  10 | 
  11 | test('downloads the invoice pdf from the list', async ({
  12 |   page,
  13 |   setupInvoiceCreateData,
  14 |   createInvoice,
  15 |   invoiceListPage,
  16 | }) => {
  17 |   const data = await setupInvoiceCreateData({ numberOfProducts: 1 });
  18 |   const customerName = getCustomerDisplayName(data.customer);
  19 |   // The storeroom Stripe account renders its documents in German, so the PDF total is German-formatted.
  20 |   const amount = formatCurrency(toInvoiceCreateTotalsSummary(data).totalInclVat, data.location.currency, 'de-DE');
  21 | 
  22 |   const invoice = await createInvoice(data);
  23 | 
  24 |   await invoiceListPage.goto();
  25 | 
  26 |   await test.step('apply filter', () => invoiceListPage.searchTextField.fill(invoice.number));
  27 | 
  28 |   // Unlike the credit-note list there is no pdf-readiness indicator to gate on (the download action is always
  29 |   // in the row menu), so the poll waits for the invoice row itself. The applied filter persists across reloads
  30 |   // (grid filters live in localStorage), so the row under test stays the only one.
  31 |   await test.step('wait for the invoice to appear in the list', () =>
  32 |     pollOrSkip(
  33 |       async () => {
  34 |         await invoiceListPage.reload();
  35 |         await expect(invoiceListPage.dataTable.getRows()).toHaveCount(1);
  36 |       },
  37 |       { timeout: 60_000, reason: 'invoice did not appear in the list within 60s — test-env queue backlog (KIN-4692)' }
  38 |     ));
  39 | 
  40 |   const download = await test.step('download invoice pdf', async () => {
  41 |     // The action fetches a signed Kinnovis storage link and opens it in a new tab that immediately turns into a
  42 |     // file download and closes itself — Chromium attributes that download to the opener page, so listen there.
  43 |     const [invoicePdfDownload] = await Promise.all([
  44 |       page.waitForEvent('download'),
  45 |       invoiceListPage.clickDownloadInvoicePdfAction(0),
  46 |     ]);
  47 | 
  48 |     return invoicePdfDownload;
  49 |   });
  50 | 
  51 |   await test.step('verify invoice pdf contents', async () => {
  52 |     const pdfText = await readPdfText(await download.path());
  53 | 
  54 |     expect(pdfText).toContain(toPdfText(invoice.number));
  55 |     expect(pdfText).toContain(toPdfText(customerName));
  56 |     expect(pdfText).toContain(toPdfText(amount));
  57 |   });
  58 | });
  59 | 
  60 | test('downloads the invoice pdf from the details page', async ({
  61 |   page,
  62 |   setupInvoiceCreateData,
  63 |   createInvoice,
  64 |   invoiceDetailsPage,
  65 | }) => {
  66 |   const data = await setupInvoiceCreateData({ numberOfProducts: 1 });
  67 |   const customerName = getCustomerDisplayName(data.customer);
  68 |   // The storeroom Stripe account renders its documents in German, so the PDF total is German-formatted.
  69 |   const amount = formatCurrency(toInvoiceCreateTotalsSummary(data).totalInclVat, data.location.currency, 'de-DE');
  70 | 
  71 |   const invoice = await createInvoice(data);
  72 | 
  73 |   await invoiceDetailsPage.goto(invoice.id);
  74 | 
  75 |   const download = await test.step('download invoice pdf', async () => {
  76 |     // The action fetches a signed Kinnovis storage link and opens it in a new tab that immediately turns into a
  77 |     // file download and closes itself — Chromium attributes that download to the opener page, so listen there.
  78 |     const [invoicePdfDownload] = await Promise.all([
> 79 |       page.waitForEvent('download'),
     |            ^ Error: page.waitForEvent: Test timeout of 120000ms exceeded.
  80 |       invoiceDetailsPage.clickDownloadInvoicePdfAction(),
  81 |     ]);
  82 | 
  83 |     return invoicePdfDownload;
  84 |   });
  85 | 
  86 |   await test.step('verify invoice pdf contents', async () => {
  87 |     const pdfText = await readPdfText(await download.path());
  88 | 
  89 |     expect(pdfText).toContain(toPdfText(invoice.number));
  90 |     expect(pdfText).toContain(toPdfText(customerName));
  91 |     expect(pdfText).toContain(toPdfText(amount));
  92 |   });
  93 | });
  94 | 
```