1- /* tslint:disable:no-unused-variable */
1+ import 'hammerjs' ;
2+ import { NO_ERRORS_SCHEMA } from '@angular/core' ;
23import { async , ComponentFixture , TestBed } from '@angular/core/testing' ;
34import { By } from '@angular/platform-browser' ;
45import { DebugElement } from '@angular/core' ;
6+ import { Observable } from 'rxjs/Observable' ;
57import { MaterialModule } from '@angular/material' ;
68import { reducer } from '../../reducers' ;
79import { StoreModule } from '@ngrx/store' ;
@@ -11,25 +13,63 @@ import { UsersComponent } from './users.component';
1113describe ( 'UsersComponent' , ( ) => {
1214 let component : UsersComponent ;
1315 let fixture : ComponentFixture < UsersComponent > ;
16+ let debugs : DebugElement [ ] ;
17+ let element : HTMLElement ;
18+ const users : any = Observable . of ( [ {
19+ url : 'http://localhost/nirgalon' ,
20+ username : 'Nir Galon' ,
21+ 22+ groups : [ 'admin' ]
23+ } , {
24+ url : 'http://localhost/adisaar' ,
25+ username : 'Adi Saar' ,
26+ email : '' ,
27+ groups : [ 'users' ]
28+ } ] ) ;
1429
1530 beforeEach ( async ( ( ) => {
1631 TestBed . configureTestingModule ( {
1732 imports : [
18- MaterialModule . forRoot ( ) ,
33+ MaterialModule ,
1934 StoreModule . provideStore ( reducer )
2035 ] ,
21- declarations : [ UsersComponent ]
36+ declarations : [ UsersComponent ] ,
37+ schemas : [ NO_ERRORS_SCHEMA ]
2238 } )
2339 . compileComponents ( ) ;
2440 } ) ) ;
2541
2642 beforeEach ( ( ) => {
2743 fixture = TestBed . createComponent ( UsersComponent ) ;
2844 component = fixture . componentInstance ;
45+
46+ // Create a dummy transaction.
47+ component . user$ = users ;
2948 fixture . detectChanges ( ) ;
3049 } ) ;
3150
3251 it ( 'should create' , ( ) => {
3352 expect ( component ) . toBeTruthy ( ) ;
3453 } ) ;
54+
55+ it ( 'should display first user email' , ( ) => {
56+ element = fixture . debugElement . query ( By . css ( 'md-card-subtitle' ) ) . nativeElement ;
57+ expect ( element . textContent ) . toContain ( '[email protected] ' ) ; 58+ } ) ;
59+
60+ it ( 'should display users name' , ( ) => {
61+ debugs = fixture . debugElement . queryAll ( By . css ( 'md-card-title' ) ) ;
62+ debugs . forEach ( ( elem , index ) => {
63+ element = elem . nativeElement ;
64+ expect ( element . textContent ) . toContain ( users . value [ index ] . username ) ;
65+ } ) ;
66+ } ) ;
67+
68+ it ( 'should display the users url links' , ( ) => {
69+ debugs = fixture . debugElement . queryAll ( By . css ( 'md-card-content > p' ) ) ;
70+ debugs . forEach ( ( elem , index ) => {
71+ element = elem . nativeElement ;
72+ expect ( element . textContent ) . toContain ( users . value [ index ] . url ) ;
73+ } ) ;
74+ } ) ;
3575} ) ;
0 commit comments