@ohif/extension-cornerstone 3.14.0-beta.98 → 3.14.0-beta.99
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/915.ohif-extension-cornerstone.umd.js +1 -1
- package/dist/ohif-extension-cornerstone.umd.js +1 -5
- package/package.json +18 -8
- package/src/Viewport/OHIFCornerstoneViewport.css +46 -0
- package/src/Viewport/OHIFCornerstoneViewport.tsx +502 -0
- package/src/Viewport/Overlays/CornerstoneOverlays.tsx +103 -0
- package/src/Viewport/Overlays/CustomizableViewportOverlay.css +25 -0
- package/src/Viewport/Overlays/CustomizableViewportOverlay.tsx +469 -0
- package/src/Viewport/Overlays/ViewportImageScrollbar.tsx +106 -0
- package/src/Viewport/Overlays/ViewportImageSliceLoadingIndicator.tsx +87 -0
- package/src/Viewport/Overlays/ViewportOrientationMarkers.css +41 -0
- package/src/Viewport/Overlays/ViewportOrientationMarkers.tsx +136 -0
- package/src/Viewport/Overlays/ViewportSliceProgressScrollbar/ViewportSliceProgressScrollbar.tsx +195 -0
- package/src/Viewport/Overlays/ViewportSliceProgressScrollbar/helpers.ts +46 -0
- package/src/Viewport/Overlays/ViewportSliceProgressScrollbar/hooks.ts +383 -0
- package/src/Viewport/Overlays/ViewportSliceProgressScrollbar/index.ts +1 -0
- package/src/Viewport/Overlays/ViewportSliceProgressScrollbar/types.ts +17 -0
- package/src/Viewport/Overlays/utils.ts +66 -0
- package/src/commandsModule.ts +2951 -0
- package/src/components/AccordionGroup/AccordionGroup.tsx +195 -0
- package/src/components/AccordionGroup/index.ts +4 -0
- package/src/components/ActiveViewportWindowLevel/ActiveViewportWindowLevel.tsx +23 -0
- package/src/components/ActiveViewportWindowLevel/index.js +1 -0
- package/src/components/AdvancedRenderingControls/AdvancedRenderingControls.tsx +149 -0
- package/src/components/AdvancedRenderingControls/index.ts +1 -0
- package/src/components/CinePlayer/CinePlayer.tsx +247 -0
- package/src/components/CinePlayer/index.ts +3 -0
- package/src/components/DicomUpload/DicomUpload.tsx +111 -0
- package/src/components/DicomUpload/DicomUploadProgress.tsx +396 -0
- package/src/components/DicomUpload/DicomUploadProgressItem.tsx +119 -0
- package/src/components/ExportSegmentationSubMenuItem.tsx +75 -0
- package/src/components/MeasurementItems.tsx +70 -0
- package/src/components/MeasurementTableNested.tsx +30 -0
- package/src/components/MeasurementsMenu.tsx +84 -0
- package/src/components/MeasurementsOrAdditionalFindings.tsx +82 -0
- package/src/components/ModalityLoadBadge/ModalityLoadBadge.tsx +171 -0
- package/src/components/ModalityLoadBadge/index.ts +1 -0
- package/src/components/NavigationComponent/NavigationComponent.tsx +138 -0
- package/src/components/NavigationComponent/index.ts +3 -0
- package/src/components/OHIFViewportActionCorners.tsx +94 -0
- package/src/components/OpacityMenu/OpacityMenu.tsx +54 -0
- package/src/components/OpacityMenu/OpacityMenuWrapper.tsx +85 -0
- package/src/components/OpacityMenu/index.ts +2 -0
- package/src/components/PanelAccordionTrigger.tsx +48 -0
- package/src/components/SegmentationToolConfig.tsx +71 -0
- package/src/components/SegmentationUtilityButton.tsx +61 -0
- package/src/components/SelectItemWithModality.tsx +29 -0
- package/src/components/SeriesMeasurements.tsx +90 -0
- package/src/components/SeriesSummaryFromDisplaySet.tsx +21 -0
- package/src/components/StudyMeasurements.tsx +88 -0
- package/src/components/StudyMeasurementsActions.tsx +75 -0
- package/src/components/StudySummaryFromMetadata.test.ts +47 -0
- package/src/components/StudySummaryFromMetadata.tsx +31 -0
- package/src/components/StudySummaryWithActions.tsx +14 -0
- package/src/components/ThresholdMenu/ThresholdMenu.tsx +104 -0
- package/src/components/ThresholdMenu/ThresholdMenuWrapper.tsx +85 -0
- package/src/components/ThresholdMenu/index.ts +2 -0
- package/src/components/TrackingStatus/TrackingStatus.tsx +32 -0
- package/src/components/TrackingStatus/index.ts +1 -0
- package/src/components/VOIManualControlMenu/VOIManualControlMenu.tsx +190 -0
- package/src/components/VOIManualControlMenu/VOIManualControlMenuWrapper.tsx +85 -0
- package/src/components/VOIManualControlMenu/index.ts +2 -0
- package/src/components/ViewportColorbar/ViewportColorbar.tsx +150 -0
- package/src/components/ViewportColorbar/ViewportColorbarsContainer.tsx +125 -0
- package/src/components/ViewportColorbar/index.ts +5 -0
- package/src/components/ViewportDataOverlaySettingMenu/ViewportDataOverlayMenu.tsx +538 -0
- package/src/components/ViewportDataOverlaySettingMenu/ViewportDataOverlayMenuWrapper.tsx +91 -0
- package/src/components/ViewportDataOverlaySettingMenu/utils.ts +118 -0
- package/src/components/ViewportOrientationMenu/ViewportOrientationMenu.tsx +249 -0
- package/src/components/ViewportOrientationMenu/ViewportOrientationMenuWrapper.tsx +29 -0
- package/src/components/ViewportWindowLevel/ViewportWindowLevel.tsx +261 -0
- package/src/components/ViewportWindowLevel/getViewportVolumeHistogram.ts +72 -0
- package/src/components/ViewportWindowLevel/histogramWorker.js +97 -0
- package/src/components/ViewportWindowLevel/index.js +1 -0
- package/src/components/ViewportWindowLevel/utils.ts +176 -0
- package/src/components/WindowLevelActionMenu/Colorbar.tsx +30 -0
- package/src/components/WindowLevelActionMenu/Colormap.tsx +121 -0
- package/src/components/WindowLevelActionMenu/VolumeLighting.tsx +82 -0
- package/src/components/WindowLevelActionMenu/VolumeRenderingOptions.tsx +38 -0
- package/src/components/WindowLevelActionMenu/VolumeRenderingPresets.tsx +36 -0
- package/src/components/WindowLevelActionMenu/VolumeRenderingPresetsContent.tsx +78 -0
- package/src/components/WindowLevelActionMenu/VolumeRenderingQuality.tsx +64 -0
- package/src/components/WindowLevelActionMenu/VolumeShade.tsx +47 -0
- package/src/components/WindowLevelActionMenu/VolumeShift.tsx +92 -0
- package/src/components/WindowLevelActionMenu/WindowLevel.tsx +157 -0
- package/src/components/WindowLevelActionMenu/WindowLevelActionMenu.tsx +102 -0
- package/src/components/WindowLevelActionMenu/WindowLevelActionMenuWrapper.tsx +131 -0
- package/src/components/WindowLevelActionMenu/defaultWindowLevelPresets.ts +23 -0
- package/src/components/WindowLevelActionMenu/index.ts +11 -0
- package/src/components/WindowLevelActionMenu/windowLevelPresetHotkeys.test.ts +19 -0
- package/src/components/index.ts +12 -0
- package/src/constants/index.ts +13 -0
- package/src/customizations/CustomDropdownMenuContent.tsx +106 -0
- package/src/customizations/CustomSegmentStatisticsHeader.tsx +140 -0
- package/src/customizations/captureViewportModalCustomization.tsx +175 -0
- package/src/customizations/colorbarCustomization.ts +93 -0
- package/src/customizations/gpuSettingsPresetCustomization.ts +8 -0
- package/src/customizations/layoutSelectorCustomization.ts +104 -0
- package/src/customizations/measurementsCustomization.ts +124 -0
- package/src/customizations/miscCustomization.ts +22 -0
- package/src/customizations/modalityColorMapCustomization.ts +23 -0
- package/src/customizations/segmentationHydrationCustomization.ts +16 -0
- package/src/customizations/segmentationPanelCustomization.tsx +119 -0
- package/src/customizations/segmentationToolbarCustomization.ts +964 -0
- package/src/customizations/toolGroupToolsCustomization.ts +204 -0
- package/src/customizations/toolbarButtonsCustomization.ts +805 -0
- package/src/customizations/viewportClickCommandsCustomization.ts +15 -0
- package/src/customizations/viewportDownloadWarningCustomization.tsx +6 -0
- package/src/customizations/viewportOverlayCustomization.tsx +46 -0
- package/src/customizations/viewportScrollbarCustomization.tsx +27 -0
- package/src/customizations/viewportToolsCustomization.ts +33 -0
- package/src/customizations/volumeRenderingCustomization.ts +14 -0
- package/src/customizations/windowLevelPresetsCustomization.ts +5 -0
- package/src/enums.ts +9 -0
- package/src/getCustomizationModule.tsx +54 -0
- package/src/getHangingProtocolModule.ts +47 -0
- package/src/getPanelModule.tsx +128 -0
- package/src/getSopClassHandlerModule.js +284 -0
- package/src/getToolbarModule.tsx +622 -0
- package/src/hooks/index.ts +8 -0
- package/src/hooks/useActiveViewportSegmentationRepresentations.ts +14 -0
- package/src/hooks/useMeasurementTracking.ts +132 -0
- package/src/hooks/useMeasurements.ts +104 -0
- package/src/hooks/useSegmentations.ts +147 -0
- package/src/hooks/useViewportDisplaySets.ts +284 -0
- package/src/hooks/useViewportHover.ts +77 -0
- package/src/hooks/useViewportRendering.tsx +868 -0
- package/src/hooks/useViewportSegmentations.ts +245 -0
- package/src/hps/fourUp.ts +117 -0
- package/src/hps/frameView.ts +1581 -0
- package/src/hps/main3D.ts +142 -0
- package/src/hps/mpr.ts +197 -0
- package/src/hps/mprAnd3DVolumeViewport.ts +124 -0
- package/src/hps/only3D.ts +70 -0
- package/src/hps/primary3D.ts +142 -0
- package/src/hps/primaryAxial.ts +114 -0
- package/src/id.js +5 -0
- package/src/index.tsx +350 -0
- package/src/init.tsx +445 -0
- package/src/initCineService.ts +75 -0
- package/src/initContextMenu.ts +94 -0
- package/src/initCornerstoneTools.js +188 -0
- package/src/initDoubleClick.ts +82 -0
- package/src/initMeasurementService.ts +576 -0
- package/src/initStudyPrefetcherService.ts +33 -0
- package/src/initWADOImageLoader.js +56 -0
- package/src/panels/PanelMeasurement.tsx +84 -0
- package/src/panels/PanelSegmentation.tsx +338 -0
- package/src/services/ColorbarService/ColorbarService.ts +242 -0
- package/src/services/ColorbarService/index.ts +2 -0
- package/src/services/CornerstoneCacheService/CornerstoneCacheService.ts +326 -0
- package/src/services/CornerstoneCacheService/index.js +3 -0
- package/src/services/SegmentationService/RTSTRUCT/mapROIContoursToRTStructData.ts +36 -0
- package/src/services/SegmentationService/SegmentationService.test.ts +3698 -0
- package/src/services/SegmentationService/SegmentationService.ts +2376 -0
- package/src/services/SegmentationService/backends/ISegmentationBackend.ts +102 -0
- package/src/services/SegmentationService/backends/ISegmentationServiceInternals.ts +44 -0
- package/src/services/SegmentationService/backends/LegacySegmentationBackend.ts +139 -0
- package/src/services/SegmentationService/backends/NextSegmentationBackend.ts +159 -0
- package/src/services/SegmentationService/backends/index.ts +4 -0
- package/src/services/SegmentationService/index.ts +3 -0
- package/src/services/SyncGroupService/SyncGroupService.ts +264 -0
- package/src/services/SyncGroupService/createHydrateSegmentationSynchronizer.ts +118 -0
- package/src/services/SyncGroupService/index.js +3 -0
- package/src/services/ToolGroupService/ToolGroupService.test.ts +83 -0
- package/src/services/ToolGroupService/ToolGroupService.ts +541 -0
- package/src/services/ToolGroupService/index.js +3 -0
- package/src/services/ViewedDataService/ViewedDataService.ts +58 -0
- package/src/services/ViewedDataService/index.ts +3 -0
- package/src/services/ViewportService/CornerstoneViewportService.ts +1814 -0
- package/src/services/ViewportService/IViewportService.ts +64 -0
- package/src/services/ViewportService/Viewport.ts +372 -0
- package/src/services/ViewportService/adapter/IViewportAdapter.contract.test.ts +467 -0
- package/src/services/ViewportService/adapter/IViewportAdapter.ts +179 -0
- package/src/services/ViewportService/adapter/LegacyViewportAdapter.ts +240 -0
- package/src/services/ViewportService/adapter/NextViewportAdapter.ts +241 -0
- package/src/services/ViewportService/adapter/getViewportAdapter.ts +62 -0
- package/src/services/ViewportService/adapter/index.ts +16 -0
- package/src/services/ViewportService/backends/IViewportBackend.ts +195 -0
- package/src/services/ViewportService/backends/IViewportOperations.ts +98 -0
- package/src/services/ViewportService/backends/IViewportServiceInternals.ts +47 -0
- package/src/services/ViewportService/backends/LegacyViewportBackend.ts +264 -0
- package/src/services/ViewportService/backends/LegacyViewportOperations.ts +272 -0
- package/src/services/ViewportService/backends/NextViewportBackend.ts +671 -0
- package/src/services/ViewportService/backends/NextViewportOperations.ts +169 -0
- package/src/services/ViewportService/backends/README.md +62 -0
- package/src/services/ViewportService/backends/dataIdRegistry.ts +121 -0
- package/src/services/ViewportService/backends/viewportOperations.ts +71 -0
- package/src/services/ViewportService/constants.ts +3 -0
- package/src/state.ts +34 -0
- package/src/stores/index.ts +5 -0
- package/src/stores/presentationUtils.ts +42 -0
- package/src/stores/useLutPresentationStore.ts +166 -0
- package/src/stores/usePositionPresentationStore.ts +172 -0
- package/src/stores/useSegmentationPresentationStore.test.ts +146 -0
- package/src/stores/useSegmentationPresentationStore.ts +417 -0
- package/src/stores/useSelectedSegmentationsForViewportStore.ts +85 -0
- package/src/stores/useSynchronizersStore.ts +84 -0
- package/src/synchronizers/frameViewSynchronizer.ts +52 -0
- package/src/tools/CalibrationLineTool.ts +97 -0
- package/src/tools/ImageOverlayViewerTool.tsx +279 -0
- package/src/tools/OverlayPlaneModuleProvider.ts +40 -0
- package/src/tools/WindowLevelTool.test.ts +55 -0
- package/src/tools/WindowLevelTool.ts +22 -0
- package/src/types/AppTypes.ts +70 -0
- package/src/types/Colorbar.ts +114 -0
- package/src/types/Colormap.ts +16 -0
- package/src/types/CornerstoneCacheService.ts +40 -0
- package/src/types/CornerstoneServices.ts +18 -0
- package/src/types/Presentation.ts +83 -0
- package/src/types/SelectedSegmentationByTypeMap.ts +3 -0
- package/src/types/ViewportPresets.ts +53 -0
- package/src/types/VolumeLighting.ts +7 -0
- package/src/types/VolumeRenderingConfig.ts +8 -0
- package/src/types/WindowLevel.ts +5 -0
- package/src/types/index.ts +10 -0
- package/src/utils/ActiveViewportBehavior.tsx +80 -0
- package/src/utils/CornerstoneViewportDownloadForm.tsx +319 -0
- package/src/utils/DicomFileUploader.ts +204 -0
- package/src/utils/JumpPresets.ts +14 -0
- package/src/utils/autoHydrateViewportTypes.ts +69 -0
- package/src/utils/colormaps.js +1597 -0
- package/src/utils/createSegmentationForViewport.ts +83 -0
- package/src/utils/dicomLoaderService.js +225 -0
- package/src/utils/ecgMetadata.test.ts +137 -0
- package/src/utils/ecgMetadata.ts +109 -0
- package/src/utils/findNearbyToolData.test.ts +125 -0
- package/src/utils/findNearbyToolData.ts +21 -0
- package/src/utils/generateSegmentationCSVReport.test.ts +324 -0
- package/src/utils/generateSegmentationCSVReport.ts +131 -0
- package/src/utils/getActiveViewportEnabledElement.test.ts +70 -0
- package/src/utils/getActiveViewportEnabledElement.ts +8 -0
- package/src/utils/getCenterExtent.test.ts +313 -0
- package/src/utils/getCenterExtent.ts +46 -0
- package/src/utils/getCornerstoneBlendMode.test.ts +59 -0
- package/src/utils/getCornerstoneBlendMode.ts +25 -0
- package/src/utils/getCornerstoneOrientation.test.ts +78 -0
- package/src/utils/getCornerstoneOrientation.ts +31 -0
- package/src/utils/getCornerstoneViewportType.test.ts +169 -0
- package/src/utils/getCornerstoneViewportType.ts +88 -0
- package/src/utils/getInterleavedFrames.test.ts +85 -0
- package/src/utils/getInterleavedFrames.ts +73 -0
- package/src/utils/getLegacyViewportType.ts +64 -0
- package/src/utils/getNthFrames.test.ts +145 -0
- package/src/utils/getNthFrames.ts +31 -0
- package/src/utils/getViewportEnabledElement.test.ts +83 -0
- package/src/utils/getViewportEnabledElement.ts +8 -0
- package/src/utils/getViewportOrientationFromImageOrientationPatient.test.ts +50 -0
- package/src/utils/getViewportOrientationFromImageOrientationPatient.ts +56 -0
- package/src/utils/hydrationUtils.test.ts +572 -0
- package/src/utils/hydrationUtils.ts +197 -0
- package/src/utils/imageSliceSync/calculateViewportRegistrations.ts +28 -0
- package/src/utils/imageSliceSync/toggleImageSliceSync.ts +101 -0
- package/src/utils/index.ts +29 -0
- package/src/utils/initGpuSettingsPreset.ts +51 -0
- package/src/utils/initViewTiming.test.ts +342 -0
- package/src/utils/initViewTiming.ts +52 -0
- package/src/utils/initWebWorkerProgressHandler.test.ts +381 -0
- package/src/utils/initWebWorkerProgressHandler.ts +110 -0
- package/src/utils/interleave.test.ts +304 -0
- package/src/utils/interleave.ts +32 -0
- package/src/utils/interleaveCenterLoader.test.ts +547 -0
- package/src/utils/interleaveCenterLoader.ts +143 -0
- package/src/utils/interleaveTopToBottom.test.ts +487 -0
- package/src/utils/interleaveTopToBottom.ts +132 -0
- package/src/utils/isAnyDisplaySetCommon.ts +18 -0
- package/src/utils/isDisplaySetOverlayable.ts +96 -0
- package/src/utils/isMeasurementWithinViewport.test.ts +340 -0
- package/src/utils/isMeasurementWithinViewport.ts +33 -0
- package/src/utils/isReferenceViewable.test.ts +581 -0
- package/src/utils/isReferenceViewable.ts +95 -0
- package/src/utils/loadDisplaySetData.ts +49 -0
- package/src/utils/measurementServiceMappings/Angle.ts +200 -0
- package/src/utils/measurementServiceMappings/ArrowAnnotate.ts +176 -0
- package/src/utils/measurementServiceMappings/Bidirectional.ts +193 -0
- package/src/utils/measurementServiceMappings/CircleROI.ts +227 -0
- package/src/utils/measurementServiceMappings/CobbAngle.ts +206 -0
- package/src/utils/measurementServiceMappings/EllipticalROI.ts +221 -0
- package/src/utils/measurementServiceMappings/Length.ts +206 -0
- package/src/utils/measurementServiceMappings/LivewireContour.ts +175 -0
- package/src/utils/measurementServiceMappings/PlanarFreehandROI.ts +228 -0
- package/src/utils/measurementServiceMappings/Probe.ts +192 -0
- package/src/utils/measurementServiceMappings/RectangleROI.ts +225 -0
- package/src/utils/measurementServiceMappings/SegmentBidirectional.ts +184 -0
- package/src/utils/measurementServiceMappings/SplineROI.ts +227 -0
- package/src/utils/measurementServiceMappings/UltrasoundDirectional.ts +214 -0
- package/src/utils/measurementServiceMappings/UltrasoundPleuraBLine.ts +179 -0
- package/src/utils/measurementServiceMappings/constants/supportedTools.js +21 -0
- package/src/utils/measurementServiceMappings/index.ts +3 -0
- package/src/utils/measurementServiceMappings/measurementServiceMappingsFactory.ts +324 -0
- package/src/utils/measurementServiceMappings/utils/getDisplayUnit.js +3 -0
- package/src/utils/measurementServiceMappings/utils/getHandlesFromPoints.js +14 -0
- package/src/utils/measurementServiceMappings/utils/getIsLocked.ts +5 -0
- package/src/utils/measurementServiceMappings/utils/getIsVisible.ts +6 -0
- package/src/utils/measurementServiceMappings/utils/getSOPInstanceAttributes.js +66 -0
- package/src/utils/measurementServiceMappings/utils/getValueDisplayString.js +12 -0
- package/src/utils/measurementServiceMappings/utils/index.ts +17 -0
- package/src/utils/measurementServiceMappings/utils/selection.ts +33 -0
- package/src/utils/mpr/getProtocolViewportStructureFromGridViewports.ts +74 -0
- package/src/utils/nextViewportPolicies.ts +41 -0
- package/src/utils/nextViewports.ts +157 -0
- package/src/utils/nthLoader.test.ts +317 -0
- package/src/utils/nthLoader.ts +78 -0
- package/src/utils/presentations/getViewportPresentations.test.ts +280 -0
- package/src/utils/presentations/getViewportPresentations.ts +151 -0
- package/src/utils/promptHydrationDialog.test.ts +490 -0
- package/src/utils/promptHydrationDialog.ts +197 -0
- package/src/utils/removeViewportSegmentationRepresentations.test.ts +129 -0
- package/src/utils/removeViewportSegmentationRepresentations.ts +17 -0
- package/src/utils/segmentUtils.test.ts +515 -0
- package/src/utils/segmentUtils.ts +46 -0
- package/src/utils/segmentationExportUtils.test.ts +100 -0
- package/src/utils/segmentationExportUtils.ts +171 -0
- package/src/utils/segmentationHandlers.test.ts +614 -0
- package/src/utils/segmentationHandlers.ts +164 -0
- package/src/utils/setUpAnnotationEventHandlers.ts +26 -0
- package/src/utils/setUpSegmentationEventHandlers.test.ts +372 -0
- package/src/utils/setUpSegmentationEventHandlers.ts +122 -0
- package/src/utils/toggleVOISliceSync.test.ts +606 -0
- package/src/utils/toggleVOISliceSync.ts +103 -0
- package/src/utils/transitions.test.ts +351 -0
- package/src/utils/transitions.ts +300 -0
- package/src/utils/updateSegmentationStats.test.ts +942 -0
- package/src/utils/updateSegmentationStats.ts +192 -0
- package/src/utils/viewportDataShape.ts +85 -0
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import { segmentation } from '@cornerstonejs/tools';
|
|
2
|
+
import removeViewportSegmentationRepresentations from './removeViewportSegmentationRepresentations';
|
|
3
|
+
|
|
4
|
+
jest.mock('@cornerstonejs/tools', () => ({
|
|
5
|
+
segmentation: {
|
|
6
|
+
state: {
|
|
7
|
+
getSegmentationRepresentations: jest.fn(),
|
|
8
|
+
removeSegmentationRepresentation: jest.fn(),
|
|
9
|
+
},
|
|
10
|
+
},
|
|
11
|
+
}));
|
|
12
|
+
|
|
13
|
+
describe('removeViewportSegmentationRepresentations', () => {
|
|
14
|
+
const viewportId = 'viewport-1';
|
|
15
|
+
|
|
16
|
+
beforeEach(() => {
|
|
17
|
+
jest.clearAllMocks();
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
it('should return early when no representations are found', () => {
|
|
21
|
+
(segmentation.state.getSegmentationRepresentations as jest.Mock).mockReturnValue(null);
|
|
22
|
+
|
|
23
|
+
removeViewportSegmentationRepresentations(viewportId);
|
|
24
|
+
|
|
25
|
+
expect(segmentation.state.getSegmentationRepresentations).toHaveBeenCalledWith(viewportId);
|
|
26
|
+
expect(segmentation.state.removeSegmentationRepresentation).not.toHaveBeenCalled();
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it('should return early when representations array is empty', () => {
|
|
30
|
+
(segmentation.state.getSegmentationRepresentations as jest.Mock).mockReturnValue([]);
|
|
31
|
+
|
|
32
|
+
removeViewportSegmentationRepresentations(viewportId);
|
|
33
|
+
|
|
34
|
+
expect(segmentation.state.removeSegmentationRepresentation).not.toHaveBeenCalled();
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
it('should remove single segmentation representation', () => {
|
|
38
|
+
const representations = [
|
|
39
|
+
{
|
|
40
|
+
segmentationRepresentationUID: 'representation-1',
|
|
41
|
+
},
|
|
42
|
+
];
|
|
43
|
+
|
|
44
|
+
(segmentation.state.getSegmentationRepresentations as jest.Mock).mockReturnValue(
|
|
45
|
+
representations
|
|
46
|
+
);
|
|
47
|
+
|
|
48
|
+
removeViewportSegmentationRepresentations(viewportId);
|
|
49
|
+
|
|
50
|
+
expect(segmentation.state.removeSegmentationRepresentation).toHaveBeenCalledTimes(1);
|
|
51
|
+
expect(segmentation.state.removeSegmentationRepresentation).toHaveBeenCalledWith(
|
|
52
|
+
'representation-1'
|
|
53
|
+
);
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
it('should remove multiple segmentation representations', () => {
|
|
57
|
+
const representations = [
|
|
58
|
+
{
|
|
59
|
+
segmentationRepresentationUID: 'representation-1',
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
segmentationRepresentationUID: 'representation-2',
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
segmentationRepresentationUID: 'representation-3',
|
|
66
|
+
},
|
|
67
|
+
];
|
|
68
|
+
|
|
69
|
+
(segmentation.state.getSegmentationRepresentations as jest.Mock).mockReturnValue(
|
|
70
|
+
representations
|
|
71
|
+
);
|
|
72
|
+
|
|
73
|
+
removeViewportSegmentationRepresentations(viewportId);
|
|
74
|
+
|
|
75
|
+
expect(segmentation.state.removeSegmentationRepresentation).toHaveBeenCalledTimes(3);
|
|
76
|
+
expect(segmentation.state.removeSegmentationRepresentation).toHaveBeenNthCalledWith(
|
|
77
|
+
1,
|
|
78
|
+
'representation-1'
|
|
79
|
+
);
|
|
80
|
+
expect(segmentation.state.removeSegmentationRepresentation).toHaveBeenNthCalledWith(
|
|
81
|
+
2,
|
|
82
|
+
'representation-2'
|
|
83
|
+
);
|
|
84
|
+
expect(segmentation.state.removeSegmentationRepresentation).toHaveBeenNthCalledWith(
|
|
85
|
+
3,
|
|
86
|
+
'representation-3'
|
|
87
|
+
);
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
it('should handle representations with additional properties', () => {
|
|
91
|
+
const representations = [
|
|
92
|
+
{
|
|
93
|
+
segmentationRepresentationUID: 'representation-1',
|
|
94
|
+
type: 'LABELMAP',
|
|
95
|
+
active: true,
|
|
96
|
+
},
|
|
97
|
+
{
|
|
98
|
+
segmentationRepresentationUID: 'representation-2',
|
|
99
|
+
type: 'CONTOUR',
|
|
100
|
+
active: false,
|
|
101
|
+
visible: true,
|
|
102
|
+
},
|
|
103
|
+
];
|
|
104
|
+
|
|
105
|
+
(segmentation.state.getSegmentationRepresentations as jest.Mock).mockReturnValue(
|
|
106
|
+
representations
|
|
107
|
+
);
|
|
108
|
+
|
|
109
|
+
removeViewportSegmentationRepresentations(viewportId);
|
|
110
|
+
|
|
111
|
+
expect(segmentation.state.removeSegmentationRepresentation).toHaveBeenCalledTimes(2);
|
|
112
|
+
expect(segmentation.state.removeSegmentationRepresentation).toHaveBeenNthCalledWith(
|
|
113
|
+
1,
|
|
114
|
+
'representation-1'
|
|
115
|
+
);
|
|
116
|
+
expect(segmentation.state.removeSegmentationRepresentation).toHaveBeenNthCalledWith(
|
|
117
|
+
2,
|
|
118
|
+
'representation-2'
|
|
119
|
+
);
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
it('should handle undefined representations', () => {
|
|
123
|
+
(segmentation.state.getSegmentationRepresentations as jest.Mock).mockReturnValue(undefined);
|
|
124
|
+
|
|
125
|
+
removeViewportSegmentationRepresentations(viewportId);
|
|
126
|
+
|
|
127
|
+
expect(segmentation.state.removeSegmentationRepresentation).not.toHaveBeenCalled();
|
|
128
|
+
});
|
|
129
|
+
});
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { segmentation } from '@cornerstonejs/tools';
|
|
2
|
+
|
|
3
|
+
function removeViewportSegmentationRepresentations(viewportId) {
|
|
4
|
+
const representations = segmentation.state.getSegmentationRepresentations(viewportId);
|
|
5
|
+
|
|
6
|
+
if (!representations || !representations.length) {
|
|
7
|
+
return;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
representations.forEach(representation => {
|
|
11
|
+
segmentation.state.removeSegmentationRepresentation(
|
|
12
|
+
representation.segmentationRepresentationUID
|
|
13
|
+
);
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export default removeViewportSegmentationRepresentations;
|
|
@@ -0,0 +1,515 @@
|
|
|
1
|
+
import { handleSegmentChange } from './segmentUtils';
|
|
2
|
+
|
|
3
|
+
describe('handleSegmentChange', () => {
|
|
4
|
+
const mockSegmentationService = {
|
|
5
|
+
getSegmentation: jest.fn(),
|
|
6
|
+
getActiveSegment: jest.fn(),
|
|
7
|
+
setActiveSegment: jest.fn(),
|
|
8
|
+
jumpToSegmentNext: jest.fn(),
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
const mockSegmentation = {
|
|
12
|
+
segments: {
|
|
13
|
+
'1': {
|
|
14
|
+
segmentIndex: 1,
|
|
15
|
+
label: 'Segment 1',
|
|
16
|
+
},
|
|
17
|
+
'2': {
|
|
18
|
+
segmentIndex: 2,
|
|
19
|
+
label: 'Segment 2',
|
|
20
|
+
},
|
|
21
|
+
'3': {
|
|
22
|
+
segmentIndex: 3,
|
|
23
|
+
label: 'Segment 3',
|
|
24
|
+
},
|
|
25
|
+
},
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
const defaultParameters = {
|
|
29
|
+
direction: 1,
|
|
30
|
+
segmentationId: 'test-segmentation-id',
|
|
31
|
+
viewportId: 'test-viewport-id',
|
|
32
|
+
selectedSegmentObjectIndex: 0,
|
|
33
|
+
// @ts-expect-error - only part of the SegmentationService is needed
|
|
34
|
+
segmentationService: mockSegmentationService as AppTypes.SegmentationService,
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
beforeEach(() => {
|
|
38
|
+
jest.clearAllMocks();
|
|
39
|
+
mockSegmentationService.getSegmentation.mockReturnValue(mockSegmentation);
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it('should move to next segment when direction is positive and activeSegment is null', () => {
|
|
43
|
+
const direction = 1;
|
|
44
|
+
mockSegmentationService.getActiveSegment.mockReturnValue(null);
|
|
45
|
+
|
|
46
|
+
handleSegmentChange({
|
|
47
|
+
...defaultParameters,
|
|
48
|
+
direction,
|
|
49
|
+
selectedSegmentObjectIndex: 0,
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
expect(mockSegmentationService.getSegmentation).toHaveBeenCalledWith(
|
|
53
|
+
defaultParameters.segmentationId
|
|
54
|
+
);
|
|
55
|
+
expect(mockSegmentationService.getActiveSegment).toHaveBeenCalledWith(
|
|
56
|
+
defaultParameters.viewportId
|
|
57
|
+
);
|
|
58
|
+
expect(mockSegmentationService.setActiveSegment).toHaveBeenCalledWith(
|
|
59
|
+
defaultParameters.segmentationId,
|
|
60
|
+
2
|
|
61
|
+
);
|
|
62
|
+
expect(mockSegmentationService.jumpToSegmentNext).toHaveBeenCalledWith(
|
|
63
|
+
defaultParameters.segmentationId,
|
|
64
|
+
2,
|
|
65
|
+
undefined,
|
|
66
|
+
direction
|
|
67
|
+
);
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
it('should move to previous segment when direction is negative and activeSegment is null', () => {
|
|
71
|
+
const direction = -1;
|
|
72
|
+
mockSegmentationService.getActiveSegment.mockReturnValue(null);
|
|
73
|
+
|
|
74
|
+
handleSegmentChange({
|
|
75
|
+
...defaultParameters,
|
|
76
|
+
direction,
|
|
77
|
+
selectedSegmentObjectIndex: 1,
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
expect(mockSegmentationService.setActiveSegment).toHaveBeenCalledWith(
|
|
81
|
+
defaultParameters.segmentationId,
|
|
82
|
+
1
|
|
83
|
+
);
|
|
84
|
+
expect(mockSegmentationService.jumpToSegmentNext).toHaveBeenCalledWith(
|
|
85
|
+
defaultParameters.segmentationId,
|
|
86
|
+
1,
|
|
87
|
+
undefined,
|
|
88
|
+
direction
|
|
89
|
+
);
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
it('should update selectedSegmentObjectIndex when activeSegment is found', () => {
|
|
93
|
+
const direction = 1;
|
|
94
|
+
const mockActiveSegment = {
|
|
95
|
+
segmentIndex: 2,
|
|
96
|
+
};
|
|
97
|
+
mockSegmentationService.getActiveSegment.mockReturnValue(mockActiveSegment);
|
|
98
|
+
|
|
99
|
+
handleSegmentChange({
|
|
100
|
+
...defaultParameters,
|
|
101
|
+
direction,
|
|
102
|
+
selectedSegmentObjectIndex: 0,
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
expect(mockSegmentationService.setActiveSegment).toHaveBeenCalledWith(
|
|
106
|
+
defaultParameters.segmentationId,
|
|
107
|
+
3
|
|
108
|
+
);
|
|
109
|
+
expect(mockSegmentationService.jumpToSegmentNext).toHaveBeenCalledWith(
|
|
110
|
+
defaultParameters.segmentationId,
|
|
111
|
+
3,
|
|
112
|
+
undefined,
|
|
113
|
+
direction
|
|
114
|
+
);
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
it('should loop to first segment when going beyond last segment', () => {
|
|
118
|
+
const direction = 1;
|
|
119
|
+
mockSegmentationService.getActiveSegment.mockReturnValue(null);
|
|
120
|
+
|
|
121
|
+
handleSegmentChange({
|
|
122
|
+
...defaultParameters,
|
|
123
|
+
direction,
|
|
124
|
+
selectedSegmentObjectIndex: 2,
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
expect(mockSegmentationService.setActiveSegment).toHaveBeenCalledWith(
|
|
128
|
+
defaultParameters.segmentationId,
|
|
129
|
+
1
|
|
130
|
+
);
|
|
131
|
+
expect(mockSegmentationService.jumpToSegmentNext).toHaveBeenCalledWith(
|
|
132
|
+
defaultParameters.segmentationId,
|
|
133
|
+
1,
|
|
134
|
+
undefined,
|
|
135
|
+
direction
|
|
136
|
+
);
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
it('should loop to last segment when going before first segment', () => {
|
|
140
|
+
const direction = -1;
|
|
141
|
+
mockSegmentationService.getActiveSegment.mockReturnValue(null);
|
|
142
|
+
|
|
143
|
+
handleSegmentChange({
|
|
144
|
+
...defaultParameters,
|
|
145
|
+
direction,
|
|
146
|
+
selectedSegmentObjectIndex: 0,
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
expect(mockSegmentationService.setActiveSegment).toHaveBeenCalledWith(
|
|
150
|
+
defaultParameters.segmentationId,
|
|
151
|
+
3
|
|
152
|
+
);
|
|
153
|
+
expect(mockSegmentationService.jumpToSegmentNext).toHaveBeenCalledWith(
|
|
154
|
+
defaultParameters.segmentationId,
|
|
155
|
+
3,
|
|
156
|
+
undefined,
|
|
157
|
+
direction
|
|
158
|
+
);
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
it('should handle direction with value greater than 1', () => {
|
|
162
|
+
const direction = 2;
|
|
163
|
+
mockSegmentationService.getActiveSegment.mockReturnValue(null);
|
|
164
|
+
|
|
165
|
+
handleSegmentChange({
|
|
166
|
+
...defaultParameters,
|
|
167
|
+
direction,
|
|
168
|
+
selectedSegmentObjectIndex: 0,
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
expect(mockSegmentationService.setActiveSegment).toHaveBeenCalledWith(
|
|
172
|
+
defaultParameters.segmentationId,
|
|
173
|
+
3
|
|
174
|
+
);
|
|
175
|
+
expect(mockSegmentationService.jumpToSegmentNext).toHaveBeenCalledWith(
|
|
176
|
+
defaultParameters.segmentationId,
|
|
177
|
+
3,
|
|
178
|
+
undefined,
|
|
179
|
+
direction
|
|
180
|
+
);
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
it('should handle direction with value less than -1', () => {
|
|
184
|
+
const direction = -2;
|
|
185
|
+
mockSegmentationService.getActiveSegment.mockReturnValue(null);
|
|
186
|
+
|
|
187
|
+
handleSegmentChange({
|
|
188
|
+
...defaultParameters,
|
|
189
|
+
direction,
|
|
190
|
+
selectedSegmentObjectIndex: 1,
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
expect(mockSegmentationService.setActiveSegment).toHaveBeenCalledWith(
|
|
194
|
+
defaultParameters.segmentationId,
|
|
195
|
+
3
|
|
196
|
+
);
|
|
197
|
+
expect(mockSegmentationService.jumpToSegmentNext).toHaveBeenCalledWith(
|
|
198
|
+
defaultParameters.segmentationId,
|
|
199
|
+
3,
|
|
200
|
+
undefined,
|
|
201
|
+
direction
|
|
202
|
+
);
|
|
203
|
+
});
|
|
204
|
+
|
|
205
|
+
it('should handle single segment scenario with positive direction', () => {
|
|
206
|
+
const direction = 1;
|
|
207
|
+
const singleSegmentSegmentation = {
|
|
208
|
+
segments: {
|
|
209
|
+
'1': {
|
|
210
|
+
segmentIndex: 1,
|
|
211
|
+
label: 'Only Segment',
|
|
212
|
+
},
|
|
213
|
+
},
|
|
214
|
+
};
|
|
215
|
+
|
|
216
|
+
mockSegmentationService.getSegmentation.mockReturnValue(singleSegmentSegmentation);
|
|
217
|
+
mockSegmentationService.getActiveSegment.mockReturnValue(null);
|
|
218
|
+
|
|
219
|
+
handleSegmentChange({
|
|
220
|
+
...defaultParameters,
|
|
221
|
+
direction,
|
|
222
|
+
selectedSegmentObjectIndex: 0,
|
|
223
|
+
});
|
|
224
|
+
|
|
225
|
+
expect(mockSegmentationService.setActiveSegment).toHaveBeenCalledWith(
|
|
226
|
+
defaultParameters.segmentationId,
|
|
227
|
+
1
|
|
228
|
+
);
|
|
229
|
+
expect(mockSegmentationService.jumpToSegmentNext).toHaveBeenCalledWith(
|
|
230
|
+
defaultParameters.segmentationId,
|
|
231
|
+
1,
|
|
232
|
+
undefined,
|
|
233
|
+
direction
|
|
234
|
+
);
|
|
235
|
+
});
|
|
236
|
+
|
|
237
|
+
it('should handle single segment scenario with negative direction', () => {
|
|
238
|
+
const direction = -1;
|
|
239
|
+
const singleSegmentSegmentation = {
|
|
240
|
+
segments: {
|
|
241
|
+
'1': {
|
|
242
|
+
segmentIndex: 1,
|
|
243
|
+
label: 'Only Segment',
|
|
244
|
+
},
|
|
245
|
+
},
|
|
246
|
+
};
|
|
247
|
+
|
|
248
|
+
mockSegmentationService.getSegmentation.mockReturnValue(singleSegmentSegmentation);
|
|
249
|
+
mockSegmentationService.getActiveSegment.mockReturnValue(null);
|
|
250
|
+
|
|
251
|
+
handleSegmentChange({
|
|
252
|
+
...defaultParameters,
|
|
253
|
+
direction,
|
|
254
|
+
selectedSegmentObjectIndex: 0,
|
|
255
|
+
});
|
|
256
|
+
|
|
257
|
+
expect(mockSegmentationService.setActiveSegment).toHaveBeenCalledWith(
|
|
258
|
+
defaultParameters.segmentationId,
|
|
259
|
+
1
|
|
260
|
+
);
|
|
261
|
+
expect(mockSegmentationService.jumpToSegmentNext).toHaveBeenCalledWith(
|
|
262
|
+
defaultParameters.segmentationId,
|
|
263
|
+
1,
|
|
264
|
+
undefined,
|
|
265
|
+
direction
|
|
266
|
+
);
|
|
267
|
+
});
|
|
268
|
+
|
|
269
|
+
it('should handle activeSegment not found in segments', () => {
|
|
270
|
+
const direction = 1;
|
|
271
|
+
const mockActiveSegment = {
|
|
272
|
+
segmentIndex: 99,
|
|
273
|
+
};
|
|
274
|
+
mockSegmentationService.getActiveSegment.mockReturnValue(mockActiveSegment);
|
|
275
|
+
|
|
276
|
+
handleSegmentChange({
|
|
277
|
+
...defaultParameters,
|
|
278
|
+
direction,
|
|
279
|
+
selectedSegmentObjectIndex: 0,
|
|
280
|
+
});
|
|
281
|
+
|
|
282
|
+
expect(mockSegmentationService.setActiveSegment).toHaveBeenCalledWith(
|
|
283
|
+
defaultParameters.segmentationId,
|
|
284
|
+
1
|
|
285
|
+
);
|
|
286
|
+
expect(mockSegmentationService.jumpToSegmentNext).toHaveBeenCalledWith(
|
|
287
|
+
defaultParameters.segmentationId,
|
|
288
|
+
1,
|
|
289
|
+
undefined,
|
|
290
|
+
direction
|
|
291
|
+
);
|
|
292
|
+
});
|
|
293
|
+
|
|
294
|
+
it('should handle zero direction', () => {
|
|
295
|
+
const direction = 0;
|
|
296
|
+
mockSegmentationService.getActiveSegment.mockReturnValue(null);
|
|
297
|
+
|
|
298
|
+
handleSegmentChange({
|
|
299
|
+
...defaultParameters,
|
|
300
|
+
direction,
|
|
301
|
+
selectedSegmentObjectIndex: 1,
|
|
302
|
+
});
|
|
303
|
+
|
|
304
|
+
expect(mockSegmentationService.setActiveSegment).toHaveBeenCalledWith(
|
|
305
|
+
defaultParameters.segmentationId,
|
|
306
|
+
2
|
|
307
|
+
);
|
|
308
|
+
expect(mockSegmentationService.jumpToSegmentNext).toHaveBeenCalledWith(
|
|
309
|
+
defaultParameters.segmentationId,
|
|
310
|
+
2,
|
|
311
|
+
undefined,
|
|
312
|
+
direction
|
|
313
|
+
);
|
|
314
|
+
});
|
|
315
|
+
|
|
316
|
+
it('should handle segments with non-sequential indices', () => {
|
|
317
|
+
const direction = 1;
|
|
318
|
+
const nonSequentialSegmentation = {
|
|
319
|
+
segments: {
|
|
320
|
+
'5': {
|
|
321
|
+
segmentIndex: 5,
|
|
322
|
+
label: 'Segment 5',
|
|
323
|
+
},
|
|
324
|
+
'10': {
|
|
325
|
+
segmentIndex: 10,
|
|
326
|
+
label: 'Segment 10',
|
|
327
|
+
},
|
|
328
|
+
'15': {
|
|
329
|
+
segmentIndex: 15,
|
|
330
|
+
label: 'Segment 15',
|
|
331
|
+
},
|
|
332
|
+
},
|
|
333
|
+
};
|
|
334
|
+
|
|
335
|
+
mockSegmentationService.getSegmentation.mockReturnValue(nonSequentialSegmentation);
|
|
336
|
+
mockSegmentationService.getActiveSegment.mockReturnValue(null);
|
|
337
|
+
|
|
338
|
+
handleSegmentChange({
|
|
339
|
+
...defaultParameters,
|
|
340
|
+
direction,
|
|
341
|
+
selectedSegmentObjectIndex: 0,
|
|
342
|
+
});
|
|
343
|
+
|
|
344
|
+
expect(mockSegmentationService.setActiveSegment).toHaveBeenCalledWith(
|
|
345
|
+
defaultParameters.segmentationId,
|
|
346
|
+
10
|
|
347
|
+
);
|
|
348
|
+
expect(mockSegmentationService.jumpToSegmentNext).toHaveBeenCalledWith(
|
|
349
|
+
defaultParameters.segmentationId,
|
|
350
|
+
10,
|
|
351
|
+
undefined,
|
|
352
|
+
direction
|
|
353
|
+
);
|
|
354
|
+
});
|
|
355
|
+
|
|
356
|
+
it('should handle wrap around with non-sequential indices', () => {
|
|
357
|
+
const direction = 1;
|
|
358
|
+
const nonSequentialSegmentation = {
|
|
359
|
+
segments: {
|
|
360
|
+
'5': {
|
|
361
|
+
segmentIndex: 5,
|
|
362
|
+
label: 'Segment 5',
|
|
363
|
+
},
|
|
364
|
+
'10': {
|
|
365
|
+
segmentIndex: 10,
|
|
366
|
+
label: 'Segment 10',
|
|
367
|
+
},
|
|
368
|
+
},
|
|
369
|
+
};
|
|
370
|
+
|
|
371
|
+
mockSegmentationService.getSegmentation.mockReturnValue(nonSequentialSegmentation);
|
|
372
|
+
mockSegmentationService.getActiveSegment.mockReturnValue(null);
|
|
373
|
+
|
|
374
|
+
handleSegmentChange({
|
|
375
|
+
...defaultParameters,
|
|
376
|
+
direction,
|
|
377
|
+
selectedSegmentObjectIndex: 1,
|
|
378
|
+
});
|
|
379
|
+
|
|
380
|
+
expect(mockSegmentationService.setActiveSegment).toHaveBeenCalledWith(
|
|
381
|
+
defaultParameters.segmentationId,
|
|
382
|
+
5
|
|
383
|
+
);
|
|
384
|
+
expect(mockSegmentationService.jumpToSegmentNext).toHaveBeenCalledWith(
|
|
385
|
+
defaultParameters.segmentationId,
|
|
386
|
+
5,
|
|
387
|
+
undefined,
|
|
388
|
+
direction
|
|
389
|
+
);
|
|
390
|
+
});
|
|
391
|
+
|
|
392
|
+
it('should handle empty segments object', () => {
|
|
393
|
+
const direction = 1;
|
|
394
|
+
const emptySegmentation = {
|
|
395
|
+
segments: {},
|
|
396
|
+
};
|
|
397
|
+
|
|
398
|
+
mockSegmentationService.getSegmentation.mockReturnValue(emptySegmentation);
|
|
399
|
+
mockSegmentationService.getActiveSegment.mockReturnValue(null);
|
|
400
|
+
|
|
401
|
+
handleSegmentChange({
|
|
402
|
+
...defaultParameters,
|
|
403
|
+
direction,
|
|
404
|
+
selectedSegmentObjectIndex: 0,
|
|
405
|
+
});
|
|
406
|
+
|
|
407
|
+
expect(mockSegmentationService.setActiveSegment).toHaveBeenCalledWith(
|
|
408
|
+
defaultParameters.segmentationId,
|
|
409
|
+
undefined
|
|
410
|
+
);
|
|
411
|
+
expect(mockSegmentationService.jumpToSegmentNext).toHaveBeenCalledWith(
|
|
412
|
+
defaultParameters.segmentationId,
|
|
413
|
+
undefined,
|
|
414
|
+
undefined,
|
|
415
|
+
direction
|
|
416
|
+
);
|
|
417
|
+
});
|
|
418
|
+
|
|
419
|
+
it('should handle large positive direction that wraps multiple times', () => {
|
|
420
|
+
const direction = 5;
|
|
421
|
+
mockSegmentationService.getActiveSegment.mockReturnValue(null);
|
|
422
|
+
|
|
423
|
+
handleSegmentChange({
|
|
424
|
+
...defaultParameters,
|
|
425
|
+
direction,
|
|
426
|
+
selectedSegmentObjectIndex: 1,
|
|
427
|
+
});
|
|
428
|
+
|
|
429
|
+
expect(mockSegmentationService.setActiveSegment).toHaveBeenCalledWith(
|
|
430
|
+
defaultParameters.segmentationId,
|
|
431
|
+
1
|
|
432
|
+
);
|
|
433
|
+
expect(mockSegmentationService.jumpToSegmentNext).toHaveBeenCalledWith(
|
|
434
|
+
defaultParameters.segmentationId,
|
|
435
|
+
1,
|
|
436
|
+
undefined,
|
|
437
|
+
direction
|
|
438
|
+
);
|
|
439
|
+
});
|
|
440
|
+
|
|
441
|
+
it('should handle large negative direction that wraps multiple times', () => {
|
|
442
|
+
const direction = -5;
|
|
443
|
+
mockSegmentationService.getActiveSegment.mockReturnValue(null);
|
|
444
|
+
|
|
445
|
+
handleSegmentChange({
|
|
446
|
+
...defaultParameters,
|
|
447
|
+
direction,
|
|
448
|
+
selectedSegmentObjectIndex: 1,
|
|
449
|
+
});
|
|
450
|
+
|
|
451
|
+
expect(mockSegmentationService.setActiveSegment).toHaveBeenCalledWith(
|
|
452
|
+
defaultParameters.segmentationId,
|
|
453
|
+
3
|
|
454
|
+
);
|
|
455
|
+
expect(mockSegmentationService.jumpToSegmentNext).toHaveBeenCalledWith(
|
|
456
|
+
defaultParameters.segmentationId,
|
|
457
|
+
3,
|
|
458
|
+
undefined,
|
|
459
|
+
direction
|
|
460
|
+
);
|
|
461
|
+
});
|
|
462
|
+
|
|
463
|
+
it('should handle activeSegment with segmentIndex 0', () => {
|
|
464
|
+
const direction = 1;
|
|
465
|
+
const mockActiveSegment = {
|
|
466
|
+
segmentIndex: 0,
|
|
467
|
+
};
|
|
468
|
+
mockSegmentationService.getActiveSegment.mockReturnValue(mockActiveSegment);
|
|
469
|
+
|
|
470
|
+
handleSegmentChange({
|
|
471
|
+
...defaultParameters,
|
|
472
|
+
direction,
|
|
473
|
+
selectedSegmentObjectIndex: 0,
|
|
474
|
+
});
|
|
475
|
+
|
|
476
|
+
expect(mockSegmentationService.setActiveSegment).toHaveBeenCalledWith(
|
|
477
|
+
defaultParameters.segmentationId,
|
|
478
|
+
1
|
|
479
|
+
);
|
|
480
|
+
expect(mockSegmentationService.jumpToSegmentNext).toHaveBeenCalledWith(
|
|
481
|
+
defaultParameters.segmentationId,
|
|
482
|
+
1,
|
|
483
|
+
undefined,
|
|
484
|
+
direction
|
|
485
|
+
);
|
|
486
|
+
});
|
|
487
|
+
|
|
488
|
+
it('should use different viewport and segmentation IDs', () => {
|
|
489
|
+
const direction = 1;
|
|
490
|
+
mockSegmentationService.getActiveSegment.mockReturnValue(null);
|
|
491
|
+
|
|
492
|
+
handleSegmentChange({
|
|
493
|
+
...defaultParameters,
|
|
494
|
+
segmentationId: 'different-segmentation-id',
|
|
495
|
+
viewportId: 'different-viewport-id',
|
|
496
|
+
direction,
|
|
497
|
+
selectedSegmentObjectIndex: 0,
|
|
498
|
+
});
|
|
499
|
+
|
|
500
|
+
expect(mockSegmentationService.getSegmentation).toHaveBeenCalledWith(
|
|
501
|
+
'different-segmentation-id'
|
|
502
|
+
);
|
|
503
|
+
expect(mockSegmentationService.getActiveSegment).toHaveBeenCalledWith('different-viewport-id');
|
|
504
|
+
expect(mockSegmentationService.setActiveSegment).toHaveBeenCalledWith(
|
|
505
|
+
'different-segmentation-id',
|
|
506
|
+
2
|
|
507
|
+
);
|
|
508
|
+
expect(mockSegmentationService.jumpToSegmentNext).toHaveBeenCalledWith(
|
|
509
|
+
'different-segmentation-id',
|
|
510
|
+
2,
|
|
511
|
+
undefined,
|
|
512
|
+
direction
|
|
513
|
+
);
|
|
514
|
+
});
|
|
515
|
+
});
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import SegmentationServiceType from '../services/SegmentationService';
|
|
2
|
+
|
|
3
|
+
export const handleSegmentChange = ({
|
|
4
|
+
direction,
|
|
5
|
+
segmentationId,
|
|
6
|
+
viewportId,
|
|
7
|
+
selectedSegmentObjectIndex,
|
|
8
|
+
segmentationService,
|
|
9
|
+
}: {
|
|
10
|
+
direction: number;
|
|
11
|
+
segmentationId: string;
|
|
12
|
+
viewportId: string;
|
|
13
|
+
selectedSegmentObjectIndex: number;
|
|
14
|
+
segmentationService: SegmentationServiceType;
|
|
15
|
+
}) => {
|
|
16
|
+
const segmentation = segmentationService.getSegmentation(segmentationId);
|
|
17
|
+
|
|
18
|
+
const { segments } = segmentation;
|
|
19
|
+
|
|
20
|
+
const numberOfSegments = Object.keys(segments).length;
|
|
21
|
+
|
|
22
|
+
// Get activeSegment each time because the user can select any segment from the list and thus the index should be updated
|
|
23
|
+
const activeSegment = segmentationService.getActiveSegment(viewportId);
|
|
24
|
+
if (activeSegment) {
|
|
25
|
+
// from the activeSegment get the actual object array index to be used
|
|
26
|
+
selectedSegmentObjectIndex = Object.values(segments).findIndex(
|
|
27
|
+
segment => segment.segmentIndex === activeSegment.segmentIndex
|
|
28
|
+
);
|
|
29
|
+
}
|
|
30
|
+
let newSelectedSegmentIndex = selectedSegmentObjectIndex + direction;
|
|
31
|
+
|
|
32
|
+
// Handle looping through list of segments
|
|
33
|
+
if (newSelectedSegmentIndex > numberOfSegments - 1) {
|
|
34
|
+
newSelectedSegmentIndex = 0;
|
|
35
|
+
} else if (newSelectedSegmentIndex < 0) {
|
|
36
|
+
newSelectedSegmentIndex = numberOfSegments - 1;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// Convert segmentationId from object array index to property value of type Segment
|
|
40
|
+
// Functions below use the segmentIndex object attribute so we have to do the conversion
|
|
41
|
+
const segmentIndex = Object.values(segments)[newSelectedSegmentIndex]?.segmentIndex;
|
|
42
|
+
|
|
43
|
+
segmentationService.setActiveSegment(segmentationId, segmentIndex);
|
|
44
|
+
segmentationService.jumpToSegmentNext(segmentationId, segmentIndex, undefined, direction);
|
|
45
|
+
selectedSegmentObjectIndex = newSelectedSegmentIndex;
|
|
46
|
+
};
|