Skip to content

Commit

Permalink
fix client test compile issues
Browse files Browse the repository at this point in the history
  • Loading branch information
krusche committed Dec 29, 2024
1 parent a223ccc commit 66cd503
Show file tree
Hide file tree
Showing 20 changed files with 87 additions and 74 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { CourseConversationsComponent } from 'app/overview/course-conversations/course-conversations.component';
import { ComponentFixture, TestBed, fakeAsync, tick, waitForAsync } from '@angular/core/testing';
import { ConversationDTO } from 'app/entities/metis/conversation/conversation.model';
import { OneToOneChatDTO } from '../../../../../../main/webapp/app/entities/metis/conversation/one-to-one-chat.model';
import { generateExampleChannelDTO, generateExampleGroupChatDTO, generateOneToOneChatDTO } from './helpers/conversationExampleModels';
import { MockComponent, MockPipe, MockProvider } from 'ng-mocks';
import { MetisConversationService } from 'app/shared/metis/metis-conversation.service';
Expand Down Expand Up @@ -44,7 +45,12 @@ import { LayoutService } from 'app/shared/breakpoints/layout.service';
import { CustomBreakpointNames } from 'app/shared/breakpoints/breakpoints.service';
import { Posting, PostingType, SavedPostStatus, SavedPostStatusMap } from 'app/entities/metis/posting.model';

const examples: (ConversationDTO | undefined)[] = [undefined, generateOneToOneChatDTO({}), generateExampleGroupChatDTO({}), generateExampleChannelDTO({})];
const examples: (ConversationDTO | undefined)[] = [
undefined,
generateOneToOneChatDTO({} as OneToOneChatDTO),
generateExampleGroupChatDTO({} as GroupChatDTO),
generateExampleChannelDTO({} as ChannelDTO),
];

