Skip to content

Commit

Permalink
test(e2e): no need to create file, can setInput from buffer
Browse files Browse the repository at this point in the history
  • Loading branch information
corneliusroemer committed May 8, 2024
1 parent 9106d31 commit ca431d7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 22 deletions.
1 change: 1 addition & 0 deletions website/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"format-fast": "prettier --ignore-path \"../.gitignore\" --write \"./**/*.{ts,tsx,json,astro,cjs,mjs}\"",
"test": "vitest",
"e2e": "npx playwright test",
"e2e:ui": "npx playwright test --ui --headed",
"e2e:headed": "npx playwright test --headed"
},
"dependencies": {
Expand Down
35 changes: 13 additions & 22 deletions website/tests/pages/revise/revise.page.ts
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),
});
}
}

0 comments on commit ca431d7

Please sign in to comment.