fix(segmentationService): prevent no representation crash (#5495)
This commit is contained in:
parent
a1c6b5f3ec
commit
3137aed017
@ -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(
|
||||
|
||||
@ -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
|
||||
);
|
||||
};
|
||||
|
||||
Loading…
Reference in New Issue
Block a user