Skip to content

Commit

Permalink
Merge branch 'chore/update-angular19' of https://github.com/ls1intum/…
Browse files Browse the repository at this point in the history
…Artemis into chore/update-angular19
  • Loading branch information
LeonWehrhahn committed Jan 10, 2025
2 parents 1f86b95 + b2612c3 commit 620b821
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ describe('CompetencyFormComponent', () => {
})
.overrideModule(ArtemisMarkdownEditorModule, {
remove: { exports: [MarkdownEditorMonacoComponent] },
add: { exports: [MockComponent(MarkdownEditorMonacoComponent)], declarations: [MockComponent(MarkdownEditorMonacoComponent)] },
add: { exports: [MockComponent(MarkdownEditorMonacoComponent)], imports: [MockComponent(MarkdownEditorMonacoComponent)] },
})
.compileComponents()
.then(() => {
competencyFormComponentFixture = TestBed.createComponent(CompetencyFormComponent);
competencyFormComponent = competencyFormComponentFixture.componentInstance;
});
.compileComponents();

competencyFormComponentFixture = TestBed.createComponent(CompetencyFormComponent);
competencyFormComponent = competencyFormComponentFixture.componentInstance;

translateService = TestBed.inject(TranslateService);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,15 @@ describe('CourseCompetenciesRelationGraphComponent', () => {
let fixture: ComponentFixture<CourseCompetenciesRelationGraphComponent>;

const courseCompetencies: CourseCompetency[] = [
{ id: 1, type: CourseCompetencyType.COMPETENCY, title: 'Competency' },
{ id: 2, type: CourseCompetencyType.PREREQUISITE, title: 'Prerequisite' },
{ id: 1, type: CourseCompetencyType.COMPETENCY, title: 'Competency', dimension: { height: 45.59, width: 0 }, meta: { forceDimensions: false }, position: { x: 0, y: 0 } },

Check failure on line 13 in src/test/javascript/spec/component/competencies/components/course-competencies-relation-graph.component.spec.ts

View workflow job for this annotation

GitHub Actions / client-tests

Object literal may only specify known properties, and 'dimension' does not exist in type 'CourseCompetency'.

Check failure on line 13 in src/test/javascript/spec/component/competencies/components/course-competencies-relation-graph.component.spec.ts

View workflow job for this annotation

GitHub Actions / client-tests-selected

Object literal may only specify known properties, and 'dimension' does not exist in type 'CourseCompetency'.
{
id: 2,
type: CourseCompetencyType.PREREQUISITE,
title: 'Prerequisite',
dimension: { height: 45.59, width: 0 },

Check failure on line 18 in src/test/javascript/spec/component/competencies/components/course-competencies-relation-graph.component.spec.ts

View workflow job for this annotation

GitHub Actions / client-tests

Object literal may only specify known properties, and 'dimension' does not exist in type 'CourseCompetency'.

Check failure on line 18 in src/test/javascript/spec/component/competencies/components/course-competencies-relation-graph.component.spec.ts

View workflow job for this annotation

GitHub Actions / client-tests-selected

Object literal may only specify known properties, and 'dimension' does not exist in type 'CourseCompetency'.
meta: { forceDimensions: false },
position: { x: 0, y: 0 },
},
];

const relations: CompetencyRelationDTO[] = [
Expand Down Expand Up @@ -80,6 +87,9 @@ describe('CourseCompetenciesRelationGraphComponent', () => {
id: cc.id,
type: cc.type,
},
dimension: cc.dimension,

Check failure on line 90 in src/test/javascript/spec/component/competencies/components/course-competencies-relation-graph.component.spec.ts

View workflow job for this annotation

GitHub Actions / client-tests

Property 'dimension' does not exist on type 'CourseCompetency'.

Check failure on line 90 in src/test/javascript/spec/component/competencies/components/course-competencies-relation-graph.component.spec.ts

View workflow job for this annotation

GitHub Actions / client-tests-selected

Property 'dimension' does not exist on type 'CourseCompetency'.
meta: cc.meta,

Check failure on line 91 in src/test/javascript/spec/component/competencies/components/course-competencies-relation-graph.component.spec.ts

View workflow job for this annotation

GitHub Actions / client-tests

Property 'meta' does not exist on type 'CourseCompetency'.

Check failure on line 91 in src/test/javascript/spec/component/competencies/components/course-competencies-relation-graph.component.spec.ts

View workflow job for this annotation

GitHub Actions / client-tests-selected

Property 'meta' does not exist on type 'CourseCompetency'.
position: cc.position,

Check failure on line 92 in src/test/javascript/spec/component/competencies/components/course-competencies-relation-graph.component.spec.ts

View workflow job for this annotation

GitHub Actions / client-tests

Property 'position' does not exist on type 'CourseCompetency'.

Check failure on line 92 in src/test/javascript/spec/component/competencies/components/course-competencies-relation-graph.component.spec.ts

View workflow job for this annotation

GitHub Actions / client-tests-selected

Property 'position' does not exist on type 'CourseCompetency'.
};
}),
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -269,8 +269,7 @@ describe('ExerciseImportComponent', () => {
comp.exerciseType = exerciseType;

comp.ngOnInit();

expect(getSpy).toHaveBeenCalledExactlyOnceWith(expectedPagingService, undefined, 0); // default values for arguments 2 and 3
expect(getSpy).toHaveBeenCalledWith(expectedPagingService, {});
}),
);

