Skip to content

Commit

Permalink
Reinstate e2e download test but disabled for webkit (#2465)
Browse files Browse the repository at this point in the history
* Revert "Revert "feat(e2e): create e2e test for bulk download (#2445)" (#2463)"

This reverts commit be208eb.

* skip download tests on webkit
  • Loading branch information
theosanderson authored Aug 20, 2024
1 parent a3e1b5f commit 42efc5f
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export const DownloadButton: FC<DownloadButtonProps> = ({
className={`btn loculusColor ${disabled ? 'btn-disabled' : ''} text-white`}
href={downloadUrl}
onClick={handleClick}
data-testid='start-download'
>
Download
</a>
Expand Down
52 changes: 52 additions & 0 deletions website/tests/pages/search/index.spec.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
import { type Page, type Download } from '@playwright/test';
import { DateTime } from 'luxon';

import { routes } from '../../../src/routes/routes.ts';
import { getAccessionVersionString } from '../../../src/utils/extractAccessionVersion.ts';
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();
Expand Down Expand Up @@ -97,4 +102,51 @@ test.describe('The search page', () => {

await expect(searchPage.getAccessionField()).toHaveValue('');
});

async function performDownload(page: Page, options: PerformDownloadOptions = {}): Promise<string> {
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<Download> = 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, browserName }) => {
test.skip(browserName === 'webkit', 'Download tests are skipped on WebKit');
await searchPage.goto();

const filePath = await performDownload(page);

expect(filePath).toBeTruthy();
});

test('should download raw nucleotide sequences when selected', async ({ searchPage, page, browserName }) => {
test.skip(browserName === 'webkit', 'Download tests are skipped on WebKit');
await searchPage.goto();

const filePath = await performDownload(page, { selectRawNucleotide: true });

expect(filePath).toBeTruthy();
});
});

0 comments on commit 42efc5f

Please sign in to comment.