Skip to content

Commit

Permalink
fix: comments
Browse files Browse the repository at this point in the history
  • Loading branch information
kovalsofiia1 committed Nov 22, 2024
1 parent 6750f1b commit a1d3ecc
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ export class MatSnackBarComponent {
addFriend: { classname: SnackbarClassName.success, key: 'snack-bar.success.add-friend' },
friendValidation: { classname: SnackbarClassName.error, key: 'snack-bar.error.friend-request' },
friendInValidRequest: { classname: SnackbarClassName.error, key: 'snack-bar.error.friend-already-added' },
friendRequestAccepted: { classname: SnackbarClassName.success, key: 'snack-bar.success.friend-added-success' },
friendRequestDeclined: { classname: SnackbarClassName.success, key: 'snack-bar.success.friend-declined-success' },
habitAcceptRequest: { classname: SnackbarClassName.success, key: 'snack-bar.success.habit-added-success' },
habitDeclineRequest: { classname: SnackbarClassName.success, key: 'snack-bar.success.habit-decline-success' },
habitAcceptInValidRequest: { classname: SnackbarClassName.error, key: 'snack-bar.error.habit-not-added' },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -296,9 +296,7 @@ export class UserNotificationsComponent implements OnInit, OnDestroy {
isAccepted = false;
},
complete: () => {
if (isAccepted) {
this.matSnackBar.openSnackBar('friendInValidRequest');
}
this.matSnackBar.openSnackBar(isAccepted ? 'friendRequestAccepted' : 'friendInValidRequest');
}
});
} else {
Expand All @@ -307,9 +305,7 @@ export class UserNotificationsComponent implements OnInit, OnDestroy {
isAccepted = false;
},
complete: () => {
if (isAccepted) {
this.matSnackBar.openSnackBar('friendInValidRequest');
}
this.matSnackBar.openSnackBar(isAccepted ? 'friendRequestDeclined' : 'friendInValidRequest');
}
});
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Component } from '@angular/core';
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
import { NotificContentReplaceDirective } from './notific-content-replace.directive';

