1
- import {
2
- CUSTOM_ELEMENTS_SCHEMA ,
3
- Component ,
4
- } from '@angular/core' ;
1
+ import { Component } from '@angular/core' ;
5
2
import {
6
3
ComponentFixture ,
7
4
TestBed ,
8
5
waitForAsync ,
9
6
} from '@angular/core/testing' ;
10
7
import { By } from '@angular/platform-browser' ;
11
8
import { RouterTestingModule } from '@angular/router/testing' ;
12
- import { FontAwesomeModule } from '@fortawesome/angular-fontawesome' ;
13
- import {
14
- StoreModule ,
15
- Store ,
16
- } from '@ngrx/store' ;
9
+ import { BehaviorSubject } from 'rxjs' ;
10
+
11
+ import { DaffRouterDataService } from '@daffodil/router' ;
17
12
18
13
import { DaffioNavHeaderContainer } from './header.component' ;
19
- import { ToggleSidebar } from '../../sidebar/actions/sidebar.actions' ;
20
- import * as fromSidebar from '../../sidebar/reducers/index' ;
14
+ import { DAFFIO_NAV_SIDEBAR_ID } from './sidebar-id' ;
15
+ import { DaffioRoute } from '../../router/route.type' ;
16
+ import { DaffioSidebarService } from '../../sidebar/services/sidebar.service' ;
17
+ import { DaffioNavLink } from '../link/type' ;
21
18
22
19
@Component ( {
23
20
template : '<daffio-nav-header-container></daffio-nav-header-container>' ,
@@ -32,28 +29,44 @@ describe('DaffioNavHeaderContainer', () => {
32
29
let component : WrapperComponent ;
33
30
let fixture : ComponentFixture < WrapperComponent > ;
34
31
let daffioHeaderContainer : DaffioNavHeaderContainer ;
35
-
36
- let store : Store < fromSidebar . State > ;
32
+ let dataSpy : BehaviorSubject < DaffioRoute [ 'data' ] > ;
33
+ let sidebarServiceSpy : jasmine . SpyObj < DaffioSidebarService > ;
34
+ let links : Array < DaffioNavLink > ;
37
35
38
36
beforeEach ( waitForAsync ( ( ) => {
37
+ dataSpy = new BehaviorSubject ( { } ) ;
38
+ sidebarServiceSpy = jasmine . createSpyObj ( 'DaffioSidebarService' , [ 'open' ] ) ;
39
+
39
40
TestBed . configureTestingModule ( {
40
41
imports : [
41
- StoreModule . forRoot ( { } ) ,
42
42
RouterTestingModule ,
43
43
WrapperComponent ,
44
44
] ,
45
- schemas : [
46
- CUSTOM_ELEMENTS_SCHEMA ,
45
+ providers : [
46
+ {
47
+ provide : DaffRouterDataService ,
48
+ useValue : jasmine . createSpyObj ( 'DaffRouterDataService' , [ ] , { data$ : dataSpy } ) ,
49
+ } ,
50
+ {
51
+ provide : DaffioSidebarService ,
52
+ useValue : sidebarServiceSpy ,
53
+ } ,
47
54
] ,
48
55
} )
49
56
. compileComponents ( ) ;
57
+
58
+ links = [
59
+ { title : 'title1' , url : 'url1' } ,
60
+ { title : 'title2' , url : 'url2' } ,
61
+ ] ;
62
+ dataSpy . next ( {
63
+ daffioNavLinks : links ,
64
+ } ) ;
50
65
} ) ) ;
51
66
52
67
beforeEach ( ( ) => {
53
68
fixture = TestBed . createComponent ( WrapperComponent ) ;
54
69
component = fixture . componentInstance ;
55
- store = TestBed . inject ( Store ) ;
56
- spyOn ( store , 'dispatch' ) ;
57
70
fixture . detectChanges ( ) ;
58
71
59
72
daffioHeaderContainer = fixture . debugElement . query ( By . css ( 'daffio-nav-header-container' ) ) . componentInstance ;
@@ -63,12 +76,19 @@ describe('DaffioNavHeaderContainer', () => {
63
76
expect ( component ) . toBeTruthy ( ) ;
64
77
} ) ;
65
78
79
+ it ( 'should render the links' , ( ) => {
80
+ fixture . debugElement . queryAll ( By . css ( 'a[daffioHeaderItem]' ) ) . forEach ( ( de , i ) => {
81
+ expect ( de . attributes [ 'ng-reflect-router-link' ] ) . toEqual ( links [ i ] . url ) ;
82
+ expect ( de . nativeElement . innerText ) . toEqual ( links [ i ] . title ) ;
83
+ } ) ;
84
+ } ) ;
85
+
66
86
describe ( 'when [sidebar-button] is clicked' , ( ) => {
67
- it ( 'should call store.dispatch with a ToggleSidebar action ' , ( ) => {
87
+ it ( 'should open the nav sidebar ' , ( ) => {
68
88
const sidebarButton = fixture . debugElement . query ( By . css ( '[sidebar-button]' ) ) . nativeElement ;
69
89
sidebarButton . click ( ) ;
70
90
71
- expect ( store . dispatch ) . toHaveBeenCalledWith ( new ToggleSidebar ( ) ) ;
91
+ expect ( sidebarServiceSpy . open ) . toHaveBeenCalledWith ( DAFFIO_NAV_SIDEBAR_ID ) ;
72
92
} ) ;
73
93
} ) ;
74
94
} ) ;
0 commit comments