Skip to content

Commit

Permalink
e2e replace invalid file with text buffer
Browse files Browse the repository at this point in the history
  • Loading branch information
jer3k committed Nov 28, 2024
1 parent ae2589b commit 1cd06d0
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
1 change: 0 additions & 1 deletion admin-frontend/e2e/assets/announcements/invalid.com

This file was deleted.

29 changes: 21 additions & 8 deletions admin-frontend/e2e/pages/announcements/form-page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import path from 'path';
import { expect, Locator } from 'playwright/test';
import { AnnouncementStatus } from '../../types';
import { AdminPortalPage } from '../admin-portal-page';
declare const Buffer;

export enum FormMode {
ADD,
Expand All @@ -24,6 +25,7 @@ export class FormPage extends AdminPortalPage {
linkTextInput: Locator;
chooseFileButton: Locator;
fileDisplayNameInput: Locator;
fileInput: Locator;

async setup() {
await super.setup();
Expand All @@ -45,6 +47,7 @@ export class FormPage extends AdminPortalPage {
this.fileDisplayNameInput = await this.page.getByLabel(
'Display File Link As',
);
this.fileInput = await this.page.getByLabel('Attachment', { exact: true });

await expect(this.titleInput).toBeVisible();
await expect(this.descriptionInput).toBeVisible();
Expand Down Expand Up @@ -153,16 +156,26 @@ export class FormPage extends AdminPortalPage {
async chooseFile(valid: boolean = true) {
await this.fillFileDisplayName(faker.lorem.words(1));
await expect(this.chooseFileButton).toBeVisible();
const scanResponse = this.waitForClamavScan();

const fileChooserPromise = this.page.waitForEvent('filechooser');
if (valid) {
const fileChooserPromise = this.page.waitForEvent('filechooser');

await this.chooseFileButton.click();
const fileChooser = await fileChooserPromise;
await fileChooser.setFiles(
path.resolve('e2e', 'assets', 'announcements', 'valid.pdf'),
);
} else {
await this.fileInput.setInputFiles({
name: 'invalid.pdf',
mimeType: 'application/pdf',
buffer: Buffer.from(
String.raw`X5O!P%@AP[4\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*`,
),
});
}

const scanResponse = this.waitForClamavScan();
await this.chooseFileButton.click();
const fileChooser = await fileChooserPromise;
const fileName = valid ? 'valid.pdf' : 'invalid.com';
await fileChooser.setFiles(
path.resolve('e2e', 'assets', 'announcements', fileName),
);
const response = await scanResponse;
await response.json();
}
Expand Down

0 comments on commit 1cd06d0

Please sign in to comment.