Expand All @@ -285,7 +284,7 @@ describe('ExerciseImportComponent', () => {
comp.ngOnInit();

expect(comp.titleKey).toContain('configureGrading');
expect(getSpy).toHaveBeenCalledExactlyOnceWith(CodeAnalysisPagingService, undefined, 0);
expect(getSpy).toHaveBeenCalledWith(CodeAnalysisPagingService, {});
});

it('should sort by exam title when only the exam filter is active', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { TutorialGroup } from 'app/entities/tutorial-group/tutorial-group.model';
import { Course } from 'app/entities/course.model';
import { User } from 'app/core/user/user.model';
import { TutorialGroupFormData } from 'app/course/tutorial-groups/tutorial-groups-management/tutorial-groups/crud/tutorial-group-form/tutorial-group-form.component';
import { TutorialGroupFormData, UserWithLabel } from 'app/course/tutorial-groups/tutorial-groups-management/tutorial-groups/crud/tutorial-group-form/tutorial-group-form.component';
import dayjs from 'dayjs/esm';

export const generateExampleTutorialGroup = ({
Expand All @@ -12,7 +11,7 @@ export const generateExampleTutorialGroup = ({
language = 'ENGLISH',
additionalInformation = 'Example Additional Information',
isOnline = false,
teachingAssistant = { id: 1, login: 'Example TA' } as User,
teachingAssistant = { id: 1, login: 'Example TA', label: '(Example TA)' } as UserWithLabel,
isUserRegistered = false,
isUserTutor = false,
numberOfRegisteredUsers = 5,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { MockPipe, MockProvider } from 'ng-mocks';
import { MockProvider } from 'ng-mocks';
import { AlertService } from 'app/core/util/alert.service';
import { Router } from '@angular/router';
import { MockRouter } from '../../../../../helpers/mocks/mock-router';
import { of } from 'rxjs';
import { TutorialGroupsService } from 'app/course/tutorial-groups/services/tutorial-groups.service';
import { ArtemisTranslatePipe } from 'app/shared/pipes/artemis-translate.pipe';
import { HttpResponse } from '@angular/common/http';
import { TutorialGroup } from 'app/entities/tutorial-group/tutorial-group.model';
import { By } from '@angular/platform-browser';
import { EditTutorialGroupComponent } from 'app/course/tutorial-groups/tutorial-groups-management/tutorial-groups/crud/edit-tutorial-group/edit-tutorial-group.component';
import { TutorialGroupFormStubComponent } from '../../../stubs/tutorial-group-form-stub.component';
import { LoadingIndicatorContainerStubComponent } from '../../../../../helpers/stubs/loading-indicator-container-stub.component';
import { generateExampleTutorialGroup, tutorialGroupToTutorialGroupFormData } from '../../../helpers/tutorialGroupExampleModels';
import { mockedActivatedRoute } from '../../../../../helpers/mocks/activated-route/mock-activated-route-query-param-map';
import { ArtemisTestModule } from '../../../../../test.module';
import '@angular/localize/init';
import { OwlNativeDateTimeModule } from '@danielmoncada/angular-datetime-picker';
import { ArtemisDatePipe } from '../../../../../../../../main/webapp/app/shared/pipes/artemis-date.pipe';
import { MockResizeObserver } from '../../../../../helpers/mocks/service/mock-resize-observer';
import { TutorialGroupFormComponent } from '../../../../../../../../main/webapp/app/course/tutorial-groups/tutorial-groups-management/tutorial-groups/crud/tutorial-group-form/tutorial-group-form.component';

describe('EditTutorialGroupComponent', () => {
let fixture: ComponentFixture<EditTutorialGroupComponent>;
Expand All @@ -26,12 +29,11 @@ describe('EditTutorialGroupComponent', () => {

const router = new MockRouter();

beforeEach(() => {
TestBed.configureTestingModule({
imports: [],
declarations: [EditTutorialGroupComponent, LoadingIndicatorContainerStubComponent, TutorialGroupFormStubComponent, MockPipe(ArtemisTranslatePipe)],
beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [ArtemisTestModule, EditTutorialGroupComponent, OwlNativeDateTimeModule],
providers: [
MockProvider(TutorialGroupsService),
MockProvider(ArtemisDatePipe),
MockProvider(AlertService),
{ provide: Router, useValue: router },
mockedActivatedRoute(
Expand All @@ -43,23 +45,25 @@ describe('EditTutorialGroupComponent', () => {
{},
),
],
})
.compileComponents()
.then(() => {
fixture = TestBed.createComponent(EditTutorialGroupComponent);
component = fixture.componentInstance;
exampleTutorialGroup = generateExampleTutorialGroup({});

tutorialGroupService = TestBed.inject(TutorialGroupsService);

const response: HttpResponse<TutorialGroup> = new HttpResponse({
body: exampleTutorialGroup,
status: 200,
});

findTutorialGroupSpy = jest.spyOn(tutorialGroupService, 'getOneOfCourse').mockReturnValue(of(response));
fixture.detectChanges();
});
}).compileComponents();

fixture = TestBed.createComponent(EditTutorialGroupComponent);
component = fixture.componentInstance;
exampleTutorialGroup = generateExampleTutorialGroup({});

tutorialGroupService = TestBed.inject(TutorialGroupsService);

const response: HttpResponse<TutorialGroup> = new HttpResponse({
body: exampleTutorialGroup,
status: 200,
});

global.ResizeObserver = jest.fn().mockImplementation((callback: ResizeObserverCallback) => {
return new MockResizeObserver(callback);
});

findTutorialGroupSpy = jest.spyOn(tutorialGroupService, 'getOneOfCourse').mockReturnValue(of(response));
fixture.detectChanges();
});

afterEach(() => {
Expand All @@ -73,14 +77,14 @@ describe('EditTutorialGroupComponent', () => {
});

it('should set form data correctly', () => {
const tutorialGroupFormStubComponent: TutorialGroupFormStubComponent = fixture.debugElement.query(By.directive(TutorialGroupFormStubComponent)).componentInstance;
const tutorialGroupFormComponent: TutorialGroupFormComponent = fixture.debugElement.query(By.directive(TutorialGroupFormComponent)).componentInstance;

expect(component.tutorialGroup).toEqual(exampleTutorialGroup);
expect(findTutorialGroupSpy).toHaveBeenCalledWith(2, 1);
expect(findTutorialGroupSpy).toHaveBeenCalledOnce();

expect(component.formData).toEqual(tutorialGroupToTutorialGroupFormData(exampleTutorialGroup));
expect(tutorialGroupFormStubComponent.formData).toEqual(component.formData);
expect(tutorialGroupFormComponent.formData).toEqual(component.formData);
});

it('should send PUT request upon form submission and navigate', () => {
Expand All @@ -106,7 +110,7 @@ describe('EditTutorialGroupComponent', () => {
const updatedStub = jest.spyOn(tutorialGroupService, 'update').mockReturnValue(of(updateResponse));
const navigateSpy = jest.spyOn(router, 'navigate');

const tutorialGroupForm: TutorialGroupFormStubComponent = fixture.debugElement.query(By.directive(TutorialGroupFormStubComponent)).componentInstance;
const tutorialGroupForm: TutorialGroupFormComponent = fixture.debugElement.query(By.directive(TutorialGroupFormComponent)).componentInstance;

const formData = tutorialGroupToTutorialGroupFormData(changedTutorialGroup);

Expand Down

0 comments on commit 620b821

Please sign in to comment.