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,
|
type: representations[0].type,
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(service.getSegmentationRepresentations).toHaveBeenCalledTimes(2);
|
expect(service.getSegmentationRepresentations).toHaveBeenCalledTimes(1);
|
||||||
expect(service.getSegmentationRepresentations).toHaveBeenCalledWith(viewportId, {
|
expect(service.getSegmentationRepresentations).toHaveBeenCalledWith(viewportId, {
|
||||||
segmentationId: representations[0].segmentationId,
|
segmentationId: representations[0].segmentationId,
|
||||||
type: representations[0].type,
|
type: representations[0].type,
|
||||||
@ -2511,20 +2511,20 @@ describe('SegmentationService', () => {
|
|||||||
false
|
false
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('setSegmentationRepresentationVisibility', () => {
|
||||||
it('should early return if the representation is not found', () => {
|
it('should early return if the representation is not found', () => {
|
||||||
jest.spyOn(service, 'getSegmentationRepresentations').mockReturnValueOnce(representations);
|
jest.spyOn(service, 'getSegmentationRepresentations').mockReturnValueOnce([]);
|
||||||
jest.spyOn(cstSegmentation.state, 'getSegmentationRepresentations').mockReturnValueOnce([]);
|
|
||||||
jest
|
|
||||||
.spyOn(cstSegmentation.config.visibility, 'getHiddenSegmentIndices')
|
|
||||||
.mockReturnValue(new Set());
|
|
||||||
jest.spyOn(console, 'debug').mockReturnValue(undefined);
|
jest.spyOn(console, 'debug').mockReturnValue(undefined);
|
||||||
jest.spyOn(cstSegmentation.config.visibility, 'setSegmentationRepresentationVisibility');
|
jest.spyOn(cstSegmentation.config.visibility, 'setSegmentationRepresentationVisibility');
|
||||||
|
|
||||||
service.toggleSegmentationRepresentationVisibility(viewportId, {
|
service['_setSegmentationRepresentationVisibility'](
|
||||||
segmentationId: representations[0].segmentationId,
|
viewportId,
|
||||||
type: representations[0].type,
|
representations[0].segmentationId,
|
||||||
});
|
representations[0].type,
|
||||||
|
true
|
||||||
|
);
|
||||||
|
|
||||||
expect(console.debug).toHaveBeenCalledTimes(1);
|
expect(console.debug).toHaveBeenCalledTimes(1);
|
||||||
expect(console.debug).toHaveBeenCalledWith(
|
expect(console.debug).toHaveBeenCalledWith(
|
||||||
|
|||||||
@ -1756,22 +1756,16 @@ class SegmentationService extends PubSubService {
|
|||||||
segmentationId: string,
|
segmentationId: string,
|
||||||
type: csToolsEnums.SegmentationRepresentations
|
type: csToolsEnums.SegmentationRepresentations
|
||||||
): void => {
|
): void => {
|
||||||
const representations = this.getSegmentationRepresentations(viewportId, {
|
|
||||||
segmentationId,
|
|
||||||
type,
|
|
||||||
});
|
|
||||||
const representation = representations[0];
|
|
||||||
|
|
||||||
const segmentsHidden = cstSegmentation.config.visibility.getHiddenSegmentIndices(viewportId, {
|
const segmentsHidden = cstSegmentation.config.visibility.getHiddenSegmentIndices(viewportId, {
|
||||||
segmentationId,
|
segmentationId,
|
||||||
type: representation.type,
|
type,
|
||||||
});
|
});
|
||||||
|
|
||||||
const currentVisibility = segmentsHidden.size === 0;
|
const currentVisibility = segmentsHidden.size === 0;
|
||||||
this._setSegmentationRepresentationVisibility(
|
this._setSegmentationRepresentationVisibility(
|
||||||
viewportId,
|
viewportId,
|
||||||
segmentationId,
|
segmentationId,
|
||||||
representation.type,
|
type,
|
||||||
!currentVisibility
|
!currentVisibility
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user