Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Communication: Add profile picture to sidebar element and conversation header #9719

Merged
merged 3 commits into from
Nov 10, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
updated test
  • Loading branch information
asliayk committed Nov 9, 2024
commit 2e5ecffb7dd932f3bf5306217377adcf29546327
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export class SidebarCardItemComponent implements OnInit, OnChanges {
return this.unreadCount().toString() || '';
}

private extractMessageUser(): void {
extractMessageUser(): void {
if (this.sidebarItem.type === 'oneToOneChat' && (this.sidebarItem.conversation as OneToOneChatDTO)?.members) {
this.otherUser = (this.sidebarItem.conversation as OneToOneChatDTO).members!.find((user) => !user.isRequestingUser);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,41 @@ import { SidebarCardItemComponent } from 'app/shared/sidebar/sidebar-card-item/s
import { SidebarCardSize } from 'app/types/sidebar';
import { ArtemisTestModule } from '../../../test.module';
import { DifficultyLevel } from 'app/entities/exercise.model';
import { OneToOneChatDTO } from 'app/entities/metis/conversation/one-to-one-chat.model';
import { input, runInInjectionContext } from '@angular/core';
import { faPeopleGroup } from '@fortawesome/free-solid-svg-icons';
import { ProfilePictureComponent } from '../../../../../../main/webapp/app/shared/profile-picture/profile-picture.component';
import { MockComponent } from 'ng-mocks';

describe('SidebarCardItemComponent', () => {
let component: SidebarCardItemComponent;
let fixture: ComponentFixture<SidebarCardItemComponent>;
let sidebarItemMock: any;

beforeEach(() => {
TestBed.configureTestingModule({
imports: [ArtemisTestModule],
declarations: [SidebarCardItemComponent],
declarations: [SidebarCardItemComponent, MockComponent(ProfilePictureComponent)],
}).compileComponents();
});

beforeEach(() => {
fixture = TestBed.createComponent(SidebarCardItemComponent);
component = fixture.componentInstance;

sidebarItemMock = {
title: 'testTitle',
id: 'testId',
size: 'M' as SidebarCardSize,
difficulty: DifficultyLevel.EASY,
type: 'oneToOneChat',
conversation: {
members: [
{ id: 2, name: 'RequestingUser', isRequestingUser: true },
{ id: 1, name: 'User1', isRequestingUser: false },
],
} as OneToOneChatDTO,
};

component.sidebarItem = sidebarItemMock;
fixture.detectChanges();
});

Expand All @@ -27,16 +46,8 @@ describe('SidebarCardItemComponent', () => {
});

it('should display item title', () => {
const testItem = {
title: 'testTitle',
id: 'testId',
size: 'M' as SidebarCardSize,
difficulty: DifficultyLevel.EASY,
};
component.sidebarItem = testItem;
fixture.detectChanges();
const compiled = fixture.debugElement.nativeElement;
expect(compiled.querySelector('#test-sidebar-card-title').textContent).toContain(testItem.title);
expect(compiled.querySelector('#test-sidebar-card-title').textContent).toContain(sidebarItemMock.title);
});

it('should format unreadCount correctly when count is less than 99', () => {
Expand All @@ -54,4 +65,16 @@ describe('SidebarCardItemComponent', () => {
expect(component.formattedUnreadCount).toBe('99+');
});
});

it('should set group icon for group chats in extractMessageUser', () => {
component.sidebarItem.type = 'groupChat';
component.sidebarItem.icon = undefined;
component.extractMessageUser();
expect(component.sidebarItem.icon).toBe(faPeopleGroup);
});

it('should set otherUser for one-to-one chat in extractMessageUser', () => {
component.extractMessageUser();
expect(component.otherUser).toEqual(sidebarItemMock.conversation.members[1]);
});
});
Loading