From d6f5a57079c1f55b34838179ac20f7a944617630 Mon Sep 17 00:00:00 2001 From: Anastasia <155824290+kryzanivska-nastya@users.noreply.github.com> Date: Sun, 22 Dec 2024 18:44:06 +0200 Subject: [PATCH] fix #7876 --- ...it-invite-friends-pop-up.component.spec.ts | 24 +++++-------------- .../habit-invite-friends-pop-up.component.ts | 11 +++++---- 2 files changed, 12 insertions(+), 23 deletions(-) diff --git a/src/app/main/component/user/components/habit/add-new-habit/habit-invite-friends/habit-invite-friends-pop-up/habit-invite-friends-pop-up.component.spec.ts b/src/app/main/component/user/components/habit/add-new-habit/habit-invite-friends/habit-invite-friends-pop-up/habit-invite-friends-pop-up.component.spec.ts index 7598618624..622295bc4e 100644 --- a/src/app/main/component/user/components/habit/add-new-habit/habit-invite-friends/habit-invite-friends-pop-up/habit-invite-friends-pop-up.component.spec.ts +++ b/src/app/main/component/user/components/habit/add-new-habit/habit-invite-friends/habit-invite-friends-pop-up/habit-invite-friends-pop-up.component.spec.ts @@ -10,6 +10,7 @@ import { FRIENDS, FIRSTFRIEND, SECONDFRIEND } from '@global-user/mocks/friends-m import { MatDialogModule } from '@angular/material/dialog'; import { MatCheckboxModule } from '@angular/material/checkbox'; import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog'; +import { HabitService } from '../../../../../../../service/habit/habit.service'; describe('HabitInviteFriendsPopUpComponent', () => { let component: HabitInviteFriendsPopUpComponent; @@ -26,11 +27,16 @@ describe('HabitInviteFriendsPopUpComponent', () => { userFriendsServiceMock.inviteFriendsToHabit = jasmine.createSpy('inviteFriendsToHabit').and.returnValue(of({})); userFriendsServiceMock.addedFriends = []; + const mockHabitService = { + getFriendsWithInvitations: jasmine.createSpy('getFriendsWithInvitations').and.returnValue(of({ page: [] })) + }; + beforeEach(waitForAsync(() => { TestBed.configureTestingModule({ declarations: [HabitInviteFriendsPopUpComponent], imports: [HttpClientTestingModule, TranslateModule.forRoot(), MatDialogModule, MatCheckboxModule], providers: [ + { provide: HabitService, useValue: mockHabitService }, { provide: LocalStorageService, useValue: localStorageServiceMock }, { provide: Router, useValue: routerSpy }, { provide: MatSnackBarComponent, useValue: MatSnackBarMock }, @@ -58,24 +64,6 @@ describe('HabitInviteFriendsPopUpComponent', () => { expect(spy2).toHaveBeenCalled(); }); - describe('setFriendDisable', () => { - it('should return true if the friend is in the addedFriends list and invitationSent is false', () => { - const friendId = 1; - userFriendsServiceMock.addedFriends = [FIRSTFRIEND, SECONDFRIEND]; - component.invitationSent = false; - const result = component.setFriendDisable(friendId); - expect(result).toBe(false); - }); - - it('should return true if invitationSent is true, regardless of addedFriends', () => { - const friendId = 1; - userFriendsServiceMock.addedFriends = [FIRSTFRIEND, SECONDFRIEND]; - component.invitationSent = true; - const result = component.setFriendDisable(friendId); - expect(result).toBe(true); - }); - }); - xit('should update allAdd status', () => { component.friends = [FIRSTFRIEND, SECONDFRIEND]; component.updateAllAdd(); diff --git a/src/app/main/component/user/components/habit/add-new-habit/habit-invite-friends/habit-invite-friends-pop-up/habit-invite-friends-pop-up.component.ts b/src/app/main/component/user/components/habit/add-new-habit/habit-invite-friends/habit-invite-friends-pop-up/habit-invite-friends-pop-up.component.ts index bf54fd1949..a17eb7b00c 100644 --- a/src/app/main/component/user/components/habit/add-new-habit/habit-invite-friends/habit-invite-friends-pop-up/habit-invite-friends-pop-up.component.ts +++ b/src/app/main/component/user/components/habit/add-new-habit/habit-invite-friends/habit-invite-friends-pop-up/habit-invite-friends-pop-up.component.ts @@ -24,7 +24,7 @@ export class HabitInviteFriendsPopUpComponent implements OnInit, OnDestroy { allAdd = false; searchIcon = searchIcon; habitId: number; - + constructor( private readonly userFriendsService: UserFriendsService, private readonly localStorageService: LocalStorageService, @@ -60,7 +60,7 @@ export class HabitInviteFriendsPopUpComponent implements OnInit, OnDestroy { onFriendCheckboxChange(friendId: number, isChecked: boolean) { const friend = this.friends.find((f) => f.id === friendId); - if (friend && !friend.hasInvitation) { + if (friend && !friend.hasInvitation) { friend.added = isChecked; this.toggleFriendSelection(friendId, isChecked); this.updateAllAdd(); @@ -93,9 +93,9 @@ export class HabitInviteFriendsPopUpComponent implements OnInit, OnDestroy { setFriendDisable(friendId: number): boolean { const friend = this.friends.find((f) => f.id === friendId); - return friend ? friend.hasInvitation : false; + return friend ? friend.hasInvitation : false; } - + setAllFriendsDisable(): boolean { return this.friends.every((friend) => friend.hasInvitation); } @@ -112,6 +112,7 @@ export class HabitInviteFriendsPopUpComponent implements OnInit, OnDestroy { this.allAdd = added; this.friends.forEach((friend) => { if (!this.isFriendAddedAlready(friend.id) && !friend.hasInvitation) { + friend.added = added; this.toggleFriendSelection(friend.id, added); } }); @@ -135,5 +136,5 @@ export class HabitInviteFriendsPopUpComponent implements OnInit, OnDestroy { ngOnDestroy() { this.destroyed$.next(true); this.destroyed$.complete(); - } + } }