@Component({
Expand Down Expand Up @@ -30,7 +30,7 @@ describe('NotificContentReplaceDirective', () => {
viewed: false
};

beforeEach(() => {
beforeEach(waitForAsync(() => {
TestBed.configureTestingModule({
declarations: [TestComponent, NotificContentReplaceDirective]
});
Expand All @@ -39,7 +39,7 @@ describe('NotificContentReplaceDirective', () => {
fixture.detectChanges();
component = fixture.componentInstance;
paragrEl = fixture.nativeElement.querySelector('p');
});
}));

it('should display multiple user replacements', () => {
component.notification = { ...notification, ...{ bodyText: '{user1} and {user2} liked your post' } };
Expand Down Expand Up @@ -74,7 +74,7 @@ describe('NotificContentReplaceDirective', () => {
component.notification = { ...notification, ...{ bodyText: 'commented event {message}' } };
fixture.detectChanges();
expect(paragrEl.textContent).toBe('commented event test message');
expect(paragrEl.innerHTML).toBe('commented event <a data-targetid="10" data-notificationtype="Eco_NEWS">test message</a>');
expect(paragrEl.innerHTML).toBe('commented event test message');
});

it('should add property value to the content and anchor tag', () => {
Expand All @@ -83,10 +83,7 @@ describe('NotificContentReplaceDirective', () => {
...{ bodyText: '{user1},{user2} commented event {message}', actionUserId: [2, 3], actionUserText: ['testUser1', 'testUser2'] }
};
fixture.detectChanges();
expect(paragrEl.textContent).toBe('testUser1,testUser2 commented event test message'); // Text content without tags
expect(paragrEl.innerHTML).toBe(
'<a data-userid="2">testUser1</a>,<a data-userid="3">testUser2</a> commented event ' +
'<a data-targetid="10" data-notificationtype="Eco_NEWS">test message</a>'
);
expect(paragrEl.textContent).toBe('testUser1,testUser2 commented event test message');
expect(paragrEl.innerHTML).toBe('<a data-userid="2">testUser1</a>,<a data-userid="3">testUser2</a> commented event test message');
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,6 @@ export class NotificContentReplaceDirective implements OnChanges {
userId: replacements.actionUserId[index]
});
}
} else if (contentKey === 'message' && replacements.notificationType) {
const linkAttributes = replacements.targetId
? { targetId: replacements.targetId, notificationType: replacements.notificationType }
: null;
result = this.buildReplacementString(result, contentKey, replacements[replacementKey], linkAttributes);
} else if (replacements.hasOwnProperty(replacementKey)) {
const linkAttributes = idToNavigate ? { userId: replacements[idToNavigate] } : null;

Expand Down
28 changes: 27 additions & 1 deletion src/app/main/service/habit/habit.service.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing';
import { TestBed } from '@angular/core/testing';
import { TestBed, waitForAsync } from '@angular/core/testing';
import { LocalStorageService } from '@global-service/localstorage/local-storage.service';
import { BehaviorSubject } from 'rxjs';
import { HabitService } from './habit.service';
Expand Down Expand Up @@ -255,4 +255,30 @@ describe('HabitService', () => {
expect(req.request.method).toBe('GET');
req.flush(HABITLIST);
});

it('should accept habit invitation', () => {
const invitationId = 123;
const mockResponse = 'Invitation accepted successfully';

habitService.acceptHabitInvitation(invitationId).subscribe((response) => {
expect(response).toEqual(mockResponse);
});

const req = httpMock.expectOne(`${habitLink}/invite/${invitationId}/accept`);
expect(req.request.method).toBe('PATCH');
req.flush(mockResponse);
});

it('should decline habit invitation', () => {
const invitationId = 456;
const mockResponse = 'Invitation declined successfully';

habitService.declineHabitInvitation(invitationId).subscribe((response) => {
expect(response).toEqual(mockResponse);
});

const req = httpMock.expectOne(`${habitLink}/invite/${invitationId}/reject`);
expect(req.request.method).toBe('DELETE');
req.flush(mockResponse);
});
});
2 changes: 1 addition & 1 deletion src/app/main/service/habit/habit.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export class HabitService {
}

declineHabitInvitation(invitationId: number): Observable<string> {
return this.http.patch<string>(`${habitLink}/invite/${invitationId}/reject`, {});
return this.http.delete<string>(`${habitLink}/invite/${invitationId}/reject`);
}

private prepareCustomHabitRequest(habit: CustomHabit, lang: string): FormData {
Expand Down
6 changes: 4 additions & 2 deletions src/assets/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,7 @@
"exist-address": "This address has already been added",
"certificate-duration": "The duration of the certificate cant be more than 12 months",
"friend-request": "You cannot add this friend",
"friend-already-added": "This friend has been already added",
"friend-already-added": "This friend invitation has been already accepted or declined",
"error-create-address": "Oops, An error occurred while creating the address. Please try again.",
"habit-not-added": "This habit invitation can`t be accepted",
"habit-already-added": "This habit invitation can`t be declined",
Expand Down Expand Up @@ -538,7 +538,9 @@
"joint-event-request": "The request to join the closed event has been successfully sent to the organizer",
"create-news": "Your news has been successfully published",
"habit-added-success": "Habit invitation was accepted",
"habit-decline-success": "Habit invitation was declined"
"habit-decline-success": "Habit invitation was declined",
"friend-added-success": "Friend invitation accepted",
"friend-declined-success": "Friend invitation declined"
}
},
"user": {
Expand Down
6 changes: 4 additions & 2 deletions src/assets/i18n/ua.json
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,7 @@
"exist-address": "Ця адреса вже додана",
"certificate-duration": "Термін дії сертифіката не може перевищувати 12 місяців",
"friend-request": "Ви не можете додати цього друга",
"friend-already-added": "Цього друга вже було додано",
"friend-already-added": "Це запрошення друга вже було додано або відхилено",
"error-create-address": "Упс! Виникла помилка при створенні адреси. Будь ласка, спробуйте ще раз.",
"habit-not-added": "Неможливо прийняти запрошення",
"habit-already-added": "Неможливо відхилити запрошення",
Expand Down Expand Up @@ -547,7 +547,9 @@
"joint-event-request": "Запит на приєднання до закритої події надіслано",
"create-news": "Ваша новина успішно опублікована",
"habit-added-success": "Запрошення прийнято",
"habit-decline-success": "Запрошення відхилено"
"habit-decline-success": "Запрошення відхилено",
"friend-added-success": "Запит на дружбу прийнято",
"friend-declined-success": "Запит на дружбу відхилено"
}
},
"user": {
Expand Down

0 comments on commit a1d3ecc

Please sign in to comment.