Skip to content

Commit

Permalink
Revert "Revert "feat(e2e): create e2e test for bulk download (#2445)" (
Browse files Browse the repository at this point in the history
…#2463)"

This reverts commit be208eb.
  • Loading branch information
theosanderson authored Aug 20, 2024
1 parent be208eb commit e61dfaf
Show file tree
Hide file tree
Showing 2 changed files with 51 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
50 changes: 50 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,49 @@ 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 }) => {
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();
});
});

0 comments on commit e61dfaf

Please sign in to comment.