-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(e2e): refactor revise tests, SSR disable file upload (#1833)
- Refactor revise test to not require an explicit file but set file from buffer. (Async file setting was also incorrectly not awaited for) - Disable buttons when React stuff is server side rendered. Playwright would otherwise click buttons in HTML without the react event handlers attached which made tests flaky: in particular locally where things are faster than in CI - Uses data-testid for elements/buttons that are hard to get from Playwright otherwise - Get rid of unnecessarily tight timeout (1s) in seqset test (default is 5s) - Add npm run script e2e:ui that opens playwright GUI mode with headed playwright: this makes it particularly easy to debug tests and see why they fail (extensively used in the preparation of this)
- Loading branch information
1 parent
9106d31
commit c29b912
Showing
4 changed files
with
50 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,34 @@ | ||
import { unlinkSync, writeFileSync } from 'fs'; | ||
|
||
import type { Locator, Page } from '@playwright/test'; | ||
import { v4 as uuid } from 'uuid'; | ||
import { expect, type Page } from '@playwright/test'; | ||
|
||
import { routes } from '../../../src/routes/routes.ts'; | ||
import type { Accession } from '../../../src/types/backend.ts'; | ||
import { baseUrl, dummyOrganism, sequencesTestFile } from '../../e2e.fixture'; | ||
import { createModifiedFileContent } from '../../util/createFileContent.ts'; | ||
|
||
export class RevisePage { | ||
public readonly submitButton: Locator; | ||
private readonly temporaryMetadataFile: string = `./tests/testData/${uuid()}_metadata.tsv`; | ||
|
||
constructor(public readonly page: Page) { | ||
this.submitButton = page.getByRole('button', { name: 'Submit' }); | ||
} | ||
constructor(public readonly page: Page) {} | ||
|
||
public async goto(groupId: number) { | ||
await this.page.goto(`${baseUrl}${routes.revisePage(dummyOrganism.key, groupId)}`); | ||
} | ||
|
||
public async uploadSequenceData(file: string = sequencesTestFile) { | ||
await this.page.getByLabel('Sequence file').setInputFiles(file); | ||
public async submitRevisedData(accessions: Accession[]) { | ||
await this.setSequenceFile(); | ||
await this.setRevisedMetadataFile(accessions); | ||
await this.page.getByRole('button', { name: 'Submit' }).click(); | ||
} | ||
|
||
public async submitRevisedData(accessions: Accession[]) { | ||
try { | ||
await Promise.all([this.uploadSequenceData(), this.uploadRevisedMetadata(accessions)]); | ||
await this.submitButton.click(); | ||
} finally { | ||
unlinkSync(this.temporaryMetadataFile); | ||
} | ||
private async setSequenceFile(file: string = sequencesTestFile) { | ||
await this.page.getByTestId('sequence_file').setInputFiles(file); | ||
await expect(this.page.getByTestId('discard_sequence_file')).toBeEnabled(); | ||
} | ||
|
||
private async uploadRevisedMetadata(accessions: Accession[]) { | ||
writeFileSync(this.temporaryMetadataFile, createModifiedFileContent(accessions).metadataContent); | ||
await this.page.getByLabel('Metadata file').setInputFiles(this.temporaryMetadataFile); | ||
private async setRevisedMetadataFile(accessions: Accession[]) { | ||
await this.page.getByTestId('metadata_file').setInputFiles({ | ||
name: 'metadata.tsv', | ||
mimeType: 'text/plain', | ||
buffer: Buffer.from(createModifiedFileContent(accessions).metadataContent), | ||
}); | ||
await expect(this.page.getByTestId('discard_metadata_file')).toBeEnabled(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters