Notifications test final

This commit is contained in:
Andrea Chiapparelli - 4Science
2018-04-05 17:35:49 +02:00
parent b03acc8a3f
commit 548aafcf62
11 changed files with 251 additions and 194 deletions

View File

@@ -0,0 +1,63 @@
import { async, ComponentFixture, inject, TestBed } from '@angular/core/testing';
import { BrowserModule } from '@angular/platform-browser';
import { ChangeDetectorRef } from '@angular/core';
import { NotificationsService } from '../notifications.service';
import { notificationsReducer } from '../notifications.reducers';
import { Store, StoreModule } from '@ngrx/store';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { NotificationsBoardComponent } from './notifications-board.component';
import { AppState } from '../../../app.reducer';
import { NotificationComponent } from '../notification/notification.component';
import { Notification } from '../models/notification.model';
import { NotificationType } from '../models/notification-type';
import { uniqueId } from 'lodash';
describe('LoadingComponent (inline template)', () => {
let comp: NotificationsBoardComponent;
let fixture: ComponentFixture<NotificationsBoardComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [
BrowserModule,
BrowserAnimationsModule,
StoreModule.forRoot({notificationsReducer})],
declarations: [NotificationsBoardComponent, NotificationComponent], // declare the test component
providers: [
NotificationsService,
ChangeDetectorRef]
}).compileComponents(); // compile template and css
}));
beforeEach(inject([NotificationsService, Store], (service: NotificationsService, store: Store<AppState>) => {
store
.subscribe((state) => {
const notifications = [
new Notification(uniqueId(), NotificationType.Success, 'title1', 'content1'),
new Notification(uniqueId(), NotificationType.Info, 'title2', 'content2')
];
state.notifications = notifications;
});
fixture = TestBed.createComponent(NotificationsBoardComponent);
comp = fixture.componentInstance;
comp.options = {
rtl: false,
position: ['top', 'right'],
maxStack: 5
};
fixture.detectChanges();
}));
it('should create', () => {
expect(comp).toBeTruthy();
});
it('should be 2 notifications', () => {
expect(comp.notifications.length).toBe(2);
});
})
;