Skip to content

Commit

Permalink
Increase test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
edkaya committed Oct 14, 2024
1 parent 4251db5 commit bc137e7
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,13 @@ <h3 class="fw-medium mb-0" jhiTranslate="artemisApp.course.archive.title"></h3>
<div class="module-bg py-3 rounded-3">
@if (courses.length) {
<div class="mb-0">
@for (semester of semesters; track semester; let last = $last) {
@for (semester of semesters; track semester; let last = $last; let i = $index) {
<div
class="d-flex justify-content-between align-items-center px-3"
(click)="isCourseFoundInSemester(semester) && toggleCollapseState(semester)"
tabindex="0"
role="button"
id="semester-group-{{ i }}"
[ngClass]="{ 'text-secondary': !(coursesBySemester[semester] | searchFilter: ['title'] : searchCourseText).length }"
>
<span class="fw-bold" jhiTranslate="{{ fullFormOfSemesterStrings[semester] }}" [translateValues]="{ param: semester.slice(2) }"></span>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,5 +228,50 @@ describe('CourseArchiveComponent', () => {
expect(iconComponent).not.toBeNull();
expect(iconComponent.icon).toBe(component.faArrowUp19);
}));

it('should find the correct course and call toggle', fakeAsync(() => {
const getCoursesForArchiveSpy = jest.spyOn(courseService, 'getCoursesForArchive');
getCoursesForArchiveSpy.mockReturnValue(of(new HttpResponse({ body: courses, headers: new HttpHeaders() })));
const mapCoursesIntoSemestersSpy = jest.spyOn(component, 'mapCoursesIntoSemesters');

component.ngOnInit();
tick();
fixture.detectChanges();
expect(component.courses).toHaveLength(7);
expect(getCoursesForArchiveSpy).toHaveBeenCalledOnce();
expect(mapCoursesIntoSemestersSpy).toHaveBeenCalledOnce();

// iPraktikum is in semester-group-3 : WS21/22
const button = fixture.debugElement.nativeElement.querySelector('#semester-group-3');
const toggleCollapseStateSpy = jest.spyOn(component, 'toggleCollapseState');
component.setSearchValue('iPraktikum');
const courseFound = component.isCourseFoundInSemester('WS21/22');
expect(courseFound).toBeTrue();
expect(button).not.toBeNull();
button.click();
expect(toggleCollapseStateSpy).toHaveBeenCalledOnce();
}));

it('should initialize collapse state correctly', () => {
const getCoursesForArchiveSpy = jest.spyOn(courseService, 'getCoursesForArchive');
getCoursesForArchiveSpy.mockReturnValue(of(new HttpResponse({ body: courses, headers: new HttpHeaders() })));
const mapCoursesIntoSemestersSpy = jest.spyOn(component, 'mapCoursesIntoSemesters');

component.ngOnInit();
expect(component.courses).toHaveLength(7);
expect(getCoursesForArchiveSpy).toHaveBeenCalledOnce();
expect(mapCoursesIntoSemestersSpy).toHaveBeenCalledOnce();
const getCollapseStateForSemestersSpy = jest.spyOn(component, 'getCollapseStateForSemesters');
component.setSearchValue('');
expect(getCollapseStateForSemestersSpy).toHaveBeenCalledOnce();

expect(component.semesterCollapsed).toStrictEqual({
'WS23/24': false,
'WS22/23': false,
SS22: false,
'WS21/22': false,
SS19: false,
});
});
});
});

0 comments on commit bc137e7

Please sign in to comment.