examples.forEach((activeConversation) => {
describe('CourseConversationComponent with ' + (activeConversation?.type || 'no active conversation'), () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@ import { ChannelItemComponent } from 'app/overview/course-conversations/dialogs/
import { MockComponent, MockPipe } from 'ng-mocks';
import { ArtemisTranslatePipe } from 'app/shared/pipes/artemis-translate.pipe';
import { ChannelIconComponent } from 'app/overview/course-conversations/other/channel-icon/channel-icon.component';
import { ChannelDTO } from '../../../../../../../../../main/webapp/app/entities/metis/conversation/channel.model';
import { generateExampleChannelDTO } from '../../../helpers/conversationExampleModels';

describe('ChannelItemComponent', () => {
let component: ChannelItemComponent;
let fixture: ComponentFixture<ChannelItemComponent>;
const canJoinChannel = jest.fn();
const canLeaveConversation = jest.fn();
const channel = generateExampleChannelDTO({ id: 1 });
const channel = generateExampleChannelDTO({ id: 1 } as ChannelDTO);

beforeEach(waitForAsync(() => {
TestBed.configureTestingModule({ declarations: [ChannelItemComponent, MockPipe(ArtemisTranslatePipe), MockComponent(ChannelIconComponent)] }).compileComponents();
Expand Down Expand Up @@ -53,7 +54,7 @@ describe('ChannelItemComponent', () => {
expect(fixture.nativeElement.querySelector('#deregister' + channel.id)).toBeFalsy();

// change dto to one where not is member
component.channel = generateExampleChannelDTO({ id: 2, isMember: false });
component.channel = generateExampleChannelDTO({ id: 2, isMember: false } as ChannelDTO);
fixture.detectChanges();
expect(fixture.nativeElement.querySelector('#view' + channel.id)).toBeFalsy();
expect(fixture.nativeElement.querySelector('#register' + channel.id)).toBeFalsy();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,15 @@ import { NgbCollapseMocksModule } from '../../../../../helpers/mocks/directive/n
template: '',
})
class ChannelItemStubComponent {
@Output()
channelAction = new EventEmitter<ChannelAction>();
@Input()
channel: ChannelDTO;
@Output() channelAction = new EventEmitter<ChannelAction>();
@Input() channel: ChannelDTO;
}

const examples: ChannelDTO[] = [
generateExampleChannelDTO({}),
generateExampleChannelDTO({ subType: ChannelSubType.EXERCISE }),
generateExampleChannelDTO({ subType: ChannelSubType.LECTURE }),
generateExampleChannelDTO({ subType: ChannelSubType.EXAM }),
generateExampleChannelDTO({} as ChannelDTO),
generateExampleChannelDTO({ subType: ChannelSubType.EXERCISE } as ChannelDTO),
generateExampleChannelDTO({ subType: ChannelSubType.LECTURE } as ChannelDTO),
generateExampleChannelDTO({ subType: ChannelSubType.EXAM } as ChannelDTO),
];

examples.forEach((exampleChannel) => {
Expand Down Expand Up @@ -76,8 +74,8 @@ examples.forEach((exampleChannel) => {
beforeEach(() => {
fixture = TestBed.createComponent(ChannelsOverviewDialogComponent);
component = fixture.componentInstance;
channelOne = generateExampleChannelDTO({ id: 1, name: 'one', subType: exampleChannel.subType });
channelTwo = generateExampleChannelDTO({ id: 2, name: 'two', subType: exampleChannel.subType });
channelOne = generateExampleChannelDTO({ id: 1, name: 'one', subType: exampleChannel.subType } as ChannelDTO);
channelTwo = generateExampleChannelDTO({ id: 2, name: 'two', subType: exampleChannel.subType } as ChannelDTO);
channelService = TestBed.inject(ChannelService);
getChannelsOfCourseSpy = jest.spyOn(channelService, 'getChannelsOfCourse').mockReturnValue(
of(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@ import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { MockComponent, MockDirective, MockPipe } from 'ng-mocks';
import { CourseUsersSelectorComponent } from 'app/shared/course-users-selector/course-users-selector.component';
import { ConversationDTO } from 'app/entities/metis/conversation/conversation.model';
import { GroupChatDTO } from '../../../../../../../../../main/webapp/app/entities/metis/conversation/group-chat.model';
import { generateExampleChannelDTO, generateExampleGroupChatDTO } from '../../../helpers/conversationExampleModels';
import { Course } from 'app/entities/course.model';
import { isChannelDTO } from 'app/entities/metis/conversation/channel.model';
import { ChannelDTO, isChannelDTO } from 'app/entities/metis/conversation/channel.model';
import { By } from '@angular/platform-browser';
import { UserPublicInfoDTO } from 'app/core/user/user.model';
import { TranslateDirective } from 'app/shared/language/translate.directive';

const examples: ConversationDTO[] = [generateExampleGroupChatDTO({}), generateExampleChannelDTO({})];
const examples: ConversationDTO[] = [generateExampleGroupChatDTO({} as GroupChatDTO), generateExampleChannelDTO({} as ChannelDTO)];
examples.forEach((activeConversation) => {
describe('ConversationAddUsersFormComponent with ' + activeConversation.type, () => {
let component: ConversationAddUsersFormComponent;
Expand Down Expand Up @@ -164,23 +165,22 @@ examples.forEach((activeConversation) => {
expect(component.form.valid).toBeTrue();
expect(component.isSubmitPossible).toBeTrue();
}
const clickSubmitButton = (expectSubmitEvent: boolean, expectedFormData?: AddUsersFormData) => {
const clickSubmitButton = async (expectSubmitEvent: boolean, expectedFormData?: AddUsersFormData) => {
const submitFormSpy = jest.spyOn(component, 'submitForm');
const submitFormEventSpy = jest.spyOn(component.formSubmitted, 'emit');

const submitButton = fixture.debugElement.nativeElement.querySelector('#submitButton');
submitButton.click();

return fixture.whenStable().then(() => {
if (expectSubmitEvent) {
expect(submitFormSpy).toHaveBeenCalledOnce();
expect(submitFormEventSpy).toHaveBeenCalledOnce();
expect(submitFormEventSpy).toHaveBeenCalledWith(expectedFormData);
} else {
expect(submitFormSpy).not.toHaveBeenCalled();
expect(submitFormEventSpy).not.toHaveBeenCalled();
}
});
await fixture.whenStable();
if (expectSubmitEvent) {
expect(submitFormSpy).toHaveBeenCalledOnce();
expect(submitFormEventSpy).toHaveBeenCalledOnce();
expect(submitFormEventSpy).toHaveBeenCalledWith(expectedFormData);
} else {
expect(submitFormSpy).not.toHaveBeenCalled();
expect(submitFormEventSpy).not.toHaveBeenCalled();
}
};
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ import { ArtemisTranslatePipe } from 'app/shared/pipes/artemis-translate.pipe';
import { ChannelIconComponent } from 'app/overview/course-conversations/other/channel-icon/channel-icon.component';
import { UserPublicInfoDTO } from 'app/core/user/user.model';
import { By } from '@angular/platform-browser';
import { isChannelDTO } from 'app/entities/metis/conversation/channel.model';
import { isGroupChatDTO } from 'app/entities/metis/conversation/group-chat.model';
import { ChannelDTO, isChannelDTO } from 'app/entities/metis/conversation/channel.model';
import { GroupChatDTO, isGroupChatDTO } from 'app/entities/metis/conversation/group-chat.model';
import { of } from 'rxjs';
import { HttpResponse } from '@angular/common/http';
@Component({
Expand All @@ -34,7 +34,7 @@ class ConversationAddUsersFormStubComponent {
@Input()
activeConversation: ConversationDTO;
}
const examples: ConversationDTO[] = [generateExampleGroupChatDTO({}), generateExampleChannelDTO({})];
const examples: ConversationDTO[] = [generateExampleGroupChatDTO({} as GroupChatDTO), generateExampleChannelDTO({} as ChannelDTO)];
examples.forEach((activeConversation) => {
describe('ConversationAddUsersDialogComponent with ' + activeConversation.type, () => {
let component: ConversationAddUsersDialogComponent;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { MockComponent, MockPipe, MockProvider } from 'ng-mocks';
import { ChannelIconComponent } from 'app/overview/course-conversations/other/channel-icon/channel-icon.component';
import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap';
import { ConversationService } from 'app/shared/metis/conversations/conversation.service';
import { ChannelDTO } from '../../../../../../../../main/webapp/app/entities/metis/conversation/channel.model';
import { generateExampleChannelDTO, generateExampleGroupChatDTO, generateOneToOneChatDTO } from '../../helpers/conversationExampleModels';
import { initializeDialog } from '../dialog-test-helpers';
import { isOneToOneChatDTO } from 'app/entities/metis/conversation/one-to-one-chat.model';
Expand Down Expand Up @@ -65,7 +66,7 @@ class ConversationInfoStubComponent {
changesPerformed = new EventEmitter<void>();
}

const examples: ConversationDTO[] = [generateOneToOneChatDTO({}), generateExampleGroupChatDTO({}), generateExampleChannelDTO({})];
const examples: ConversationDTO[] = [generateOneToOneChatDTO({}), generateExampleGroupChatDTO({}), generateExampleChannelDTO({} as ChannelDTO)];

examples.forEach((activeConversation) => {
describe('ConversationDetailDialogComponent with ' + activeConversation.type, () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { GenericUpdateTextPropertyDialogComponent } from 'app/overview/course-co
import { defaultSecondLayerDialogOptions } from 'app/overview/course-conversations/other/conversation.util';
import { input } from '@angular/core';

const examples: ConversationDTO[] = [generateOneToOneChatDTO({}), generateExampleGroupChatDTO({}), generateExampleChannelDTO({})];
const examples: ConversationDTO[] = [generateOneToOneChatDTO({}), generateExampleGroupChatDTO({}), generateExampleChannelDTO({} as ChannelDTO)];

examples.forEach((activeConversation) => {
describe('ConversationInfoComponent with ' + activeConversation.type, () => {
Expand All @@ -36,7 +36,7 @@ examples.forEach((activeConversation) => {
name: 'updated',
description: 'updated',
topic: 'updated',
});
} as ChannelDTO);

beforeEach(waitForAsync(() => {
TestBed.configureTestingModule({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ const currentUserTemplate = { id: 3, login: 'login3', firstName: 'Kaddl3', lastN
const examples: ConversationDTO[] = [
generateOneToOneChatDTO({}),
generateExampleGroupChatDTO({}),
generateExampleChannelDTO({}),
generateExampleChannelDTO({ isCourseWide: true }),
generateExampleChannelDTO({} as ChannelDTO),
generateExampleChannelDTO({ isCourseWide: true } as ChannelDTO),
];

examples.forEach((activeConversation) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { ItemCountComponent } from 'app/shared/pagination/item-count.component';
import { NgbModal, NgbModalRef } from '@ng-bootstrap/ng-bootstrap';
import { ConversationMemberSearchFilter, ConversationService } from 'app/shared/metis/conversations/conversation.service';
import { AlertService } from 'app/core/util/alert.service';
import { ChannelDTO } from '../../../../../../../../../../main/webapp/app/entities/metis/conversation/channel.model';
import { generateExampleChannelDTO, generateExampleGroupChatDTO, generateOneToOneChatDTO } from '../../../../helpers/conversationExampleModels';
import { HttpHeaders, HttpResponse } from '@angular/common/http';
import { of } from 'rxjs';
Expand All @@ -34,7 +35,7 @@ class ConversationMemberRowStubComponent {
@Input()
conversationMember: ConversationUserDTO;
}
const examples: ConversationDTO[] = [generateOneToOneChatDTO({}), generateExampleGroupChatDTO({}), generateExampleChannelDTO({})];
const examples: ConversationDTO[] = [generateOneToOneChatDTO({}), generateExampleGroupChatDTO({}), generateExampleChannelDTO({} as ChannelDTO)];

examples.forEach((activeConversation) => {
describe('ConversationMembersComponent with ' + activeConversation.type, () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { defaultSecondLayerDialogOptions } from 'app/overview/course-conversatio
import * as ConversationPermissionUtils from 'app/shared/metis/conversations/conversation-permissions.utils';
import { input, runInInjectionContext } from '@angular/core';

const examples: ConversationDTO[] = [generateExampleGroupChatDTO({}), generateExampleChannelDTO({})];
const examples: ConversationDTO[] = [generateExampleGroupChatDTO({}), generateExampleChannelDTO({} as ChannelDTO)];

examples.forEach((activeConversation) => {
describe('ConversationSettingsComponent with ' + activeConversation.type, () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ import { ProfilePictureComponent } from '../../../../../../../../main/webapp/app
const examples: ConversationDTO[] = [
generateOneToOneChatDTO({}),
generateExampleGroupChatDTO({}),
generateExampleChannelDTO({}),
generateExampleChannelDTO({ subType: ChannelSubType.EXERCISE, subTypeReferenceId: 1 }),
generateExampleChannelDTO({ subType: ChannelSubType.LECTURE, subTypeReferenceId: 1 }),
generateExampleChannelDTO({ subType: ChannelSubType.EXAM, subTypeReferenceId: 1 }),
generateExampleChannelDTO({} as ChannelDTO),
generateExampleChannelDTO({ subType: ChannelSubType.EXERCISE, subTypeReferenceId: 1 } as ChannelDTO),
generateExampleChannelDTO({ subType: ChannelSubType.LECTURE, subTypeReferenceId: 1 } as ChannelDTO),
generateExampleChannelDTO({ subType: ChannelSubType.EXAM, subTypeReferenceId: 1 } as ChannelDTO),
];
examples.forEach((activeConversation) => {
describe('ConversationHeaderComponent with' + +(activeConversation instanceof ChannelDTO ? activeConversation.subType + ' ' : '') + activeConversation.type, () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ import { generateExampleChannelDTO, generateExampleGroupChatDTO, generateOneToOn
import { Directive, EventEmitter, Input, Output, QueryList } from '@angular/core';
import { By } from '@angular/platform-browser';
import { Course } from 'app/entities/course.model';
import { getAsChannelDTO } from 'app/entities/metis/conversation/channel.model';
import { ChannelDTO, getAsChannelDTO } from 'app/entities/metis/conversation/channel.model';
import { PostCreateEditModalComponent } from 'app/shared/metis/posting-create-edit-modal/post-create-edit-modal/post-create-edit-modal.component';
import dayjs from 'dayjs';

const examples: ConversationDTO[] = [
generateOneToOneChatDTO({}),
generateExampleGroupChatDTO({}),
generateExampleChannelDTO({}),
generateExampleChannelDTO({ isAnnouncementChannel: true }),
generateExampleChannelDTO({} as ChannelDTO),
generateExampleChannelDTO({ isAnnouncementChannel: true } as ChannelDTO),
];

@Directive({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ describe('ChannelService', () => {
service = TestBed.inject(ChannelService);
httpMock = TestBed.inject(HttpTestingController);

elemDefault = generateExampleChannelDTO({});
elemDefault = generateExampleChannelDTO({} as ChannelDTO);
});

afterEach(() => {
Expand Down
Loading

0 comments on commit 66cd503

Please sign in to comment.