diff --git a/src/app/services/annotationService.spec.ts b/src/app/services/annotationService.spec.ts index 4ced47474f6..791ae80c8e0 100644 --- a/src/app/services/annotationService.spec.ts +++ b/src/app/services/annotationService.spec.ts @@ -66,7 +66,7 @@ function getLatestScoreAnnotation() { function getLatestScoreAnnotation_NoMatch_ReturnNull() { describe('no matching annotation is found', () => { it('returns null', () => { - expect(service.getLatestScoreAnnotation('nodeX', 'componentX', 10, 'any')).toBeUndefined(); + expect(service.getLatestScoreAnnotation('nodeX', 'componentX', 10, 'any')).toBeNull(); }); }); } diff --git a/src/assets/wise5/services/annotationService.ts b/src/assets/wise5/services/annotationService.ts index 6030ee93536..d14691f6b0b 100644 --- a/src/assets/wise5/services/annotationService.ts +++ b/src/assets/wise5/services/annotationService.ts @@ -536,15 +536,17 @@ export class AnnotationService { workgroupId: number, scoreType: 'score' | 'autoScore' | 'any' = 'any' ): Annotation { - return this.getAnnotations() - .filter( - (annotation) => - annotation.nodeId == nodeId && - annotation.componentId == componentId && - annotation.toWorkgroupId == workgroupId && - this.matchesScoreType(annotation, scoreType) - ) - .at(-1); + return ( + this.getAnnotations() + .filter( + (annotation) => + annotation.nodeId == nodeId && + annotation.componentId == componentId && + annotation.toWorkgroupId == workgroupId && + this.matchesScoreType(annotation, scoreType) + ) + .at(-1) || null + ); } private matchesScoreType( @@ -552,8 +554,8 @@ export class AnnotationService { scoreType: 'score' | 'autoScore' | 'any' ): boolean { return ( - ['autoScore', 'score'].includes(annotation.type) && - (scoreType === 'any' || annotation.type === scoreType) + (scoreType === 'any' && ['autoScore', 'score'].includes(annotation.type)) || + annotation.type === scoreType ); }