expect(component.selectedNotificationID()).toBe('1');
});
+ it('should re-select when query params change while a notification is already selected', () => {
+ queryParamsSubject.next({ id: '1' });
+ fixture.detectChanges();
+ expect(component.selectedNotificationID()).toBe('1');
+
+ queryParamsSubject.next({ id: '2' });
+ fixture.detectChanges();
+ expect(component.selectedNotificationID()).toBe('2');
+ expect(notificationService.markAsRead).toHaveBeenCalledWith('2');
+ });
+
it('should pre-select when navigating from toast view more link', () => {
dataSourceSubject.next(mockNotifications);
fixture.detectChanges();
this.sub.add(
this.route.queryParams.subscribe((params) => {
this._pendingId = params['id'] || null;
- this._tryPreselect(this.notificationService.getNotificationsSnapshot());
+ this._tryPreselect(this.notificationService.getNotificationsSnapshot(), true);
})
);
}
}
}
- private _tryPreselect(notifications: CdNotification[]): void {
- if (!this._pendingId || this.selectedNotificationID()) return;
+ private _tryPreselect(notifications: CdNotification[], force = false): void {
+ if (!this._pendingId || (!force && this.selectedNotificationID())) return;
const match = notifications.find((n) => n.id === this._pendingId);
if (match) {
this.selectedNotificationID.set(this._pendingId);