import { ToastrModule } from 'ngx-toastr';
import { configureTestBed, i18nProviders } from '../../../../testing/unit-test-helper';
+import { CdNotification, CdNotificationConfig } from '../../../shared/models/cd-notification';
import { ExecutingTask } from '../../../shared/models/executing-task';
+import { NotificationService } from '../../../shared/services/notification.service';
import { SummaryService } from '../../../shared/services/summary.service';
import { SharedModule } from '../../../shared/shared.module';
import { NotificationsComponent } from './notifications.component';
let component: NotificationsComponent;
let fixture: ComponentFixture<NotificationsComponent>;
let summaryService: SummaryService;
+ let notificationService: NotificationService;
configureTestBed({
imports: [HttpClientTestingModule, SharedModule, ToastrModule.forRoot(), RouterTestingModule],
fixture = TestBed.createComponent(NotificationsComponent);
component = fixture.componentInstance;
summaryService = TestBed.get(SummaryService);
+ notificationService = TestBed.get(NotificationService);
fixture.detectChanges();
});
expect(component.hasRunningTasks).toBeTruthy();
});
+
+ it('should create a dot if there are running notifications', () => {
+ const notification = new CdNotification(new CdNotificationConfig());
+ const recent = notificationService['dataSource'].getValue();
+ recent.push(notification);
+ notificationService['dataSource'].next(recent);
+ expect(component.hasNotifications).toBeTruthy();
+ fixture.detectChanges();
+ const dot = fixture.debugElement.nativeElement.querySelector('.dot');
+ expect(dot).not.toBe('');
+ });
});
import { Subscription } from 'rxjs';
import { Icons } from '../../../shared/enum/icons.enum';
+import { CdNotification } from '../../../shared/models/cd-notification';
import { NotificationService } from '../../../shared/services/notification.service';
import { SummaryService } from '../../../shared/services/summary.service';
export class NotificationsComponent implements OnInit, OnDestroy {
icons = Icons;
hasRunningTasks = false;
+ hasNotifications = false;
private subs = new Subscription();
constructor(
this.hasRunningTasks = summary.executing_tasks.length > 0;
})
);
+
+ this.subs.add(
+ this.notificationService.data$.subscribe((notifications: CdNotification[]) => {
+ this.hasNotifications = notifications.length > 0;
+ })
+ );
}
ngOnDestroy(): void {