From 884577a23d9b44505321fbb09dc5c0a42aaa69a1 Mon Sep 17 00:00:00 2001 From: Bill Wallace Date: Tue, 15 Aug 2023 07:20:45 -0400 Subject: [PATCH] fix: Integration test instability (#3597) There are a couple of changes here which should improve stability of the tests. Hopefully that will be sufficient, but it is difficult to tell for sure if it is complete. --- .gitmodules | 1 + extensions/cornerstone/src/init.tsx | 11 ++- .../viewports/TrackedCornerstoneViewport.tsx | 3 +- .../OHIFMeasurementPanel.spec.js | 1 + platform/app/cypress/support/commands.js | 73 +++++++++++-------- testdata | 2 +- 6 files changed, 51 insertions(+), 40 deletions(-) diff --git a/.gitmodules b/.gitmodules index 413cf77c1..f787a67a4 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,4 @@ [submodule "testdata"] path = testdata url = https://github.com/OHIF/viewer-testdata-dicomweb.git + branch = main diff --git a/extensions/cornerstone/src/init.tsx b/extensions/cornerstone/src/init.tsx index bda746947..40e318da0 100644 --- a/extensions/cornerstone/src/init.tsx +++ b/extensions/cornerstone/src/init.tsx @@ -54,12 +54,11 @@ export default async function init({ }, }); - // For debugging large datasets - const MAX_CACHE_SIZE_1GB = 1073741824; - const maxCacheSize = appConfig.maxCacheSize; - cornerstone.cache.setMaxCacheSize( - maxCacheSize ? maxCacheSize : MAX_CACHE_SIZE_1GB - ); + // For debugging large datasets, otherwise prefer the defaults + const { maxCacheSize } = appConfig; + if (maxCacheSize) { + cornerstone.cache.setMaxCacheSize(maxCacheSize); + } initCornerstoneTools(); diff --git a/extensions/measurement-tracking/src/viewports/TrackedCornerstoneViewport.tsx b/extensions/measurement-tracking/src/viewports/TrackedCornerstoneViewport.tsx index f65d0d034..00e2c974b 100644 --- a/extensions/measurement-tracking/src/viewports/TrackedCornerstoneViewport.tsx +++ b/extensions/measurement-tracking/src/viewports/TrackedCornerstoneViewport.tsx @@ -259,8 +259,9 @@ function TrackedCornerstoneViewport(props) { patientAge: PatientAge || '', MRN: PatientID || '', thickness: SliceThickness - ? `${parseFloat(SliceThickness).toFixed(2)}mm` + ? `${parseFloat(SliceThickness).toFixed(2)}` : '', + thicknessUnits: 'mm', spacing: SpacingBetweenSlices !== undefined ? `${parseFloat(SpacingBetweenSlices).toFixed(2)}mm` diff --git a/platform/app/cypress/integration/measurement-tracking/OHIFMeasurementPanel.spec.js b/platform/app/cypress/integration/measurement-tracking/OHIFMeasurementPanel.spec.js index f41cd7480..b06a0fd9e 100644 --- a/platform/app/cypress/integration/measurement-tracking/OHIFMeasurementPanel.spec.js +++ b/platform/app/cypress/integration/measurement-tracking/OHIFMeasurementPanel.spec.js @@ -8,6 +8,7 @@ describe('OHIF Measurement Panel', function() { cy.initCommonElementsAliases(); cy.initCornerstoneToolsAliases(); cy.resetViewport().wait(50); + cy.waitDicomImage(); }); it('checks if Measurements right panel can be hidden/displayed', function() { diff --git a/platform/app/cypress/support/commands.js b/platform/app/cypress/support/commands.js index 0585c8034..5b0383294 100644 --- a/platform/app/cypress/support/commands.js +++ b/platform/app/cypress/support/commands.js @@ -56,14 +56,14 @@ Cypress.Commands.add('openStudy', PatientName => { Cypress.Commands.add( 'checkStudyRouteInViewer', - (StudyInstanceUID, otherParams = '') => { + (StudyInstanceUID, otherParams = '', mode = '/basic-test') => { cy.location('pathname').then($url => { cy.log($url); if ( $url === 'blank' || - !$url.includes(`/basic-test/${StudyInstanceUID}${otherParams}`) + !$url.includes(`${mode}/${StudyInstanceUID}${otherParams}`) ) { - cy.openStudyInViewer(StudyInstanceUID, otherParams); + cy.openStudyInViewer(StudyInstanceUID, otherParams, mode); cy.waitDicomImage(); // Very short wait to ensure pending updates are handled cy.wait(25); @@ -74,8 +74,8 @@ Cypress.Commands.add( Cypress.Commands.add( 'openStudyInViewer', - (StudyInstanceUID, otherParams = '') => { - cy.visit(`/basic-test?StudyInstanceUIDs=${StudyInstanceUID}${otherParams}`); + (StudyInstanceUID, otherParams = '', mode = '/basic-test') => { + cy.visit(`${mode}?StudyInstanceUIDs=${StudyInstanceUID}${otherParams}`); } ); @@ -156,13 +156,13 @@ Cypress.Commands.add('addLine', (viewport, firstClick, secondClick) => { const [x1, y1] = firstClick; const [x2, y2] = secondClick; - // TODO: Added a wait which appears necessary in Cornerstone Tools >4? + // The wait is necessary because of double click testing cy.wrap($viewport) - .click(x1, y1, { force: true }) - .wait(100) + .click(x1, y1) + .wait(250) .trigger('mousemove', { clientX: x2, clientY: y2 }) - .click(x2, y2, { force: true }) - .wait(100); + .click(x2, y2) + .wait(250); }); }); @@ -202,28 +202,33 @@ Cypress.Commands.add('expectMinimumThumbnails', (seriesToWait = 1) => { }); //Command to wait DICOM image to load into the viewport -Cypress.Commands.add('waitDicomImage', () => { - cy.window() - .its('cornerstone') - .should($cornerstone => { - const enabled = $cornerstone.getEnabledElements(); - if (enabled?.length) { - enabled.forEach((item, i) => { - if ( - item.viewport.viewportStatus !== - $cornerstone.Enums.ViewportStatus.RENDERED - ) { - throw new Error( - `Viewport ${i} in state ${item.viewport.viewportStatus}` - ); - } - }); - } else { - throw new Error('No enabled elements'); - } - }); - cy.log('DICOM image loaded'); -}); +Cypress.Commands.add( + 'waitDicomImage', + (mode = '/basic-test', timeout = 50000) => { + cy.window() + .its('cornerstone') + .should($cornerstone => { + const enabled = $cornerstone.getEnabledElements(); + if (enabled?.length) { + enabled.forEach((item, i) => { + if ( + item.viewport.viewportStatus !== + $cornerstone.Enums.ViewportStatus.RENDERED + ) { + throw new Error( + `Viewport ${i} in state ${item.viewport.viewportStatus}` + ); + } + }); + } else { + throw new Error('No enabled elements'); + } + }); + // This shouldn't be necessary, but seems to be. + cy.wait(250); + cy.log('DICOM image loaded'); + } +); //Command to reset and clear all the changes made to the viewport Cypress.Commands.add('resetViewport', () => { @@ -237,6 +242,7 @@ Cypress.Commands.add('resetViewport', () => { Cypress.Commands.add('imageZoomIn', () => { cy.initCornerstoneToolsAliases(); cy.get('@zoomBtn').click(); + cy.wait(25); //drags the mouse inside the viewport to be able to interact with series cy.get('@viewport') @@ -248,6 +254,7 @@ Cypress.Commands.add('imageZoomIn', () => { Cypress.Commands.add('imageContrast', () => { cy.initCornerstoneToolsAliases(); cy.get('@wwwcBtnPrimary').click(); + cy.wait(25); //drags the mouse inside the viewport to be able to interact with series cy.get('@viewport') @@ -295,7 +302,9 @@ Cypress.Commands.add( Cypress.Commands.add( 'addAngleMeasurement', (initPos = [180, 390], midPos = [300, 410], finalPos = [180, 450]) => { + cy.get('[data-cy="MeasurementTools-split-button-secondary"]').click(); cy.get('[data-cy="Angle"]').click(); + cy.addAngle('.viewport-element', initPos, midPos, finalPos); } ); diff --git a/testdata b/testdata index 4d59660c2..da63adc20 160000 --- a/testdata +++ b/testdata @@ -1 +1 @@ -Subproject commit 4d59660c2883ed749a680e5fb6d4624ab54c9422 +Subproject commit da63adc206455ce860b87c6fe723d71fb415a891