Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,16 @@ import { AnswerPost } from 'app/communication/shared/entities/answer-post.model'
import { MetisConversationService } from 'app/communication/service/metis-conversation.service';
import { of } from 'rxjs';
import { MockMetisConversationService } from 'test/helpers/mocks/service/mock-metis-conversation.service';
import { CourseSidebarService } from 'app/core/course/overview/services/course-sidebar.service';

describe('PostingReactionsBarComponent', () => {
let component: PostingReactionsBarComponent<Posting>;
let fixture: ComponentFixture<PostingReactionsBarComponent<Posting>>;
let debugElement: DebugElement;
let metisService: MetisService;
let accountService: AccountService;
let courseSidebarService: CourseSidebarService;
let reloadSidebarSpy: jest.SpyInstance;
let metisServiceUpdateDisplayPriorityMock: jest.SpyInstance;
let metisServiceUserIsAtLeastTutorStub: jest.SpyInstance;
let metisServiceUserIsAtLeastInstructorStub: jest.SpyInstance;
Expand Down Expand Up @@ -88,13 +91,16 @@ describe('PostingReactionsBarComponent', () => {
{ provide: TranslateService, useClass: MockTranslateService },
{ provide: Router, useClass: MockRouter },
{ provide: MetisConversationService, useClass: MockMetisConversationService },
MockProvider(CourseSidebarService),
],
})
.compileComponents()
.then(() => {
fixture = TestBed.createComponent(PostingReactionsBarComponent);
metisService = TestBed.inject(MetisService);
accountService = TestBed.inject(AccountService);
courseSidebarService = TestBed.inject(CourseSidebarService);
reloadSidebarSpy = jest.spyOn(courseSidebarService, 'reloadSidebar');
debugElement = fixture.debugElement;
component = fixture.componentInstance;
metisServiceUpdateDisplayPriorityMock = jest.spyOn(metisService, 'updatePostDisplayPriority');
Expand Down Expand Up @@ -720,4 +726,18 @@ describe('PostingReactionsBarComponent', () => {
expect(createForwardedMessagesSpy).toHaveBeenCalledWith([testPost], testConversation, isAnswer, content);
expect(consoleErrorSpy).not.toHaveBeenCalled();
});

it('should reload sidebar when forwardPost is completed', fakeAsync(() => {
const testPost = { id: 42 } as Posting;
const testConversation = { id: 1337 } as Conversation;
const content = 'Test content';
const isAnswer = false;

createForwardedMessagesSpy.mockReturnValue(of(null));

component.forwardPost(testPost, testConversation, content, isAnswer);
tick();

expect(reloadSidebarSpy).toHaveBeenCalledOnce();
}));
});
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import { map } from 'rxjs';
import { ForwardMessageDialogComponent } from 'app/communication/course-conversations-components/forward-message-dialog/forward-message-dialog.component';
import { UserPublicInfoDTO } from 'app/core/user/user.model';
import { firstValueFrom } from 'rxjs';
import { CourseSidebarService } from 'app/core/course/overview/services/course-sidebar.service';

const PIN_EMOJI_ID = 'pushpin';
const ARCHIVE_EMOJI_ID = 'open_file_folder';
Expand Down Expand Up @@ -147,6 +148,7 @@ export class PostingReactionsBarComponent<T extends Posting> implements OnInit,
private conversationService = inject(ConversationService);
private modalService = inject(NgbModal);
private metisConversationService = inject(MetisConversationService);
private courseSidebarService = inject(CourseSidebarService);

/**
* on initialization: updates the current posting and its reactions,
Expand Down Expand Up @@ -582,7 +584,11 @@ export class PostingReactionsBarComponent<T extends Posting> implements OnInit,
* Sends the post to selected conversation with optional new content via MetisService.
*/
forwardPost(post: Posting, conversation: Conversation, content: string, isAnswer: boolean): void {
this.metisService.createForwardedMessages([post], conversation, isAnswer, content).subscribe({});
this.metisService.createForwardedMessages([post], conversation, isAnswer, content).subscribe({
complete: () => {
this.courseSidebarService.reloadSidebar();
},
});
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,15 @@ examples.forEach((activeConversation) => {
expect(component.isCollapsed).toBeTrue();
});

it('should reload sidebar when reloadSidebar$ event is emitted', () => {
const prepareSidebarDataSpy = jest.spyOn(component, 'prepareSidebarData');
fixture.detectChanges(); // ngOnInit is called here

courseSidebarService.reloadSidebar();

expect(prepareSidebarDataSpy).toHaveBeenCalled();
});

it('should switch to mobile if breakpoint returns true and open sidebar', () => {
const openSidebarSpy = jest.spyOn(courseSidebarService, 'openSidebar');
expect(component.isMobile()).toBeFalse();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ export class CourseConversationsComponent implements OnInit, OnDestroy {
private closeSidebarEventSubscription: Subscription;
private openSidebarEventSubscription: Subscription;
private toggleSidebarEventSubscription: Subscription;
private reloadSidebarEventSubscription: Subscription;
course = signal<Course | undefined>(undefined);
isLoading = false;
isServiceSetUp = false;
Expand Down Expand Up @@ -254,6 +255,10 @@ export class CourseConversationsComponent implements OnInit, OnDestroy {
this.toggleSidebar();
});

this.reloadSidebarEventSubscription = this.courseSidebarService.reloadSidebar$.subscribe(() => {
this.prepareSidebarData();
});

if (!this.isMobile()) {
if (this.courseOverviewService.getSidebarCollapseStateFromStorage('conversation')) {
this.courseSidebarService.openSidebar();
Expand Down Expand Up @@ -375,6 +380,7 @@ export class CourseConversationsComponent implements OnInit, OnDestroy {
this.openSidebarEventSubscription?.unsubscribe();
this.closeSidebarEventSubscription?.unsubscribe();
this.toggleSidebarEventSubscription?.unsubscribe();
this.reloadSidebarEventSubscription?.unsubscribe();
}

private subscribeToActiveConversation() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,21 +32,31 @@ describe('CourseSidebarService', () => {
expect(emitSpy).toHaveBeenCalled();
});

it('should emit reloadSidebar event', () => {
const emitSpy = jest.spyOn(service.reloadSidebar$, 'emit');
service.reloadSidebar();
expect(emitSpy).toHaveBeenCalled();
});

it('should emit events when subscribing', () => {
const closeSpy = jest.fn();
const openSpy = jest.fn();
const toggleSpy = jest.fn();
const reloadSpy = jest.fn();

service.closeSidebar$.subscribe(closeSpy);
service.openSidebar$.subscribe(openSpy);
service.toggleSidebar$.subscribe(toggleSpy);
service.reloadSidebar$.subscribe(reloadSpy);

service.closeSidebar();
service.openSidebar();
service.toggleSidebar();
service.reloadSidebar();

expect(closeSpy).toHaveBeenCalled();
expect(openSpy).toHaveBeenCalled();
expect(toggleSpy).toHaveBeenCalled();
expect(reloadSpy).toHaveBeenCalled();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export class CourseSidebarService {
public closeSidebar$: EventEmitter<void> = new EventEmitter();
public openSidebar$: EventEmitter<void> = new EventEmitter();
public toggleSidebar$: EventEmitter<void> = new EventEmitter();
public reloadSidebar$: EventEmitter<void> = new EventEmitter();

public closeSidebar(): void {
this.closeSidebar$.emit();
Expand All @@ -19,4 +20,8 @@ export class CourseSidebarService {
public toggleSidebar(): void {
this.toggleSidebar$.emit();
}

public reloadSidebar(): void {
this.reloadSidebar$.emit();
}
}
Loading