Skip to content

Commit 245a6b3

Browse files
committed
feat(website): add file uploads to revisions
1 parent efb7303 commit 245a6b3

11 files changed

Lines changed: 318 additions & 105 deletions

File tree

integration-tests/tests/pages/edit.page.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
import { expect, Page } from '@playwright/test';
22
import { ReviewPage } from './review.page';
3+
import { prepareTmpDirForSingleUpload, uploadFilesFromTmpDir } from '../utils/file-upload-helpers';
34

45
export class EditPage {
56
constructor(private page: Page) {}
67

8+
async goto(organism: string, accession: string, version: number) {
9+
await this.page.goto(`/${organism}/submission/edit/${accession}/${version}`);
10+
}
11+
712
async discardSequenceFile() {
813
await this.page.getByRole('button', { name: 'Discard file' }).click();
914
}
@@ -31,4 +36,14 @@ export class EditPage {
3136
await this.page.waitForURL('**/review', { timeout: 15_000 });
3237
return new ReviewPage(this.page);
3338
}
39+
40+
async uploadExternalFiles(
41+
fileId: string,
42+
fileContents: Record<string, string>,
43+
tmpDir: string,
44+
) {
45+
await prepareTmpDirForSingleUpload(fileContents, tmpDir);
46+
const fileCount = Object.keys(fileContents).length;
47+
await uploadFilesFromTmpDir(this.page, fileId, tmpDir, fileCount);
48+
}
3449
}

integration-tests/tests/pages/revision.page.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { expect, type Page } from '@playwright/test';
2+
import { prepareTmpDirForBulkUpload, uploadFilesFromTmpDir } from '../utils/file-upload-helpers';
23

34
/**
45
* Page object for the sequence revision page.
@@ -121,7 +122,6 @@ export class RevisionPage {
121122
async submitRevision() {
122123
await this.acceptTerms();
123124
await this.clickSubmit();
124-
await this.clickConfirm();
125125
}
126126

127127
/**
@@ -187,4 +187,17 @@ export class RevisionPage {
187187

188188
await this.submitRevision();
189189
}
190+
191+
async uploadExternalFiles(
192+
fileId: string,
193+
fileContents: Record<string, Record<string, string>>,
194+
tmpDir: string,
195+
) {
196+
await prepareTmpDirForBulkUpload(fileContents, tmpDir);
197+
const fileCount = Object.values(fileContents).reduce(
198+
(total, files) => total + Object.keys(files).length,
199+
0,
200+
);
201+
await uploadFilesFromTmpDir(this.page, fileId, tmpDir, fileCount);
202+
}
190203
}

integration-tests/tests/pages/submission.page.ts

Lines changed: 9 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import { Page } from '@playwright/test';
22
import { ReviewPage } from './review.page';
3-
import fs from 'fs';
4-
import path from 'path';
53
import Papa from 'papaparse';
64
import { NavigationPage } from './navigation.page';
7-
import { clearTmpDir } from '../utils/tmpdir';
5+
import {
6+
prepareTmpDirForBulkUpload,
7+
prepareTmpDirForSingleUpload,
8+
uploadFilesFromTmpDir,
9+
} from '../utils/file-upload-helpers';
810

911
class SubmissionPage {
1012
protected page: Page;
@@ -68,17 +70,6 @@ class SubmissionPage {
6870
await reviewPage.waitForZeroProcessing();
6971
return reviewPage;
7072
}
71-
72-
protected async _uploadFilesFromTmpDir(testId: string, tmpDir: string, fileCount: number) {
73-
await this.page.getByRole('heading', { name: 'Extra files' }).scrollIntoViewIfNeeded();
74-
// Trigger file upload (don't await) and wait for checkmarks to appear (indicates success)
75-
void this.page.getByTestId(testId).setInputFiles(tmpDir);
76-
return Promise.all(
77-
Array.from({ length: fileCount }, (_, i) =>
78-
this.page.getByText('✓').nth(i).waitFor({ state: 'visible' }),
79-
),
80-
);
81-
}
8273
}
8374

8475
export class SingleSequenceSubmissionPage extends SubmissionPage {
@@ -140,19 +131,9 @@ export class SingleSequenceSubmissionPage extends SubmissionPage {
140131
fileContents: Record<string, string>,
141132
tmpDir: string,
142133
) {
143-
await this._prepareTmpDirWithFiles(fileContents, tmpDir);
134+
await prepareTmpDirForSingleUpload(fileContents, tmpDir);
144135
const fileCount = Object.keys(fileContents).length;
145-
await this._uploadFilesFromTmpDir(fileId, tmpDir, fileCount);
146-
}
147-
148-
private async _prepareTmpDirWithFiles(fileContents: Record<string, string>, tmpDir: string) {
149-
await clearTmpDir(tmpDir);
150-
151-
await Promise.all(
152-
Object.entries(fileContents).map(([fileName, fileContent]) =>
153-
fs.promises.writeFile(path.join(tmpDir, fileName), fileContent),
154-
),
155-
);
136+
await uploadFilesFromTmpDir(this.page, fileId, tmpDir, fileCount);
156137
}
157138

158139
async completeSubmission(
@@ -229,43 +210,16 @@ export class BulkSubmissionPage extends SubmissionPage {
229210
});
230211
}
231212

232-
/**
233-
* The given file contents will be stored in a temp dir and then submitted
234-
* for the given file ID.
235-
* @param fileId For which file ID to upload the files.
236-
* @param fileContents A struct: submissionID -> filename -> filecontent.
237-
* @param tmpDir The temporary directory to use for storing files.
238-
*/
239213
async uploadExternalFiles(
240214
fileId: string,
241215
fileContents: Record<string, Record<string, string>>,
242216
tmpDir: string,
243217
) {
244-
await this._prepareTmpDirWithFiles(fileContents, tmpDir);
218+
await prepareTmpDirForBulkUpload(fileContents, tmpDir);
245219
const fileCount = Object.values(fileContents).reduce(
246220
(total, files) => total + Object.keys(files).length,
247221
0,
248222
);
249-
await this._uploadFilesFromTmpDir(fileId, tmpDir, fileCount);
250-
}
251-
252-
private async _prepareTmpDirWithFiles(
253-
fileContents: Record<string, Record<string, string>>,
254-
tmpDir: string,
255-
) {
256-
await clearTmpDir(tmpDir);
257-
258-
// Create submission directories and write files
259-
const submissionIds = Object.keys(fileContents);
260-
await Promise.all(
261-
submissionIds.map((submissionId) => fs.promises.mkdir(path.join(tmpDir, submissionId))),
262-
);
263-
await Promise.all(
264-
Object.entries(fileContents).flatMap(([submissionId, files]) => {
265-
return Object.entries(files).map(([fileName, fileContent]) =>
266-
fs.promises.writeFile(path.join(tmpDir, submissionId, fileName), fileContent),
267-
);
268-
}),
269-
);
223+
await uploadFilesFromTmpDir(this.page, fileId, tmpDir, fileCount);
270224
}
271225
}

0 commit comments

Comments
 (0)