From 030e1e41047547ad5e4024788dd4ea6d7417500d Mon Sep 17 00:00:00 2001 From: Bill Wallace Date: Wed, 19 Jul 2023 09:41:47 -0400 Subject: [PATCH] chore(test): Integration test wait until rendered/queried instead of timed (#3540) --- extensions/cornerstone-dicom-sr/package.json | 6 +- extensions/cornerstone/package.json | 8 +- extensions/measurement-tracking/package.json | 4 +- platform/app/cypress/support/commands.js | 78 +++++++------------ platform/app/src/routes/WorkList/WorkList.tsx | 7 +- .../StudyListTable/StudyListTable.tsx | 5 +- yarn.lock | 38 +++++---- 7 files changed, 70 insertions(+), 76 deletions(-) diff --git a/extensions/cornerstone-dicom-sr/package.json b/extensions/cornerstone-dicom-sr/package.json index 8dac65ef21a..4c458f041e1 100644 --- a/extensions/cornerstone-dicom-sr/package.json +++ b/extensions/cornerstone-dicom-sr/package.json @@ -44,9 +44,9 @@ }, "dependencies": { "@babel/runtime": "^7.20.13", - "@cornerstonejs/adapters": "^1.4.4", - "@cornerstonejs/core": "^1.4.4", - "@cornerstonejs/tools": "^1.4.4", + "@cornerstonejs/adapters": "^1.5.0", + "@cornerstonejs/core": "^1.5.0", + "@cornerstonejs/tools": "^1.5.0", "classnames": "^2.3.2" } } diff --git a/extensions/cornerstone/package.json b/extensions/cornerstone/package.json index 00d262e6eee..e81d368f1c3 100644 --- a/extensions/cornerstone/package.json +++ b/extensions/cornerstone/package.json @@ -52,10 +52,10 @@ }, "dependencies": { "@babel/runtime": "^7.20.13", - "@cornerstonejs/adapters": "^1.4.4", - "@cornerstonejs/core": "^1.4.4", - "@cornerstonejs/streaming-image-volume-loader": "^1.4.4", - "@cornerstonejs/tools": "^1.4.4", + "@cornerstonejs/adapters": "^1.5.0", + "@cornerstonejs/core": "^1.5.0", + "@cornerstonejs/streaming-image-volume-loader": "^1.5.0", + "@cornerstonejs/tools": "^1.5.0", "@kitware/vtk.js": "27.3.1", "html2canvas": "^1.4.1", "lodash.debounce": "4.0.8", diff --git a/extensions/measurement-tracking/package.json b/extensions/measurement-tracking/package.json index d4e69bc3da5..89117143fd5 100644 --- a/extensions/measurement-tracking/package.json +++ b/extensions/measurement-tracking/package.json @@ -30,8 +30,8 @@ "start": "yarn run dev" }, "peerDependencies": { - "@cornerstonejs/core": "^1.4.4", - "@cornerstonejs/tools": "^1.4.4", + "@cornerstonejs/core": "^1.5.0", + "@cornerstonejs/tools": "^1.5.0", "@ohif/core": "3.7.0-beta.33", "@ohif/extension-cornerstone-dicom-sr": "3.7.0-beta.33", "@ohif/ui": "3.7.0-beta.33", diff --git a/platform/app/cypress/support/commands.js b/platform/app/cypress/support/commands.js index df760db1035..0f22951ee73 100644 --- a/platform/app/cypress/support/commands.js +++ b/platform/app/cypress/support/commands.js @@ -46,7 +46,7 @@ Cypress.Commands.add('openStudy', PatientName => { cy.openStudyList(); cy.get('#filter-patientNameOrId').type(PatientName); // cy.get('@getStudies').then(() => { - cy.wait(1000); + cy.waitQueryList(); cy.get('[data-cy="study-list-results"]', { timeout: 5000 }) .contains(PatientName) @@ -65,7 +65,8 @@ Cypress.Commands.add( ) { cy.openStudyInViewer(StudyInstanceUID, otherParams); cy.waitDicomImage(); - cy.wait(2000); + // Very short wait to ensure pending updates are handled + cy.wait(25); } }); } @@ -78,6 +79,9 @@ Cypress.Commands.add( } ); +Cypress.Commands.add('waitQueryList', () => { + cy.get('[data-querying="false"]'); +}); /** * Command to search for a Modality and open the study. * @@ -89,7 +93,7 @@ Cypress.Commands.add('openStudyModality', Modality => { cy.get('#filter-accessionOrModalityOrDescription') .type(Modality) - .wait(2000); + .waitQueryList(); cy.get('[data-cy="study-list-results"]') .contains(Modality) @@ -113,7 +117,7 @@ Cypress.Commands.add('openStudyList', () => { // For some reason cypress 12.x does not like to stub the network request // so we just wait herer for 1 second // cy.wait('@getStudies'); - cy.wait(1000); + cy.waitQueryList(); }); Cypress.Commands.add('waitStudyList', () => { @@ -198,54 +202,27 @@ Cypress.Commands.add('expectMinimumThumbnails', (seriesToWait = 1) => { }); //Command to wait DICOM image to load into the viewport -Cypress.Commands.add('waitDicomImage', (timeout = 50000) => { - const loaded = cy.isPageLoaded(); - - if (loaded) { - cy.window() - .its('cornerstone') - .then({ timeout }, $cornerstone => { - return new Cypress.Promise(resolve => { - const onEvent = renderedEvt => { - const element = renderedEvt.detail.element; - - element.removeEventListener( - $cornerstone.Enums.Events.IMAGE_RENDERED, - onEvent - ); - $cornerstone.eventTarget.removeEventListener( - $cornerstone.Enums.Events.IMAGE_RENDERED, - onEvent - ); - resolve(); - }; - const onEnabled = enabledEvt => { - const element = enabledEvt.detail.element; - - element.addEventListener( - $cornerstone.Enums.Events.IMAGE_RENDERED, - onEvent - ); - - $cornerstone.eventTarget.removeEventListener( - $cornerstone.Enums.Events.ELEMENT_ENABLED, - onEnabled - ); - }; - const enabledElements = $cornerstone.getEnabledElements(); - if (enabledElements && enabledElements.length) { - // Sometimes the page finishes rendering before this gets run, - // if so, just resolve immediately. - resolve(); - } else { - $cornerstone.eventTarget.addEventListener( - $cornerstone.Enums.Events.ELEMENT_ENABLED, - onEnabled +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'); }); //Command to reset and clear all the changes made to the viewport @@ -401,7 +378,8 @@ Cypress.Commands.add('setLayout', (columns = 1, rows = 1) => { .eq(columns - 1) .click(); - cy.wait(1000); + cy.wait(10); + cy.waitDicomImage(); }); function convertCanvas(documentClone) { diff --git a/platform/app/src/routes/WorkList/WorkList.tsx b/platform/app/src/routes/WorkList/WorkList.tsx index 7156b5451c4..a30141bb2af 100644 --- a/platform/app/src/routes/WorkList/WorkList.tsx +++ b/platform/app/src/routes/WorkList/WorkList.tsx @@ -1,4 +1,4 @@ -import React, { useState, useEffect } from 'react'; +import React, { useState, useEffect, useMemo } from 'react'; import classnames from 'classnames'; import PropTypes from 'prop-types'; import { Link, useNavigate } from 'react-router-dom'; @@ -112,6 +112,9 @@ function WorkList({ const [expandedRows, setExpandedRows] = useState([]); const [studiesWithSeriesData, setStudiesWithSeriesData] = useState([]); const numOfStudies = studiesTotal; + const querying = useMemo(() => { + return isLoadingData || expandedRows.length > 0; + }, [isLoadingData, expandedRows]); const setFilterValues = val => { if (filterValues.pageNumber === val.pageNumber) { @@ -218,6 +221,7 @@ function WorkList({ fetchSeries(studyInstanceUid); } + // eslint-disable-next-line react-hooks/exhaustive-deps }, [expandedRows, studies]); @@ -501,6 +505,7 @@ function WorkList({
diff --git a/platform/ui/src/components/StudyListTable/StudyListTable.tsx b/platform/ui/src/components/StudyListTable/StudyListTable.tsx index a6fdf50fff3..abe9615cafe 100644 --- a/platform/ui/src/components/StudyListTable/StudyListTable.tsx +++ b/platform/ui/src/components/StudyListTable/StudyListTable.tsx @@ -3,12 +3,12 @@ import PropTypes from 'prop-types'; import StudyListTableRow from './StudyListTableRow'; -const StudyListTable = ({ tableDataSource }) => { +const StudyListTable = ({ tableDataSource, querying }) => { return (
- + {tableDataSource.map((tableData, i) => { return ; })} @@ -24,6 +24,7 @@ StudyListTable.propTypes = { PropTypes.shape({ row: PropTypes.array.isRequired, expandedContent: PropTypes.node.isRequired, + querying: PropTypes.bool, onClickRow: PropTypes.func.isRequired, isExpanded: PropTypes.bool.isRequired, }) diff --git a/yarn.lock b/yarn.lock index f80a61bda0a..a4e5c9d93e2 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1589,10 +1589,10 @@ resolved "https://registry.yarnpkg.com/@colors/colors/-/colors-1.5.0.tgz#bb504579c1cae923e6576a4f5da43d25f97bdbd9" integrity sha512-ooWCrlZP11i8GImSjTHYHLkvFDP48nS4+204nGb1RiX/WXYHmJA2III9/e2DWVabCESdW7hBAEzHRqUn9OUVvQ== -"@cornerstonejs/adapters@^1.4.4": - version "1.4.4" - resolved "https://registry.yarnpkg.com/@cornerstonejs/adapters/-/adapters-1.4.4.tgz#49e31d5f25412688ac451a666bc7a5e5937b59ec" - integrity sha512-MY7o6QX319DtjUCmJ2cHvzreFcaeKm2jwYH8uf5pCHbpjeW8W2HTifqSLec4CYTefWlxQgRAT46On9sDmGojJA== +"@cornerstonejs/adapters@^1.5.0": + version "1.5.0" + resolved "https://registry.yarnpkg.com/@cornerstonejs/adapters/-/adapters-1.5.0.tgz#3ff8e0e6c36b8a080f4550180b6d713b17af6288" + integrity sha512-GLn2yKNOz4PODjgVt2i2in6ageYebazuECzm61u/oqHF+i1oIc6GUk1mD6SLA8D71DG3EAxW+T4/YNgN+Fcv5g== dependencies: "@babel/runtime-corejs2" "^7.17.8" dcmjs "^0.29.5" @@ -1650,6 +1650,16 @@ gl-matrix "^3.4.3" lodash.clonedeep "4.5.0" +"@cornerstonejs/core@^1.5.0": + version "1.5.0" + resolved "https://registry.yarnpkg.com/@cornerstonejs/core/-/core-1.5.0.tgz#20eaae16456f42a9f3eb2989a048afe43b4a64a4" + integrity sha512-AytOb2eepFaF95WuufXe+u3q4Xtu/BNPYppiFJlupGk7a1vRO0ESb+p+EJnZB3UCeJOr26ToVbpXPGvihpPv5Q== + dependencies: + "@kitware/vtk.js" "27.3.1" + detect-gpu "^5.0.22" + gl-matrix "^3.4.3" + lodash.clonedeep "4.5.0" + "@cornerstonejs/dicom-image-loader@^1.4.4": version "1.4.4" resolved "https://registry.yarnpkg.com/@cornerstonejs/dicom-image-loader/-/dicom-image-loader-1.4.4.tgz#49eae4dcb32427d7b992f10d277423692632e507" @@ -1664,19 +1674,19 @@ pako "^2.0.4" uuid "^9.0.0" -"@cornerstonejs/streaming-image-volume-loader@^1.4.4": - version "1.4.4" - resolved "https://registry.yarnpkg.com/@cornerstonejs/streaming-image-volume-loader/-/streaming-image-volume-loader-1.4.4.tgz#f92575eecd6ac5988a40c7f9e2d7a223e9948e6c" - integrity sha512-/er5VwRsOlMssFx+zPBqLWD/RM3MCqzTVXg+DHw3fi/TFTUqK1TmrrEoLQmL6wKPV2zpKbnhqaWFj0GyLu0kVA== +"@cornerstonejs/streaming-image-volume-loader@^1.5.0": + version "1.5.0" + resolved "https://registry.yarnpkg.com/@cornerstonejs/streaming-image-volume-loader/-/streaming-image-volume-loader-1.5.0.tgz#5a235210ac37d88c8bbcc3a9ec9ce66f925cada7" + integrity sha512-3O20GZdjl3Mk8F8OK+m9jB2A6p0qdI01uTb1zcFeubZLtMRQQDRK9WPv1yDJTpTSGUGXtP/unNBHvwP1YEfyLw== dependencies: - "@cornerstonejs/core" "^1.4.4" + "@cornerstonejs/core" "^1.5.0" -"@cornerstonejs/tools@^1.4.4": - version "1.4.4" - resolved "https://registry.yarnpkg.com/@cornerstonejs/tools/-/tools-1.4.4.tgz#3568dfe089977a2be23b631a81106542799713d0" - integrity sha512-edS63QnkoYxjSGfjetOGfotNACVk57R9or+GYz6r7NsBxnjy00Xxrj5twf4SM0PsAJcaDi/1gDwtahoiUlLELg== +"@cornerstonejs/tools@^1.5.0": + version "1.5.0" + resolved "https://registry.yarnpkg.com/@cornerstonejs/tools/-/tools-1.5.0.tgz#edde925fe5feeafbed782be7f6479e064d53e7ac" + integrity sha512-q9pjDXN1OBkXL0NOtzrphz74BN8N5WWi06y5XahxnuDQ3F/6xDYLnrCLD8msPIO54jb7UeNDXF5cyvA+FXGDBw== dependencies: - "@cornerstonejs/core" "^1.4.4" + "@cornerstonejs/core" "^1.5.0" lodash.clonedeep "4.5.0" lodash.get "^4.4.2"