Skip to content

Commit

Permalink
Add client test to increase coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
florian-glombik committed Oct 12, 2024
1 parent 366e927 commit 5fad596
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<ExerciseTitleChannelNameComponent>;
let exerciseService: ExerciseService;

beforeEach(async () => {
await TestBed.configureTestingModule({
Expand All @@ -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', () => {
Expand Down

0 comments on commit 5fad596

Please sign in to comment.