-
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): no need to create file, can setInput from buffer
- Loading branch information
1 parent
9106d31
commit ca431d7
Showing
2 changed files
with
14 additions
and
22 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,31 @@ | ||
import { unlinkSync, writeFileSync } from 'fs'; | ||
|
||
import type { Locator, Page } from '@playwright/test'; | ||
import { v4 as uuid } from 'uuid'; | ||
import 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 Promise.all([this.setSequenceFile(), 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.getByLabel('Sequence file').setInputFiles(file); | ||
} | ||
|
||
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.getByLabel('Metadata file').setInputFiles({ | ||
name: 'metadata.tsv', | ||
mimeType: 'text/plain', | ||
buffer: Buffer.from(createModifiedFileContent(accessions).metadataContent), | ||
}); | ||
} | ||
} |