Skip to content

Commit

Permalink
Cleaning up tests and debugging
Browse files Browse the repository at this point in the history
  • Loading branch information
gr812b committed Nov 12, 2024
1 parent b9138b7 commit 64da8ce
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 24 deletions.
3 changes: 0 additions & 3 deletions e2e/testers/graph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ export class GraphTester extends Tester {
}

async testCreateGraph() {
await this.page.waitForTimeout(10000);
await this.openGraphForm();
await this.pressNextButton();
await this.selectFile('182848/BATT PERC');
Expand Down Expand Up @@ -41,6 +40,4 @@ export class GraphTester extends Tester {
async verifyGraphCreated() {
await expect(this.page.getByText('Graph Created')).toBeVisible();
}


}
56 changes: 35 additions & 21 deletions e2e/testers/upload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export class UploadTester extends Tester {
await this.uploadFile(this.binFilePath);
await this.submitFile();
await this.verifyFilesUploaded();
await this.awaitFileParsed('182848/BATT PERC');
}

async testUploadNoFile() {
Expand All @@ -32,12 +33,35 @@ export class UploadTester extends Tester {
await this.verifyNoFileSelectedAlert();
}

async awaitFileParsed(filePath: string) {
let fileUploaded = false;

while (!fileUploaded) {
await this.openDownloadForm();
await this.page.waitForTimeout(1000);

if (await this.isFileVisible(filePath)) {
fileUploaded = true;
}

await this.closeDownloadForm()
}
}

// Basic functions

async openUploadForm() {
await this.page.getByRole('button', { name: 'Upload' }).click();
}

async openDownloadForm() {
await this.page.getByRole('button', { name: 'Download' }).click();
}

async closeDownloadForm() {
await this.page.getByRole('button', { name: 'X' }).click();
}

async uploadFile(filePath: string) {
await this.page.locator('#label-file-upload').click();
await this.page.setInputFiles('#label-file-upload', filePath);
Expand All @@ -58,28 +82,18 @@ export class UploadTester extends Tester {
});
}

// TODO: Implement this better
async checkFileParsed(filePath: string) {
await this.page.getByRole('button', { name: 'Download' }).click();

let fileUploaded = false;
while (!fileUploaded) {
try {
// Attempt to locate the file cell and check visibility
const fileCell = this.page.getByRole('row', { name: 'endurance 307 MB -' }).getByRole('cell').first();
if (await fileCell.isVisible()) {
fileUploaded = true; // Exit the loop if the file is visible
} else {
throw new Error('File not yet visible'); // Continue to the catch block if not visible
}
} catch (error) {
// Close the modal and wait before re-trying
await this.page.getByRole('button', { name: 'X' }).click();
await this.page.waitForTimeout(1000); // Wait for a short delay before retrying
await this.page.getByRole('button', { name: 'Download' }).click(); // Re-open the modal
async isFileVisible(filePath: string) {
const splitPath = filePath.split('/');
for (const path of splitPath) {
if (!await this.page.getByRole('cell', { name: path }).isVisible()) {
return false;
} else if (path === splitPath[splitPath.length - 1]) {
// If last path, return true
return true;
} else {
// Expand folder
await this.page.getByRole('cell', { name: path }).click();
}
}

await this.page.getByRole('button', { name: 'X' }).click();
}
}
2 changes: 2 additions & 0 deletions front-end/src/lib/apiUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,8 @@ export const ApiUtil = {
console.log(response);
// eslint-disable-next-line no-console
console.log(response.statusText);
// eslint-disable-next-line no-console
console.log('hostname: ' + window.location.hostname);

if (!response.ok) throw Error(response.statusText);
},
Expand Down

0 comments on commit 64da8ce

Please sign in to comment.