@@ -21,6 +21,13 @@ describe('HomeComponent', () => {
21
21
let fixture : ComponentFixture < HomeComponent > ;
22
22
let component :HomeComponent ;
23
23
let el : DebugElement ;
24
+ let coursesService : any ;
25
+
26
+ const beginnerCourses = setupCourses ( )
27
+ . filter ( course => course . category == 'BEGINNER' ) ;
28
+
29
+ const advancedCourses = setupCourses ( )
30
+ . filter ( course => course . category == 'ADVANCED' ) ;
24
31
25
32
beforeEach ( async ( ( ) => {
26
33
@@ -39,11 +46,14 @@ describe('HomeComponent', () => {
39
46
fixture = TestBed . createComponent ( HomeComponent ) ;
40
47
component = fixture . componentInstance ;
41
48
el = fixture . debugElement ;
49
+ coursesService = TestBed . get ( CoursesService ) ;
42
50
} ) ;
43
51
44
52
45
53
} ) ) ;
46
54
55
+
56
+
47
57
it ( "should create the component" , ( ) => {
48
58
49
59
expect ( component ) . toBeTruthy ( ) ;
@@ -53,21 +63,39 @@ describe('HomeComponent', () => {
53
63
54
64
it ( "should display only beginner courses" , ( ) => {
55
65
56
- pending ( ) ;
66
+ coursesService . findAllCourses . and . returnValue ( of ( beginnerCourses ) ) ;
67
+
68
+ fixture . detectChanges ( ) ;
69
+
70
+ const tabs = el . queryAll ( By . css ( ".mat-tab-label" ) ) ;
71
+
72
+ expect ( tabs . length ) . toBe ( 1 , "Unexpected number of tabs found" ) ;
57
73
58
74
} ) ;
59
75
60
76
61
77
it ( "should display only advanced courses" , ( ) => {
62
78
63
- pending ( ) ;
79
+ coursesService . findAllCourses . and . returnValue ( of ( advancedCourses ) ) ;
80
+
81
+ fixture . detectChanges ( ) ;
82
+
83
+ const tabs = el . queryAll ( By . css ( ".mat-tab-label" ) ) ;
84
+
85
+ expect ( tabs . length ) . toBe ( 1 , "Unexpected number of tabs found" ) ;
64
86
65
87
} ) ;
66
88
67
89
68
90
it ( "should display both tabs" , ( ) => {
69
91
70
- pending ( ) ;
92
+ coursesService . findAllCourses . and . returnValue ( of ( setupCourses ( ) ) ) ;
93
+
94
+ fixture . detectChanges ( ) ;
95
+
96
+ const tabs = el . queryAll ( By . css ( ".mat-tab-label" ) ) ;
97
+
98
+ expect ( tabs . length ) . toBe ( 2 , "Expected to find 2 tabs" ) ;
71
99
72
100
} ) ;
73
101
0 commit comments