From 5fad59629f54814f21d82976c127f3fe0ed9724d Mon Sep 17 00:00:00 2001 From: Florian Glombik Date: Sat, 12 Oct 2024 23:47:35 +0200 Subject: [PATCH] Add client test to increase coverage --- .../title-channel-name.component.ts | 2 +- ...rcise-title-channel-name.component.spec.ts | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/main/webapp/app/shared/form/title-channel-name/title-channel-name.component.ts b/src/main/webapp/app/shared/form/title-channel-name/title-channel-name.component.ts index dedfc829fc7e..d5cfd1725591 100644 --- a/src/main/webapp/app/shared/form/title-channel-name/title-channel-name.component.ts +++ b/src/main/webapp/app/shared/form/title-channel-name/title-channel-name.component.ts @@ -67,7 +67,7 @@ export class TitleChannelNameComponent implements AfterViewInit, OnDestroy, OnIn } private registerChangeListeners() { - this.fieldTitleSubscription = this.field_title.valueChanges?.subscribe(() => this.calculateFormValid()); + this.fieldTitleSubscription = this.field_title?.valueChanges?.subscribe(() => this.calculateFormValid()); this.fieldChannelNameSubscription = this.field_channel_name()?.valueChanges?.subscribe(() => this.calculateFormValid()); } diff --git a/src/test/javascript/spec/component/exercises/shared/exercise-title-channel-name.component.spec.ts b/src/test/javascript/spec/component/exercises/shared/exercise-title-channel-name.component.spec.ts index 3a2781d07463..88e0618916b2 100644 --- a/src/test/javascript/spec/component/exercises/shared/exercise-title-channel-name.component.spec.ts +++ b/src/test/javascript/spec/component/exercises/shared/exercise-title-channel-name.component.spec.ts @@ -11,10 +11,13 @@ import { MockSyncStorage } from '../../../helpers/mocks/service/mock-sync-storag import { SessionStorageService } from 'ngx-webstorage'; import { MockHttpService } from '../../../helpers/mocks/service/mock-http.service'; import { HttpClient } from '@angular/common/http'; +import { ExerciseService } from '../../../../../../main/webapp/app/exercises/shared/exercise/exercise.service'; +import { ExerciseType } from '../../../../../../main/webapp/app/entities/exercise.model'; describe('ExerciseTitleChannelNameComponent', () => { let component: ExerciseTitleChannelNameComponent; let fixture: ComponentFixture; + let exerciseService: ExerciseService; beforeEach(async () => { await TestBed.configureTestingModule({ @@ -35,6 +38,22 @@ describe('ExerciseTitleChannelNameComponent', () => { fixture.componentRef.setInput('course', new Course()); fixture.componentRef.setInput('isEditFieldDisplayedRecord', true); component = fixture.componentInstance; + + exerciseService = TestBed.inject(ExerciseService); + }); + + it('should call getExistingExerciseDetailsInCourse on init', () => { + const courseId = 123; + const exerciseType = ExerciseType.PROGRAMMING; + component.exercise = new TextExercise(new Course(), undefined); + component.exercise.type = exerciseType; + component.exercise.course!.id = courseId; + + fixture.componentRef.setInput('courseId', courseId); + const exerciseServiceSpy = jest.spyOn(exerciseService, 'getExistingExerciseDetailsInCourse'); + fixture.detectChanges(); + + expect(exerciseServiceSpy).toHaveBeenCalledWith(courseId, exerciseType); }); it('should hide channel name input if messaging and communication disabled', () => {