Skip to content

Commit

Permalink
fix(session-zip.e2e): wait for new rectangle and fix waitForFileExists
Browse files Browse the repository at this point in the history
- Wait for new rectangle element to be mounted.
- Wait for session.zip to be fully written
  • Loading branch information
PaulHax committed Oct 26, 2023
1 parent e64df9c commit 8d0c3f4
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 16 deletions.
2 changes: 1 addition & 1 deletion src/components/tools/rectangle/RectangleTool.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<template>
<div class="overlay-no-events">
<svg class="overlay-no-events">
<svg class="overlay-no-events" data-testid="rectangle-tool-container">
<rectangle-widget-2D
v-for="tool in tools"
:key="tool.id"
Expand Down
9 changes: 8 additions & 1 deletion tests/pageobjects/volview.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,10 @@ class VolViewPage extends Page {
);
return inView.every(Boolean);
},
{ timeout }
{
timeout,
timeoutMsg: `expected at least 1 view to be displayed in viewport`,
}
);
}

Expand All @@ -81,6 +84,10 @@ class VolViewPage extends Page {
await view.click({ x: 5, y: 5 });
}

get rectangleToolContainers() {
return $$('*[data-testid="rectangle-tool-container"]');
}

get saveButton() {
return $('button span i[class~=mdi-content-save-all]');
}
Expand Down
47 changes: 33 additions & 14 deletions tests/specs/session-zip.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,7 @@ const SESSION_SAVE_TIMEOUT = 40000;
// from https://stackoverflow.com/a/47764403
function waitForFileExists(filePath: string, timeout: number) {
return new Promise<void>((resolve, reject) => {
const dir = path.dirname(filePath);
const basename = path.basename(filePath);
let timerId = undefined as NodeJS.Timeout | undefined;
const watcher = fs.watch(dir, (eventType: any, filename: string | null) => {
if (eventType === 'rename' && filename === basename) {
clearTimeout(timerId);
watcher.close();
resolve();
}
});
let watcher: fs.FSWatcher;

const onTimeout = () => {
watcher.close();
Expand All @@ -28,7 +19,17 @@ function waitForFileExists(filePath: string, timeout: number) {
);
};

timerId = setTimeout(onTimeout, timeout);
const timerId = setTimeout(onTimeout, timeout);

const dir = path.dirname(filePath);
const basename = path.basename(filePath);
watcher = fs.watch(dir, (eventType: any, filename: string | null) => {
if (eventType === 'rename' && filename === basename) {
clearTimeout(timerId);
watcher.close();
resolve();
}
});

fs.access(filePath, fs.constants.R_OK, (err) => {
if (!err) {
Expand All @@ -44,6 +45,7 @@ const saveSession = async () => {
const sessionFileName = await volViewPage.saveSession();
const downloadedPath = path.join(TEMP_DIR, sessionFileName);
await waitForFileExists(downloadedPath, SESSION_SAVE_TIMEOUT);
await browser.pause(1000); // wait for writing to finish?
return sessionFileName;
};

Expand All @@ -60,17 +62,34 @@ const saveGetManifest = async () => {
return { session, manifest };
};

const getRectangleCount = async () => {
const oneRectangleContainer = (await volViewPage.rectangleToolContainers)[0];
const rectangles = await oneRectangleContainer.$$('g');
return rectangles.length;
};

const waitForRectangleCount = async (count: number) => {
// wait for rectangle to be drawn
await browser.waitUntil(
async function newRectangleExist() {
const updatedCount = await getRectangleCount();
return updatedCount >= count;
},
{ timeoutMsg: `expected ${count} rectangles to be drawn` }
);
};

const annotate = async () => {
await volViewPage.open();
await volViewPage.downloadProstateSample();
await volViewPage.waitForViews();

// draw rectangle
await volViewPage.activateRectangle();
await volViewPage.clickTwiceInTwoView();
await waitForRectangleCount(1); // wait for placing tool

// this may ensure imminently saved session.volview.zip has the tool in CI
await browser.pause(500);
await volViewPage.clickTwiceInTwoView();
await waitForRectangleCount(2); // wait for drawn tool
};

describe('VolView config and deserialization', () => {
Expand Down

0 comments on commit 8d0c3f4

Please sign in to comment.