diff --git a/website/src/components/SearchPage/DownloadDialog/DownloadButton.tsx b/website/src/components/SearchPage/DownloadDialog/DownloadButton.tsx index 072d0bbc0..7807b796b 100644 --- a/website/src/components/SearchPage/DownloadDialog/DownloadButton.tsx +++ b/website/src/components/SearchPage/DownloadDialog/DownloadButton.tsx @@ -58,6 +58,7 @@ export const DownloadButton: FC = ({ className={`btn loculusColor ${disabled ? 'btn-disabled' : ''} text-white`} href={downloadUrl} onClick={handleClick} + data-testid='start-download' > Download diff --git a/website/tests/pages/search/index.spec.ts b/website/tests/pages/search/index.spec.ts index 751ae6be5..28fcfe7c6 100644 --- a/website/tests/pages/search/index.spec.ts +++ b/website/tests/pages/search/index.spec.ts @@ -1,3 +1,4 @@ +import { type Page, type Download } from '@playwright/test'; import { DateTime } from 'luxon'; import { routes } from '../../../src/routes/routes.ts'; @@ -5,6 +6,10 @@ import { getAccessionVersionString } from '../../../src/utils/extractAccessionVe import { baseUrl, dummyOrganism, expect, test } from '../../e2e.fixture'; import { getTestSequences } from '../../util/testSequenceProvider.ts'; +interface PerformDownloadOptions { + selectRawNucleotide?: boolean; +} + test.describe('The search page', () => { test('should find no data in the future', async ({ searchPage }) => { const tomorrow = DateTime.now().plus({ days: 1 }).toISODate(); @@ -97,4 +102,49 @@ test.describe('The search page', () => { await expect(searchPage.getAccessionField()).toHaveValue(''); }); + + async function performDownload(page: Page, options: PerformDownloadOptions = {}): Promise { + const { selectRawNucleotide = false } = options; + + const downloadButton = page.getByRole('button', { name: 'Download' }); + await downloadButton.click(); + + if (selectRawNucleotide === true) { + const rawNucleotideRadio = page.getByLabel('Raw nucleotide sequences'); + await rawNucleotideRadio.check(); + } + + const agreeCheckbox = page.getByLabel(/I agree/); + await agreeCheckbox.check(); + + const downloadButton2 = page.getByTestId('start-download'); + + const downloadPromise: Promise = page.waitForEvent('download'); + + await downloadButton2.click(); + + const download: Download = await downloadPromise; + + const suggestedFileName: string = download.suggestedFilename(); + const filePath: string = '/tmp/' + String(Math.random()).slice(0, 5) + suggestedFileName; + await download.saveAs(filePath); + + return filePath; + } + + test('should download file when agreeing to terms', async ({ searchPage, page }) => { + await searchPage.goto(); + + const filePath = await performDownload(page); + + expect(filePath).toBeTruthy(); + }); + + test('should download raw nucleotide sequences when selected', async ({ searchPage, page }) => { + await searchPage.goto(); + + const filePath = await performDownload(page, { selectRawNucleotide: true }); + + expect(filePath).toBeTruthy(); + }); });