blob: 8fea818cf471e4812a26af7c0a19c7e136452e3d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
import { HttpClientTestingModule } from '@angular/common/http/testing';
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { RouterTestingModule } from '@angular/router/testing';
import { ToastrModule } from 'ngx-toastr';
import { CdNotification, CdNotificationConfig } from '~/app/shared/models/cd-notification';
import { ExecutingTask } from '~/app/shared/models/executing-task';
import { NotificationService } from '~/app/shared/services/notification.service';
import { SummaryService } from '~/app/shared/services/summary.service';
import { SharedModule } from '~/app/shared/shared.module';
import { configureTestBed } from '~/testing/unit-test-helper';
import { NotificationsComponent } from './notifications.component';
describe('NotificationsComponent', () => {
let component: NotificationsComponent;
let fixture: ComponentFixture<NotificationsComponent>;
let summaryService: SummaryService;
let notificationService: NotificationService;
configureTestBed({
imports: [HttpClientTestingModule, SharedModule, ToastrModule.forRoot(), RouterTestingModule],
declarations: [NotificationsComponent]
});
beforeEach(() => {
fixture = TestBed.createComponent(NotificationsComponent);
component = fixture.componentInstance;
summaryService = TestBed.inject(SummaryService);
notificationService = TestBed.inject(NotificationService);
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
it('should subscribe and check if there are running tasks', () => {
expect(component.hasRunningTasks).toBeFalsy();
const task = new ExecutingTask('task', { name: 'name' });
summaryService['summaryDataSource'].next({ executing_tasks: [task] });
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('');
});
});
|