Skip to content

Commit

Permalink
Add client test
Browse files Browse the repository at this point in the history
  • Loading branch information
Hialus committed Oct 13, 2024
1 parent 171b684 commit 9a2dc2c
Showing 1 changed file with 38 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ import { IrisSettingsType } from 'app/entities/iris/settings/iris-settings.model
import { ArtemisTranslatePipe } from 'app/shared/pipes/artemis-translate.pipe';
import { IrisSettingsService } from 'app/iris/settings/shared/iris-settings.service';
import { of } from 'rxjs';
import { ExerciseCategory } from 'app/entities/exercise-category.model';
import { CourseManagementService } from 'app/course/manage/course-management.service';
import { HttpResponse } from '@angular/common/http';

function baseSettings() {
const irisSubSettings = new IrisChatSubSettings();
Expand All @@ -23,10 +26,20 @@ function baseSettings() {
return irisSubSettings;
}

function mockCategories() {
return [
// Convert ExerciseCategory to json string
JSON.stringify(new ExerciseCategory('category1', '0xff0000')),
JSON.stringify(new ExerciseCategory('category2', '0x00ff00')),
JSON.stringify(new ExerciseCategory('category3', '0x0000ff')),
];
}

describe('IrisCommonSubSettingsUpdateComponent Component', () => {
let comp: IrisCommonSubSettingsUpdateComponent;
let fixture: ComponentFixture<IrisCommonSubSettingsUpdateComponent>;
let getVariantsSpy: jest.SpyInstance;
let getCategoriesSpy: jest.SpyInstance;

beforeEach(() => {
TestBed.configureTestingModule({
Expand All @@ -36,7 +49,9 @@ describe('IrisCommonSubSettingsUpdateComponent Component', () => {
.compileComponents()
.then(() => {
const irisSettingsService = TestBed.inject(IrisSettingsService);
const courseManagementService = TestBed.inject(CourseManagementService);
getVariantsSpy = jest.spyOn(irisSettingsService, 'getVariantsForFeature').mockReturnValue(of(mockVariants()));
getCategoriesSpy = jest.spyOn(courseManagementService, 'findAllCategoriesOfCourse').mockReturnValue(of(new HttpResponse({ body: mockCategories() })));
});
fixture = TestBed.createComponent(IrisCommonSubSettingsUpdateComponent);
comp = fixture.componentInstance;
Expand Down Expand Up @@ -181,4 +196,27 @@ describe('IrisCommonSubSettingsUpdateComponent Component', () => {
expect(comp.enabled).toBeFalse();
expect(comp.allowedVariants).toEqual(newModels);
});

it('enable categories', () => {
comp.subSettings = baseSettings();
comp.parentSubSettings = baseSettings();
comp.parentSubSettings.enabled = false;
comp.isAdmin = true;
comp.settingsType = IrisSettingsType.COURSE;
comp.availableVariants = mockVariants();
fixture.detectChanges();

expect(getCategoriesSpy).toHaveBeenCalledOnce();

comp.onCategorySelectionChange('category1');
expect(comp.subSettings!.enabledForCategories).toEqual(['category1']);
comp.onCategorySelectionChange('category2');
expect(comp.subSettings!.enabledForCategories).toEqual(['category1', 'category2']);
comp.onCategorySelectionChange('category1');
expect(comp.subSettings!.enabledForCategories).toEqual(['category2']);

comp.subSettings = undefined;
comp.onCategorySelectionChange('category1');
expect(comp.subSettings).toBeUndefined();
});
});

0 comments on commit 9a2dc2c

Please sign in to comment.