1
1
import {
2
2
Component ,
3
3
Input ,
4
- Injectable ,
5
4
} from '@angular/core' ;
6
5
import {
7
6
ComponentFixture ,
8
7
TestBed ,
9
8
waitForAsync ,
10
9
} from '@angular/core/testing' ;
11
10
import { By } from '@angular/platform-browser' ;
12
- import { ActivatedRoute } from '@angular/router' ;
13
11
import { RouterTestingModule } from '@angular/router/testing' ;
14
- import { cold } from 'jasmine-marbles' ;
15
- import { BehaviorSubject } from 'rxjs' ;
12
+ import { of } from 'rxjs' ;
16
13
17
14
import { DaffioApiListPageComponent } from './api-list-page.component' ;
15
+ import { DaffioDocsIndexService } from '../../../services/index.service' ;
18
16
import { DaffioApiListComponent } from '../../components/api-list/api-list.component' ;
19
17
import { DaffioApiReference } from '../../models/api-reference' ;
20
18
21
- @Injectable ( { providedIn : 'root' } )
22
- class ActivatedRouteStub {
23
- data = new BehaviorSubject ( { } ) ;
24
- } ;
25
-
26
19
@Component ( {
27
20
template : '' ,
28
21
selector : 'daffio-api-list' ,
@@ -34,7 +27,7 @@ class MockDaffioApiListComponent {
34
27
describe ( 'DaffioApiListPageComponent' , ( ) => {
35
28
let component : DaffioApiListPageComponent ;
36
29
let fixture : ComponentFixture < DaffioApiListPageComponent > ;
37
- let activatedRoute : ActivatedRouteStub ;
30
+ let indexServiceSpy : jasmine . SpyObj < DaffioDocsIndexService > ;
38
31
39
32
const stubDocsList : DaffioApiReference = {
40
33
id : 'id' ,
@@ -62,6 +55,8 @@ describe('DaffioApiListPageComponent', () => {
62
55
} ;
63
56
64
57
beforeEach ( waitForAsync ( ( ) => {
58
+ indexServiceSpy = jasmine . createSpyObj ( 'DaffioDocsIndexService' , [ 'getList' ] ) ;
59
+
65
60
TestBed . configureTestingModule ( {
66
61
imports : [
67
62
RouterTestingModule ,
@@ -71,16 +66,17 @@ describe('DaffioApiListPageComponent', () => {
71
66
DaffioApiListPageComponent ,
72
67
] ,
73
68
providers : [
74
- { provide : ActivatedRoute , useExisting : ActivatedRouteStub } ,
69
+ {
70
+ provide : DaffioDocsIndexService ,
71
+ useValue : indexServiceSpy ,
72
+ } ,
75
73
] ,
76
74
} )
77
75
. compileComponents ( ) ;
78
76
} ) ) ;
79
77
80
78
beforeEach ( ( ) => {
81
- activatedRoute = TestBed . inject ( ActivatedRouteStub ) ;
82
- activatedRoute . data . next ( { reference : stubDocsList } ) ;
83
-
79
+ indexServiceSpy . getList . and . returnValue ( of ( stubDocsList ) ) ;
84
80
fixture = TestBed . createComponent ( DaffioApiListPageComponent ) ;
85
81
component = fixture . componentInstance ;
86
82
fixture . detectChanges ( ) ;
@@ -90,17 +86,10 @@ describe('DaffioApiListPageComponent', () => {
90
86
expect ( component ) . toBeTruthy ( ) ;
91
87
} ) ;
92
88
93
- it ( 'should initialize apiList$ from a route resolver' , ( ) => {
94
- const expected = cold ( 'b' , { b : stubDocsList } ) ;
95
- expect ( component . apiList$ ) . toBeObservable ( expected ) ;
96
- } ) ;
97
-
98
89
describe ( 'on <daffio-api-list>' , ( ) => {
99
90
let apiListComponent : DaffioApiListComponent ;
100
91
101
92
beforeEach ( ( ) => {
102
- activatedRoute . data . next ( { reference : stubDocsList } ) ;
103
- fixture . detectChanges ( ) ;
104
93
apiListComponent = fixture . debugElement . query ( By . css ( 'daffio-api-list' ) ) . componentInstance ;
105
94
} ) ;
106
95
0 commit comments