@@ -9,205 +9,205 @@ describe('Dependency Injection Tests', function () {
9
9
} ) ;
10
10
11
11
describe ( 'Cars:' , function ( ) {
12
-
12
+
13
13
it ( 'DI car displays as expected' , function ( ) {
14
14
expectedMsg = 'DI car with 4 cylinders and Flintstone tires.' ;
15
15
expect ( element ( by . css ( '#di' ) ) . getText ( ) ) . toEqual ( expectedMsg ) ;
16
16
} ) ;
17
-
17
+
18
18
it ( 'No DI car displays as expected' , function ( ) {
19
- expectedMsg = 'No DI car with 4 cylinders and Flintstone tires.' ;
19
+ expectedMsg = 'No DI car with 4 cylinders and Flintstone tires.' ;
20
20
expect ( element ( by . css ( '#nodi' ) ) . getText ( ) ) . toEqual ( expectedMsg ) ;
21
21
} ) ;
22
-
22
+
23
23
it ( 'Injector car displays as expected' , function ( ) {
24
- expectedMsg = 'Injector car with 4 cylinders and Flintstone tires.' ;
24
+ expectedMsg = 'Injector car with 4 cylinders and Flintstone tires.' ;
25
25
expect ( element ( by . css ( '#injector' ) ) . getText ( ) ) . toEqual ( expectedMsg ) ;
26
26
} ) ;
27
-
27
+
28
28
it ( 'Factory car displays as expected' , function ( ) {
29
- expectedMsg = 'Factory car with 4 cylinders and Flintstone tires.' ;
29
+ expectedMsg = 'Factory car with 4 cylinders and Flintstone tires.' ;
30
30
expect ( element ( by . css ( '#factory' ) ) . getText ( ) ) . toEqual ( expectedMsg ) ;
31
31
} ) ;
32
-
32
+
33
33
it ( 'Simple car displays as expected' , function ( ) {
34
- expectedMsg = 'Simple car with 4 cylinders and Flintstone tires.' ;
34
+ expectedMsg = 'Simple car with 4 cylinders and Flintstone tires.' ;
35
35
expect ( element ( by . css ( '#simple' ) ) . getText ( ) ) . toEqual ( expectedMsg ) ;
36
36
} ) ;
37
-
37
+
38
38
it ( 'Super car displays as expected' , function ( ) {
39
- expectedMsg = 'Super car with 12 cylinders and Flintstone tires.' ;
39
+ expectedMsg = 'Super car with 12 cylinders and Flintstone tires.' ;
40
40
expect ( element ( by . css ( '#super' ) ) . getText ( ) ) . toEqual ( expectedMsg ) ;
41
41
} ) ;
42
-
42
+
43
43
it ( 'Test car displays as expected' , function ( ) {
44
- expectedMsg = 'Test car with 8 cylinders and YokoGoodStone tires.' ;
44
+ expectedMsg = 'Test car with 8 cylinders and YokoGoodStone tires.' ;
45
45
expect ( element ( by . css ( '#test' ) ) . getText ( ) ) . toEqual ( expectedMsg ) ;
46
46
} ) ;
47
47
} ) ;
48
-
48
+
49
49
describe ( 'Other Injections:' , function ( ) {
50
50
it ( 'DI car displays as expected' , function ( ) {
51
- expectedMsg = 'DI car with 4 cylinders and Flintstone tires.' ;
51
+ expectedMsg = 'DI car with 4 cylinders and Flintstone tires.' ;
52
52
expect ( element ( by . css ( '#car' ) ) . getText ( ) ) . toEqual ( expectedMsg ) ;
53
53
} ) ;
54
54
55
55
it ( 'Hero displays as expected' , function ( ) {
56
- expectedMsg = 'Mr. Nice' ;
56
+ expectedMsg = 'Mr. Nice' ;
57
57
expect ( element ( by . css ( '#hero' ) ) . getText ( ) ) . toEqual ( expectedMsg ) ;
58
58
} ) ;
59
59
60
60
it ( 'Optional injection displays as expected' , function ( ) {
61
- expectedMsg = 'R.O.U.S.\'s? I don\'t think they exist!' ;
61
+ expectedMsg = 'R.O.U.S.\'s? I don\'t think they exist!' ;
62
62
expect ( element ( by . css ( '#rodent' ) ) . getText ( ) ) . toEqual ( expectedMsg ) ;
63
- } ) ;
63
+ } ) ;
64
64
} ) ;
65
-
65
+
66
66
describe ( 'Tests:' , function ( ) {
67
-
67
+
68
68
it ( 'Tests display as expected' , function ( ) {
69
69
expectedMsg = / T e s t s p a s s e d / ;
70
70
expect ( element ( by . css ( '#tests' ) ) . getText ( ) ) . toMatch ( expectedMsg ) ;
71
71
} ) ;
72
72
73
73
} ) ;
74
-
74
+
75
75
describe ( 'Provider variations:' , function ( ) {
76
-
76
+
77
77
it ( 'P1 (class) displays as expected' , function ( ) {
78
78
expectedMsg = 'Hello from logger provided with Logger class' ;
79
79
expect ( element ( by . css ( '#p1' ) ) . getText ( ) ) . toEqual ( expectedMsg ) ;
80
- } ) ;
81
-
80
+ } ) ;
81
+
82
82
it ( 'P2 (Provider) displays as expected' , function ( ) {
83
83
expectedMsg = 'Hello from logger provided with Provider class and useClass' ;
84
84
expect ( element ( by . css ( '#p2' ) ) . getText ( ) ) . toEqual ( expectedMsg ) ;
85
85
} ) ;
86
-
86
+
87
87
it ( 'P3 (provide) displays as expected' , function ( ) {
88
88
expectedMsg = 'Hello from logger provided with useClass' ;
89
89
expect ( element ( by . css ( '#p3' ) ) . getText ( ) ) . toEqual ( expectedMsg ) ;
90
90
} ) ;
91
-
91
+
92
92
it ( 'P4 (useClass:BetterLogger) displays as expected' , function ( ) {
93
93
expectedMsg = 'Hello from logger provided with useClass:BetterLogger' ;
94
94
expect ( element ( by . css ( '#p4' ) ) . getText ( ) ) . toEqual ( expectedMsg ) ;
95
95
} ) ;
96
-
96
+
97
97
it ( 'P5 (useClass:EvenBetterLogger - dependency) displays as expected' , function ( ) {
98
98
expectedMsg = 'Message to Bob: Hello from EvenBetterlogger.' ;
99
99
expect ( element ( by . css ( '#p5' ) ) . getText ( ) ) . toEqual ( expectedMsg ) ;
100
100
} ) ;
101
-
101
+
102
102
it ( 'P6a (no alias) displays as expected' , function ( ) {
103
103
expectedMsg = 'Hello OldLogger (but we want NewLogger)' ;
104
104
expect ( element ( by . css ( '#p6a' ) ) . getText ( ) ) . toEqual ( expectedMsg ) ;
105
105
} ) ;
106
-
106
+
107
107
it ( 'P6b (alias) displays as expected' , function ( ) {
108
108
expectedMsg = 'Hello from NewLogger (via aliased OldLogger)' ;
109
109
expect ( element ( by . css ( '#p6b' ) ) . getText ( ) ) . toEqual ( expectedMsg ) ;
110
110
} ) ;
111
-
111
+
112
112
it ( 'P7 (useValue) displays as expected' , function ( ) {
113
113
expectedMsg = 'Silent logger says "Shhhhh!". Provided via "useValue"' ;
114
114
expect ( element ( by . css ( '#p7' ) ) . getText ( ) ) . toEqual ( expectedMsg ) ;
115
115
} ) ;
116
-
116
+
117
117
it ( 'P8 (useFactory) displays as expected' , function ( ) {
118
118
expectedMsg = 'Hero service injected successfully' ;
119
119
expect ( element ( by . css ( '#p8' ) ) . getText ( ) ) . toEqual ( expectedMsg ) ;
120
120
} ) ;
121
-
121
+
122
122
it ( 'P9a (string token) displays as expected' , function ( ) {
123
123
expectedMsg = '"app.config" Application title is Dependency Injection' ;
124
124
expect ( element ( by . css ( '#p9a' ) ) . getText ( ) ) . toEqual ( expectedMsg ) ;
125
125
} ) ;
126
-
126
+
127
127
it ( 'P9b (OpaqueToken) displays as expected' , function ( ) {
128
128
expectedMsg = 'APP_CONFIG Application title is Dependency Injection' ;
129
129
expect ( element ( by . css ( '#p9b' ) ) . getText ( ) ) . toEqual ( expectedMsg ) ;
130
- } ) ;
131
-
130
+ } ) ;
131
+
132
132
it ( 'P10a (required dependency) displays as expected' , function ( ) {
133
133
expectedMsg = 'Hello from the required logger.' ;
134
134
expect ( element ( by . css ( '#p10a' ) ) . getText ( ) ) . toEqual ( expectedMsg ) ;
135
135
} ) ;
136
-
136
+
137
137
it ( 'P10b (optional dependency) displays as expected' , function ( ) {
138
138
expectedMsg = 'Optional logger was not available.' ;
139
139
expect ( element ( by . css ( '#p10b' ) ) . getText ( ) ) . toEqual ( expectedMsg ) ;
140
- } )
140
+ } )
141
141
} ) ;
142
-
142
+
143
143
describe ( 'User/Heroes:' , function ( ) {
144
144
it ( 'User is Bob - unauthorized' , function ( ) {
145
145
expectedMsg = / B o b , i s n o t a u t h o r i z e d / ;
146
146
expect ( element ( by . css ( '#user' ) ) . getText ( ) ) . toMatch ( expectedMsg ) ;
147
- } ) ;
148
-
147
+ } ) ;
148
+
149
149
it ( 'should have button' , function ( ) {
150
150
expect ( element . all ( by . cssContainingText ( 'button' , 'Next User' ) )
151
151
. get ( 0 ) . isDisplayed ( ) ) . toBe ( true , "'Next User' button should be displayed" ) ;
152
152
} ) ;
153
-
153
+
154
154
it ( 'unauthorized user should have multiple unauthorized heroes' , function ( ) {
155
155
var heroes = element . all ( by . css ( '#unauthorized hero-list div' ) ) ;
156
- expect ( heroes . count ( ) ) . toBeGreaterThan ( 0 ) ;
156
+ expect ( heroes . count ( ) ) . toBeGreaterThan ( 0 ) ;
157
157
} ) ;
158
-
158
+
159
159
it ( 'unauthorized user should have no secret heroes' , function ( ) {
160
160
var heroes = element . all ( by . css ( '#unauthorized hero-list div' ) ) ;
161
161
expect ( heroes . count ( ) ) . toBeGreaterThan ( 0 ) ;
162
-
162
+
163
163
heroes . filter ( function ( elem , index ) {
164
164
return elem . getText ( ) . then ( function ( text ) {
165
165
return / s e c r e t / . test ( text ) ;
166
166
} ) ;
167
167
} ) . then ( function ( filteredElements ) {
168
168
//console.log("******Secret heroes count: "+filteredElements.length);
169
169
expect ( filteredElements . length ) . toEqual ( 0 ) ;
170
- } ) ;
171
- } ) ;
172
-
173
- it ( 'unauthorized user should have no authorized heros listed' , function ( ) {
170
+ } ) ;
171
+ } ) ;
172
+
173
+ it ( 'unauthorized user should have no authorized heroes listed' , function ( ) {
174
174
expect ( element . all ( by . css ( '#authorized hero-list div' ) ) . count ( ) ) . toEqual ( 0 ) ;
175
175
} ) ;
176
-
176
+
177
177
describe ( 'after button click' , function ( ) {
178
-
178
+
179
179
beforeAll ( function ( done ) {
180
180
var buttonEle = element . all ( by . cssContainingText ( 'button' , 'Next User' ) ) . get ( 0 ) ;
181
181
buttonEle . click ( ) . then ( done , done ) ;
182
182
} ) ;
183
-
183
+
184
184
it ( 'User is Alice - authorized' , function ( ) {
185
185
expectedMsg = / A l i c e , i s a u t h o r i z e d / ;
186
186
expect ( element ( by . css ( '#user' ) ) . getText ( ) ) . toMatch ( expectedMsg ) ;
187
187
} ) ;
188
-
188
+
189
189
it ( 'authorized user should have multiple authorized heroes ' , function ( ) {
190
190
var heroes = element . all ( by . css ( '#authorized hero-list div' ) ) ;
191
- expect ( heroes . count ( ) ) . toBeGreaterThan ( 0 ) ;
191
+ expect ( heroes . count ( ) ) . toBeGreaterThan ( 0 ) ;
192
192
} ) ;
193
-
193
+
194
194
it ( 'authorized user should have secret heroes' , function ( ) {
195
195
var heroes = element . all ( by . css ( '#authorized hero-list div' ) ) ;
196
- expect ( heroes . count ( ) ) . toBeGreaterThan ( 0 ) ;
197
-
196
+ expect ( heroes . count ( ) ) . toBeGreaterThan ( 0 ) ;
197
+
198
198
heroes . filter ( function ( elem , index ) {
199
199
return elem . getText ( ) . then ( function ( text ) {
200
200
return / s e c r e t / . test ( text ) ;
201
201
} ) ;
202
202
} ) . then ( function ( filteredElements ) {
203
203
//console.log("******Secret heroes count: "+filteredElements.length);
204
204
expect ( filteredElements . length ) . toBeGreaterThan ( 0 ) ;
205
- } ) ;
206
- } ) ;
207
-
208
- it ( 'authorized user should have no unauthorized heros listed' , function ( ) {
205
+ } ) ;
206
+ } ) ;
207
+
208
+ it ( 'authorized user should have no unauthorized heroes listed' , function ( ) {
209
209
expect ( element . all ( by . css ( '#unauthorized hero-list div' ) ) . count ( ) ) . toEqual ( 0 ) ;
210
- } ) ;
210
+ } ) ;
211
211
} ) ;
212
- } ) ;
212
+ } ) ;
213
213
} ) ;
0 commit comments