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: Remove hidden conversations from favorites #9473

Merged
merged 6 commits into from
Oct 19, 2024
Merged
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 @@ -79,11 +79,35 @@ export class ConversationOptionsComponent implements OnInit, OnDestroy {

onHiddenClicked(event: MouseEvent) {
event.stopPropagation();
if (!this.course.id || !this.conversation.id) {
return;
}

if (!this.conversation.isHidden && this.conversation.isFavorite) {
this.conversationService.updateIsFavorite(this.course.id, this.conversation.id, false).subscribe({
next: () => {
this.conversation.isFavorite = false;
},
error: (errorResponse: HttpErrorResponse) => onError(this.alertService, errorResponse),
});
}
this.hide$.next(!this.conversation.isHidden);
}

onFavoriteClicked($event: MouseEvent) {
$event.stopPropagation();
if (!this.course.id || !this.conversation.id) {
return;
}

if (this.conversation.isHidden && !this.conversation.isFavorite) {
this.conversationService.updateIsHidden(this.course.id, this.conversation.id, false).subscribe({
next: () => {
this.conversation.isHidden = false;
},
error: (errorResponse: HttpErrorResponse) => onError(this.alertService, errorResponse),
});
}
this.favorite$.next(!this.conversation.isFavorite);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,43 @@ examples.forEach((conversation) => {
expect(component).toBeTruthy();
});

it('should remove conversation from favorites when hidden', fakeAsync(() => {
component.conversation.isFavorite = true;
component.conversation.isHidden = false;

const hideButton = fixture.debugElement.nativeElement.querySelector('.hide');
hideButton.click();
tick(501);

expect(updateIsFavoriteSpy).toHaveBeenCalledOnce();
expect(updateIsFavoriteSpy).toHaveBeenCalledWith(course.id, component.conversation.id, false);

expect(updateIsHiddenSpy).toHaveBeenCalledOnce();
expect(updateIsHiddenSpy).toHaveBeenCalledWith(course.id, component.conversation.id, true);

expect(component.conversation.isFavorite).toBeFalse();
expect(component.conversation.isHidden).toBeTrue();
}));

it('should remove conversation from hidden when favorited', fakeAsync(() => {
component.conversation.isFavorite = false;
component.conversation.isHidden = true;
fixture.detectChanges();

const favoriteButton = fixture.debugElement.nativeElement.querySelector('.favorite');
favoriteButton.click();
tick(501);

expect(updateIsHiddenSpy).toHaveBeenCalledOnce();
expect(updateIsHiddenSpy).toHaveBeenCalledWith(course.id, component.conversation.id, false);

expect(updateIsFavoriteSpy).toHaveBeenCalledOnce();
expect(updateIsFavoriteSpy).toHaveBeenCalledWith(course.id, component.conversation.id, true);

expect(component.conversation.isHidden).toBeFalse();
expect(component.conversation.isFavorite).toBeTrue();
}));

it('should call updateIsFavorite when button is clicked', fakeAsync(() => {
const button = fixture.debugElement.nativeElement.querySelector('.favorite');
button.click();
Expand Down
Loading