diff --git a/extensions/cornerstone/src/services/SegmentationService/SegmentationService.test.ts b/extensions/cornerstone/src/services/SegmentationService/SegmentationService.test.ts index 37643eb08..8800fb7c0 100644 --- a/extensions/cornerstone/src/services/SegmentationService/SegmentationService.test.ts +++ b/extensions/cornerstone/src/services/SegmentationService/SegmentationService.test.ts @@ -2482,7 +2482,7 @@ describe('SegmentationService', () => { type: representations[0].type, }); - expect(service.getSegmentationRepresentations).toHaveBeenCalledTimes(2); + expect(service.getSegmentationRepresentations).toHaveBeenCalledTimes(1); expect(service.getSegmentationRepresentations).toHaveBeenCalledWith(viewportId, { segmentationId: representations[0].segmentationId, type: representations[0].type, @@ -2511,20 +2511,20 @@ describe('SegmentationService', () => { false ); }); + }); + describe('setSegmentationRepresentationVisibility', () => { it('should early return if the representation is not found', () => { - jest.spyOn(service, 'getSegmentationRepresentations').mockReturnValueOnce(representations); - jest.spyOn(cstSegmentation.state, 'getSegmentationRepresentations').mockReturnValueOnce([]); - jest - .spyOn(cstSegmentation.config.visibility, 'getHiddenSegmentIndices') - .mockReturnValue(new Set()); + jest.spyOn(service, 'getSegmentationRepresentations').mockReturnValueOnce([]); jest.spyOn(console, 'debug').mockReturnValue(undefined); jest.spyOn(cstSegmentation.config.visibility, 'setSegmentationRepresentationVisibility'); - service.toggleSegmentationRepresentationVisibility(viewportId, { - segmentationId: representations[0].segmentationId, - type: representations[0].type, - }); + service['_setSegmentationRepresentationVisibility']( + viewportId, + representations[0].segmentationId, + representations[0].type, + true + ); expect(console.debug).toHaveBeenCalledTimes(1); expect(console.debug).toHaveBeenCalledWith( diff --git a/extensions/cornerstone/src/services/SegmentationService/SegmentationService.ts b/extensions/cornerstone/src/services/SegmentationService/SegmentationService.ts index cfd09a09d..d51a9c008 100644 --- a/extensions/cornerstone/src/services/SegmentationService/SegmentationService.ts +++ b/extensions/cornerstone/src/services/SegmentationService/SegmentationService.ts @@ -1756,22 +1756,16 @@ class SegmentationService extends PubSubService { segmentationId: string, type: csToolsEnums.SegmentationRepresentations ): void => { - const representations = this.getSegmentationRepresentations(viewportId, { - segmentationId, - type, - }); - const representation = representations[0]; - const segmentsHidden = cstSegmentation.config.visibility.getHiddenSegmentIndices(viewportId, { segmentationId, - type: representation.type, + type, }); const currentVisibility = segmentsHidden.size === 0; this._setSegmentationRepresentationVisibility( viewportId, segmentationId, - representation.type, + type, !currentVisibility ); };