From ca431d7a31f5148303acccf7e60f4d3db12475e1 Mon Sep 17 00:00:00 2001 From: Cornelius Roemer Date: Thu, 9 May 2024 01:11:24 +0200 Subject: [PATCH] test(e2e): no need to create file, can setInput from buffer --- website/package.json | 1 + website/tests/pages/revise/revise.page.ts | 35 +++++++++-------------- 2 files changed, 14 insertions(+), 22 deletions(-) diff --git a/website/package.json b/website/package.json index dbfaa617e..636c124a2 100644 --- a/website/package.json +++ b/website/package.json @@ -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": { diff --git a/website/tests/pages/revise/revise.page.ts b/website/tests/pages/revise/revise.page.ts index 5d2f50ee1..238dbd0e0 100644 --- a/website/tests/pages/revise/revise.page.ts +++ b/website/tests/pages/revise/revise.page.ts @@ -1,7 +1,4 @@ -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'; @@ -9,32 +6,26 @@ 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), + }); } }