Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulHax committed Oct 27, 2023
1 parent 8d0c3f4 commit f5cc095
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 23 deletions.
6 changes: 5 additions & 1 deletion src/components/VtkTwoView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@
@input="setSlice"
/>
</div>
<div class="vtk-container" :class="active ? 'active' : ''">
<div
class="vtk-container"
:class="active ? 'active' : ''"
data-testid="two-view-container"
>
<div class="vtk-sub-container">
<div
class="vtk-view"
Expand Down
11 changes: 2 additions & 9 deletions tests/pageobjects/volview.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,8 @@ class VolViewPage extends Page {
return $$('div[data-testid~="vtk-two-view"] > canvas');
}

async clickTwiceInTwoView() {
const views = await this.twoViews;
const view = views[0];
await view.click({ x: 1, y: 1 });
await view.click({ x: 5, y: 5 });
}

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

get saveButton() {
Expand Down
47 changes: 34 additions & 13 deletions tests/specs/session-zip.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { setValueVueInput, volViewPage } from '../pageobjects/volview.page';
import { TEMP_DIR } from '../../wdio.shared.conf';

const SESSION_SAVE_TIMEOUT = 40000;
const SLOW_INTERACTION_TIMEOUT = 10000;

// from https://stackoverflow.com/a/47764403
function waitForFileExists(filePath: string, timeout: number) {
Expand All @@ -15,22 +16,27 @@ function waitForFileExists(filePath: string, timeout: number) {
const onTimeout = () => {
watcher.close();
reject(
new Error('File did not exists and was not created during the timeout.')
new Error(
`File ${filePath} did not exists and was not created during the timeout of ${timeout} ms}`
)
);
};

const timerId = setTimeout(onTimeout, timeout);

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

// check if file already exists
fs.access(filePath, fs.constants.R_OK, (err) => {
if (!err) {
clearTimeout(timerId);
Expand All @@ -45,7 +51,6 @@ 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 @@ -58,38 +63,54 @@ const parseManifest = async (sessionFileName: string) => {

const saveGetManifest = async () => {
const session = await saveSession();
await browser.pause(1000); // wait for writing to finish before unzipping?
const manifest = await parseManifest(session);
return { session, manifest };
};

const getRectangleCount = async () => {
const oneRectangleContainer = (await volViewPage.rectangleToolContainers)[0];
const rectangles = await oneRectangleContainer.$$('g');
const getRectangleCount = async (view: WebdriverIO.Element) => {
const rectangles = await view.$$(
'svg[data-testid="rectangle-tool-container"] > g'
);
return rectangles.length;
};

const waitForRectangleCount = async (count: number) => {
// wait for rectangle to be drawn
const waitForRectangleCount = async (
view: WebdriverIO.Element,
count: number
) => {
await browser.waitUntil(
async function newRectangleExist() {
const updatedCount = await getRectangleCount();
const updatedCount = await getRectangleCount(view);
console.log('updatedCount', updatedCount, count);
return updatedCount >= count;
},
{ timeoutMsg: `expected ${count} rectangles to be drawn` }
{
timeoutMsg: `expected ${count} rectangles to be drawn in ${SLOW_INTERACTION_TIMEOUT} ms}`,
timeout: SLOW_INTERACTION_TIMEOUT,
}
);
};

const clickTwice = async (view: WebdriverIO.Element) => {
await view.click({ x: 1, y: 1 });
await browser.pause(500);
await view.click({ x: 30, y: 30 });
};

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

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

await volViewPage.clickTwiceInTwoView();
await waitForRectangleCount(2); // wait for drawn tool
await browser.pause(1000);
const view = await volViewPage.viewTwoContainer;
await waitForRectangleCount(view, 1); // wait for placing tool
await browser.pause(500);
await clickTwice(view);
await waitForRectangleCount(view, 2); // wait for drawn tool
};

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

0 comments on commit f5cc095

Please sign in to comment.