Fixed tests

This commit is contained in:
Giuseppe Digilio
2018-05-08 10:05:11 +02:00
parent 343e5e4f30
commit 7d38976ea0
4 changed files with 85 additions and 14 deletions

View File

@@ -25,30 +25,30 @@
<div class="d-flex flex-column justify-content-center align-content-stretch"> <div class="d-flex flex-column justify-content-center align-content-stretch">
<div class="p-2 mr-3" *ngIf="title"> <div class="p-2 mr-3" *ngIf="title">
<strong> <strong>
<div class="pl-1" *ngIf="titleIsTemplate; else regularTitle"> <div class="notification-title pl-1" *ngIf="titleIsTemplate; else regularTitle">
<ng-container *ngTemplateOutlet="title"></ng-container> <ng-container *ngTemplateOutlet="title"></ng-container>
</div> </div>
<ng-template #regularTitle> <ng-template #regularTitle>
<div class="pl-1" [innerHTML]="(title | async)"></div> <div class="notification-title pl-1" [innerHTML]="(title | async)"></div>
</ng-template> </ng-template>
</strong> </strong>
</div> </div>
<div class="p-2 mr-3" *ngIf="content"> <div class="p-2 mr-3" *ngIf="content">
<div class="pl-1" *ngIf="contentIsTemplate; else regularContent"> <div class="notification-content pl-1" *ngIf="contentIsTemplate; else regularContent">
<ng-container *ngTemplateOutlet="content"></ng-container> <ng-container *ngTemplateOutlet="content"></ng-container>
</div> </div>
<ng-template #regularContent> <ng-template #regularContent>
<div class="pl-1" [innerHTML]="(content | async)"></div> <div class="notification-content pl-1" [innerHTML]="(content | async)"></div>
</ng-template> </ng-template>
</div> </div>
<div class="p-2 mr-3" *ngIf="item.html"> <div class="p-2 mr-3" *ngIf="item.html">
<div class="pl-1" *ngIf="htmlIsTemplate; else regularHtml"> <div class="notification-html pl-1" *ngIf="htmlIsTemplate; else regularHtml">
<ng-container *ngTemplateOutlet="html"></ng-container> <ng-container *ngTemplateOutlet="html"></ng-container>
</div> </div>
<ng-template #regularHtml> <ng-template #regularHtml>
<div class="pl-1" [innerHTML]="html"></div> <div class="notification-html pl-1" [innerHTML]="html"></div>
</ng-template> </ng-template>
</div> </div>
</div> </div>

View File

