From b4fcd6ac01800a406de2fa15e88bdb138ff964cd Mon Sep 17 00:00:00 2001 From: Arnaud Date: Tue, 22 Oct 2024 10:35:15 +0200 Subject: [PATCH] Add test case for downloading a file --- e2e/download.spec.ts | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 e2e/download.spec.ts diff --git a/e2e/download.spec.ts b/e2e/download.spec.ts new file mode 100644 index 0000000..ef17753 --- /dev/null +++ b/e2e/download.spec.ts @@ -0,0 +1,28 @@ +import { test, expect } from '@playwright/test'; +import { readFileSync } from 'fs'; +import path, { dirname } from 'path'; +import { fileURLToPath } from 'url'; + +const __filename = fileURLToPath(import.meta.url); +const __dirname = dirname(__filename); + +test('download a file', async ({ page }) => { + await page.goto('/dashboard'); + await page.locator('div').getByTestId("upload").setInputFiles([ + path.join(__dirname, "assets", 'chatgpt.jpg'), + ]); + await page.context().grantPermissions(["clipboard-read", "clipboard-write"]); + await page.locator('.files-fileActions > button:nth-child(3)').first().click(); + await page.getByRole('button', { name: 'Copy CID' }).click(); + const handle = await page.evaluateHandle(() => navigator.clipboard.readText()); + const cid = await handle.jsonValue() + await page.locator('.sheets-container > .backdrop').click(); + await page.getByPlaceholder('CID').click(); + await page.getByPlaceholder('CID').fill(cid); + const page1Promise = page.waitForEvent('popup'); + const downloadPromise = page.waitForEvent('download'); + await page.locator('div').filter({ hasText: /^Download a fileDownload$/ }).getByRole('button').click(); + const page1 = await page1Promise; + const download = await downloadPromise; + expect(await download.failure()).toBeNull() +}); \ No newline at end of file