Skip to content

Commit

Permalink
[ACS-5311] addressed review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
SheenaMalhotra182 committed Nov 2, 2023
1 parent 98f63a9 commit 21d366f
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
id="adf-notification-history-open-button"
(menuOpened)="onMenuOpened()">
<mat-icon matBadge="&#8288;"
[matBadgeHidden]="!unreadNotifications.length || badgeHidden"
[matBadgeHidden]="!unreadNotifications.length"
matBadgeColor="accent"
matBadgeSize="small">notifications</mat-icon>
</button>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import { NotificationService } from '../services/notification.service';
import { StorageService } from '../../common/services/storage.service';
import { TranslateModule } from '@ngx-translate/core';
import { NotificationModel, NOTIFICATION_TYPE, NOTIFICATION_STORAGE } from '../models/notification.model';
import { By } from '@angular/platform-browser';

describe('Notification History Component', () => {

Expand All @@ -42,8 +41,6 @@ describe('Notification History Component', () => {
fixture.detectChanges();
};

const getMatBadgeElement = (): HTMLElement => fixture.debugElement.query(By.css('[matBadge]')).nativeElement;

beforeEach(() => {
TestBed.configureTestingModule({
imports: [
Expand Down Expand Up @@ -231,29 +228,4 @@ describe('Notification History Component', () => {
expect(component.unreadNotifications.length).toEqual(1);
expect(component.unreadNotifications[0].read).toEqual(false);
});

it('should return isBadgeVisible as true when there are unread notifications', () => {
component.unreadNotifications = testNotifications;

const result = component.isBadgeVisible();
const matIconDebugElement = getMatBadgeElement();

expect(result).toBe(true);
expect(matIconDebugElement.textContent).toContain('notifications');
});

it('should return isBadgeVisible as false when there are no unread notifications', () => {
testNotifications.forEach((notification: NotificationModel) => {
notification.read = true;
});
component.notifications = testNotifications;
fixture.detectChanges();

const result = component.isBadgeVisible();
const matBadgeDebugElement = getMatBadgeElement();

expect(component.unreadNotifications).toEqual([]);
expect(result).toBe(false);
expect(matBadgeDebugElement.textContent).toContain('');
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ export class NotificationHistoryComponent implements OnDestroy, OnInit, AfterVie
paginatedNotifications: NotificationModel[] = [];
unreadNotifications: NotificationModel[] = [];
pagination: PaginationModel;
badgeHidden: boolean;

constructor(private notificationService: NotificationService, public storageService: StorageService, public cd: ChangeDetectorRef) {}

Expand All @@ -64,7 +63,6 @@ export class NotificationHistoryComponent implements OnDestroy, OnInit, AfterVie
JSON.parse(this.storageService.getItem(NOTIFICATION_STORAGE))?.filter(
(notification: NotificationModel) => !notification.read
) || [];
this.badgeHidden = !this.isBadgeVisible();
}

ngAfterViewInit(): void {
Expand All @@ -82,7 +80,6 @@ export class NotificationHistoryComponent implements OnDestroy, OnInit, AfterVie
}

addNewNotification(notification: NotificationModel) {
this.badgeHidden = !this.isBadgeVisible();
this.unreadNotifications.unshift(notification);

if (this.unreadNotifications.length > NotificationHistoryComponent.MAX_NOTIFICATION_STACK_LENGTH) {
Expand All @@ -99,7 +96,6 @@ export class NotificationHistoryComponent implements OnDestroy, OnInit, AfterVie
});

this.storageService.setItem(NOTIFICATION_STORAGE, JSON.stringify(this.notifications));
this.badgeHidden = !this.isBadgeVisible();
}

onMenuOpened() {
Expand All @@ -122,7 +118,6 @@ export class NotificationHistoryComponent implements OnDestroy, OnInit, AfterVie
notification.read = true;
});

this.badgeHidden = !this.isBadgeVisible();
this.storageService.setItem(NOTIFICATION_STORAGE, JSON.stringify(this.notifications));
this.paginatedNotifications = [];
this.createPagination();
Expand Down Expand Up @@ -155,8 +150,4 @@ export class NotificationHistoryComponent implements OnDestroy, OnInit, AfterVie
this.trigger.closeMenu();
}
}

isBadgeVisible(): boolean {
return this.unreadNotifications.length > 0;
}
}

0 comments on commit 21d366f

Please sign in to comment.