@@ -1,4 +1,4 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing'; import { async, ComponentFixture, inject, TestBed } from '@angular/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';
@@ -6,9 +6,17 @@ 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 { StoreModule } from '@ngrx/store'; import { Store, StoreModule } from '@ngrx/store';
import { NotificationOptions } from '../models/notification-options.model'; import { NotificationOptions } from '../models/notification-options.model';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { Router } from '@angular/router';
import { NotificationsServiceStub } from '../../testing/notifications-service-stub';
import { AppState } from '../../../app.reducer';
import { Observable } from 'rxjs/Observable';
import { SearchPageComponent } from '../../../+search-page/search-page.component';
import { INotificationBoardOptions } from '../../../../config/notifications-config.interfaces';
import { GlobalConfig } from '../../../../config/global-config.interface';
import { Notification } from '../models/notification.model';
describe('NotificationComponent', () => { describe('NotificationComponent', () => {
@@ -21,6 +29,22 @@ describe('NotificationComponent', () => {
let elType: HTMLElement; let elType: HTMLElement;
beforeEach(async(() => { beforeEach(async(() => {
const store: Store<Notification> = jasmine.createSpyObj('store', {
/* tslint:disable:no-empty */
notifications: []
});
const envConfig: GlobalConfig = {
notifications: {
rtl: false,
position: ['top', 'right'],
maxStack: 8,
timeOut: 5000,
clickToClose: true,
animate: 'scale'
}as INotificationBoardOptions,
} as any;
const service = new NotificationsService(envConfig, store);
TestBed.configureTestingModule({ TestBed.configureTestingModule({
imports: [ imports: [
BrowserModule, BrowserModule,
@@ -28,12 +52,12 @@ describe('NotificationComponent', () => {
StoreModule.forRoot({notificationsReducer})], StoreModule.forRoot({notificationsReducer})],
declarations: [NotificationComponent], // declare the test component declarations: [NotificationComponent], // declare the test component
providers: [ providers: [
NotificationsService, { provide: NotificationsService, useValue: service },
ChangeDetectorRef] ChangeDetectorRef]
}).compileComponents(); // compile template and css }).compileComponents(); // compile template and css
})); }));
beforeEach(() => { beforeEach(() => {
fixture = TestBed.createComponent(NotificationComponent); fixture = TestBed.createComponent(NotificationComponent);
comp = fixture.componentInstance; comp = fixture.componentInstance;
comp.item = { comp.item = {
@@ -46,11 +70,11 @@ describe('NotificationComponent', () => {
fixture.detectChanges(); fixture.detectChanges();
deTitle = fixture.debugElement.query(By.css('.sn-title')); deTitle = fixture.debugElement.query(By.css('.notification-title'));
elTitle = deTitle.nativeElement; elTitle = deTitle.nativeElement;
deContent = fixture.debugElement.query(By.css('.sn-content')); deContent = fixture.debugElement.query(By.css('.notification-content'));
elContent = deContent.nativeElement; elContent = deContent.nativeElement;
elType = fixture.debugElement.query(By.css('.fa-info')).nativeElement; elType = fixture.debugElement.query(By.css('.notification-icon')).nativeElement;
}); });
it('should create component', () => { it('should create component', () => {

View File

@@ -13,6 +13,7 @@ import { Notification } from '../models/notification.model';
import { NotificationType } from '../models/notification-type'; import { NotificationType } from '../models/notification-type';
import { uniqueId } from 'lodash'; import { uniqueId } from 'lodash';
import { INotificationBoardOptions } from '../../../../config/notifications-config.interfaces'; import { INotificationBoardOptions } from '../../../../config/notifications-config.interfaces';
import { NotificationsServiceStub } from '../../testing/notifications-service-stub';
describe('NotificationsBoardComponent', () => { describe('NotificationsBoardComponent', () => {
let comp: NotificationsBoardComponent; let comp: NotificationsBoardComponent;
@@ -26,7 +27,7 @@ describe('NotificationsBoardComponent', () => {
StoreModule.forRoot({notificationsReducer})], StoreModule.forRoot({notificationsReducer})],
declarations: [NotificationsBoardComponent, NotificationComponent], // declare the test component declarations: [NotificationsBoardComponent, NotificationComponent], // declare the test component
providers: [ providers: [
NotificationsService, { provide: NotificationsService, useClass: NotificationsServiceStub },
ChangeDetectorRef] ChangeDetectorRef]
}).compileComponents(); // compile template and css }).compileComponents(); // compile template and css
})); }));

View File

@@ -0,0 +1,46 @@
import { Observable } from 'rxjs/Observable';
import { INotification } from '../notifications/models/notification.model';
import { NotificationOptions } from '../notifications/models/notification-options.model';
export class NotificationsServiceStub {
success(title: any = Observable.of(''),
content: any = Observable.of(''),
options: NotificationOptions = this.getDefaultOptions(),
html?: any): INotification {
return
}
error(title: any = Observable.of(''),
content: any = Observable.of(''),
options: NotificationOptions = this.getDefaultOptions(),
html?: any): INotification {
return
}
info(title: any = Observable.of(''),
content: any = Observable.of(''),
options: NotificationOptions = this.getDefaultOptions(),
html?: any): INotification {
return
}
warning(title: any = Observable.of(''),
content: any = Observable.of(''),
options: NotificationOptions = this.getDefaultOptions(),
html?: any): INotification {
return
}
remove(notification: INotification) {
return
}
removeAll() {
return
}
private getDefaultOptions(): NotificationOptions {
return new NotificationOptions();
}
}