Skip to content

Commit

Permalink
[ACS-5311] moved NOTIFICATION_STORAGE to notification.model.ts to reu…
Browse files Browse the repository at this point in the history
…se across repos
  • Loading branch information
SheenaMalhotra182 committed Nov 2, 2023
1 parent a91be3a commit 98f63a9
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { OverlayContainer } from '@angular/cdk/overlay';
import { NotificationService } from '../services/notification.service';
import { StorageService } from '../../common/services/storage.service';
import { TranslateModule } from '@ngx-translate/core';
import { NotificationModel, NOTIFICATION_TYPE } from '../models/notification.model';
import { NotificationModel, NOTIFICATION_TYPE, NOTIFICATION_STORAGE } from '../models/notification.model';
import { By } from '@angular/platform-browser';

describe('Notification History Component', () => {
Expand Down Expand Up @@ -85,7 +85,7 @@ describe('Notification History Component', () => {
}));

afterEach(() => {
storage.removeItem(NotificationHistoryComponent.NOTIFICATION_STORAGE);
storage.removeItem(NOTIFICATION_STORAGE);
fixture.destroy();
});

Expand Down Expand Up @@ -171,7 +171,7 @@ describe('Notification History Component', () => {
});

it('should read notifications from local storage', (done) => {
storage.setItem(NotificationHistoryComponent.NOTIFICATION_STORAGE, JSON.stringify([{
storage.setItem(NOTIFICATION_STORAGE, JSON.stringify([{
messages: ['My new message'],
datetime: new Date(),
type: NOTIFICATION_TYPE.RECURSIVE
Expand Down Expand Up @@ -217,15 +217,15 @@ describe('Notification History Component', () => {
testNotifications.forEach((notification: NotificationModel) => {
notification.read = true;
});
storage.setItem(NotificationHistoryComponent.NOTIFICATION_STORAGE, JSON.stringify(testNotifications));
storage.setItem(NOTIFICATION_STORAGE, JSON.stringify(testNotifications));
fixture.detectChanges();

expect(component.unreadNotifications).toEqual([]);
});

it('should set unreadNotifications by filtering notifications where read is false', () => {
testNotifications[0].read = true;
storage.setItem(NotificationHistoryComponent.NOTIFICATION_STORAGE, JSON.stringify(testNotifications));
storage.setItem(NOTIFICATION_STORAGE, JSON.stringify(testNotifications));
fixture.detectChanges();

expect(component.unreadNotifications.length).toEqual(1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

import { Component, Input, ViewChild, OnDestroy, OnInit, AfterViewInit, ChangeDetectorRef, ViewEncapsulation } from '@angular/core';
import { NotificationService } from '../services/notification.service';
import { NotificationModel } from '../models/notification.model';
import { NOTIFICATION_STORAGE, NotificationModel } from '../models/notification.model';
import { MatMenuTrigger, MenuPositionX, MenuPositionY } from '@angular/material/menu';
import { takeUntil } from 'rxjs/operators';
import { Subject } from 'rxjs';
Expand All @@ -33,7 +33,6 @@ import { PaginationModel } from '../../models/pagination.model';
export class NotificationHistoryComponent implements OnDestroy, OnInit, AfterViewInit {

public static MAX_NOTIFICATION_STACK_LENGTH = 100;
public static NOTIFICATION_STORAGE = 'notification-history';

@ViewChild(MatMenuTrigger, { static: true })
trigger: MatMenuTrigger;
Expand All @@ -60,9 +59,9 @@ export class NotificationHistoryComponent implements OnDestroy, OnInit, AfterVie
constructor(private notificationService: NotificationService, public storageService: StorageService, public cd: ChangeDetectorRef) {}

ngOnInit() {
this.notifications = JSON.parse(this.storageService.getItem(NotificationHistoryComponent.NOTIFICATION_STORAGE)) || [];
this.notifications = JSON.parse(this.storageService.getItem(NOTIFICATION_STORAGE)) || [];
this.unreadNotifications =
JSON.parse(this.storageService.getItem(NotificationHistoryComponent.NOTIFICATION_STORAGE))?.filter(
JSON.parse(this.storageService.getItem(NOTIFICATION_STORAGE))?.filter(
(notification: NotificationModel) => !notification.read
) || [];
this.badgeHidden = !this.isBadgeVisible();
Expand Down Expand Up @@ -99,7 +98,7 @@ export class NotificationHistoryComponent implements OnDestroy, OnInit, AfterVie
this.notifications.push(notification);
});

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

Expand All @@ -124,7 +123,7 @@ export class NotificationHistoryComponent implements OnDestroy, OnInit, AfterVie
});

this.badgeHidden = !this.isBadgeVisible();
this.storageService.setItem(NotificationHistoryComponent.NOTIFICATION_STORAGE, JSON.stringify(this.notifications));
this.storageService.setItem(NOTIFICATION_STORAGE, JSON.stringify(this.notifications));
this.paginatedNotifications = [];
this.createPagination();
this.trigger.closeMenu();
Expand Down
2 changes: 2 additions & 0 deletions lib/core/src/lib/notifications/models/notification.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,5 @@ export interface NotificationModel {
args?: any;
read?: boolean;
}

export const NOTIFICATION_STORAGE = 'notification-history';

0 comments on commit 98f63a9

Please sign in to comment.