notification.component.spec.ts (dspace-angular-dspace-7.0) | : | notification.component.spec.ts (dspace-angular-dspace-7.1) | ||
---|---|---|---|---|
import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing'; | import { ComponentFixture, fakeAsync, TestBed, tick, waitForAsync } from '@angul ar/core/testing'; | |||
import { BrowserModule, By } from '@angular/platform-browser'; | import { BrowserModule, By } from '@angular/platform-browser'; | |||
import { ChangeDetectorRef, DebugElement } from '@angular/core'; | import { ChangeDetectorRef, DebugElement } from '@angular/core'; | |||
import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; | import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; | |||
import { Store, StoreModule } from '@ngrx/store'; | import { Store, StoreModule } from '@ngrx/store'; | |||
import { NotificationComponent } from './notification.component'; | import { NotificationComponent } from './notification.component'; | |||
import { NotificationsService } from '../notifications.service'; | import { NotificationsService } from '../notifications.service'; | |||
import { NotificationType } from '../models/notification-type'; | import { NotificationType } from '../models/notification-type'; | |||
import { notificationsReducer } from '../notifications.reducers'; | import { notificationsReducer } from '../notifications.reducers'; | |||
import { NotificationOptions } from '../models/notification-options.model'; | import { NotificationOptions } from '../models/notification-options.model'; | |||
import { INotificationBoardOptions } from '../../../../config/notifications-conf ig.interfaces'; | import { INotificationBoardOptions } from '../../../../config/notifications-conf ig.interfaces'; | |||
import { GlobalConfig } from '../../../../config/global-config.interface'; | import { GlobalConfig } from '../../../../config/global-config.interface'; | |||
import { Notification } from '../models/notification.model'; | import { Notification } from '../models/notification.model'; | |||
import { TranslateLoader, TranslateModule, TranslateService } from '@ngx-transla te/core'; | import { TranslateLoader, TranslateModule, TranslateService } from '@ngx-transla te/core'; | |||
import { TranslateLoaderMock } from '../../mocks/translate-loader.mock'; | import { TranslateLoaderMock } from '../../mocks/translate-loader.mock'; | |||
import { storeModuleConfig } from '../../../app.reducer'; | import { storeModuleConfig } from '../../../app.reducer'; | |||
import { BehaviorSubject } from 'rxjs'; | ||||
describe('NotificationComponent', () => { | describe('NotificationComponent', () => { | |||
let comp: NotificationComponent; | let comp: NotificationComponent; | |||
let fixture: ComponentFixture<NotificationComponent>; | let fixture: ComponentFixture<NotificationComponent>; | |||
let deTitle: DebugElement; | let deTitle: DebugElement; | |||
let elTitle: HTMLElement; | let elTitle: HTMLElement; | |||
let deContent: DebugElement; | let deContent: DebugElement; | |||
let elContent: HTMLElement; | let elContent: HTMLElement; | |||
let elType: HTMLElement; | let elType: HTMLElement; | |||
skipping to change at line 86 | skipping to change at line 87 | |||
options: new NotificationOptions() | options: new NotificationOptions() | |||
}; | }; | |||
fixture.detectChanges(); | fixture.detectChanges(); | |||
deTitle = fixture.debugElement.query(By.css('.notification-title')); | deTitle = fixture.debugElement.query(By.css('.notification-title')); | |||
elTitle = deTitle.nativeElement; | elTitle = deTitle.nativeElement; | |||
deContent = fixture.debugElement.query(By.css('.notification-content')); | deContent = fixture.debugElement.query(By.css('.notification-content')); | |||
elContent = deContent.nativeElement; | elContent = deContent.nativeElement; | |||
elType = fixture.debugElement.query(By.css('.notification-icon')).nativeElem ent; | elType = fixture.debugElement.query(By.css('.notification-icon')).nativeElem ent; | |||
spyOn(comp, 'remove'); | ||||
}); | }); | |||
it('should create component', () => { | it('should create component', () => { | |||
expect(comp).toBeTruthy(); | expect(comp).toBeTruthy(); | |||
}); | }); | |||
it('should set Title', () => { | it('should set Title', () => { | |||
fixture.detectChanges(); | fixture.detectChanges(); | |||
expect(elTitle.textContent).toBe(comp.notification.title as string); | expect(elTitle.textContent).toBe(comp.notification.title as string); | |||
}); | }); | |||
skipping to change at line 127 | skipping to change at line 130 | |||
html: true | html: true | |||
}; | }; | |||
fixture.detectChanges(); | fixture.detectChanges(); | |||
deContent = fixture.debugElement.query(By.css('.notification-html')); | deContent = fixture.debugElement.query(By.css('.notification-html')); | |||
elContent = deContent.nativeElement; | elContent = deContent.nativeElement; | |||
expect(elContent.innerHTML).toEqual(htmlContent); | expect(elContent.innerHTML).toEqual(htmlContent); | |||
}); | }); | |||
describe('dismiss countdown', () => { | ||||
const TIMEOUT = 5000; | ||||
let isPaused$: BehaviorSubject<boolean>; | ||||
beforeEach(() => { | ||||
isPaused$ = new BehaviorSubject<boolean>(false); | ||||
comp.isPaused$ = isPaused$; | ||||
comp.notification = { | ||||
id: '1', | ||||
type: NotificationType.Info, | ||||
title: 'Notif. title', | ||||
content: 'test', | ||||
options: Object.assign( | ||||
new NotificationOptions(), | ||||
{ timeout: TIMEOUT } | ||||
), | ||||
html: true | ||||
}; | ||||
}); | ||||
it('should remove notification after timeout', fakeAsync(() => { | ||||
comp.ngOnInit(); | ||||
tick(TIMEOUT); | ||||
expect(comp.remove).toHaveBeenCalled(); | ||||
})); | ||||
describe('isPaused$', () => { | ||||
it('should pause countdown on true', fakeAsync(() => { | ||||
comp.ngOnInit(); | ||||
tick(TIMEOUT / 2); | ||||
isPaused$.next(true); | ||||
tick(TIMEOUT); | ||||
expect(comp.remove).not.toHaveBeenCalled(); | ||||
})); | ||||
it('should resume paused countdown on false', fakeAsync(() => { | ||||
comp.ngOnInit(); | ||||
tick(TIMEOUT / 4); | ||||
isPaused$.next(true); | ||||
tick(TIMEOUT / 4); | ||||
isPaused$.next(false); | ||||
tick(TIMEOUT); | ||||
expect(comp.remove).toHaveBeenCalled(); | ||||
})); | ||||
}); | ||||
}); | ||||
}); | }); | |||
End of changes. 4 change blocks. | ||||
1 lines changed or deleted | 51 lines changed or added |