@@ -4,69 +4,62 @@ describe('Server Communication', function () {
4
4
browser . get ( '' ) ;
5
5
} ) ;
6
6
7
- describe ( 'Tour of Heroes e2e tests' , function ( ) {
8
-
9
- var _initialHeroCount = 4 ;
10
- var _newHeroName = 'Mr. IQ' ;
11
- var _heroCountAfterAdd = 5 ;
12
-
13
- it ( 'should display ' + _initialHeroCount + ' heroes after init' , function ( ) {
14
- var myTohComp = element ( by . tagName ( 'my-toh' ) ) ;
15
- expect ( myTohComp ) . toBeDefined ( '<my-toh> must exist' ) ;
16
- var heroListComp = myTohComp . element ( by . tagName ( 'hero-list' ) ) ;
7
+ describe ( 'Tour of Heroes (Observable)' , function ( ) {
8
+
9
+ var initialHeroCount = 4 ;
10
+ var newHeroName = 'Mr. IQ' ;
11
+ var heroCountAfterAdd = 5 ;
12
+
13
+ var heroListComp = element ( by . tagName ( 'hero-list' ) ) ;
14
+ var addButton = heroListComp . element ( by . tagName ( 'button' ) ) ;
15
+ var heroTags = heroListComp . all ( by . tagName ( 'li' ) ) ;
16
+ var heroNameInput = heroListComp . element ( by . tagName ( 'input' ) ) ;
17
+
18
+ it ( 'should exist' , function ( ) {
17
19
expect ( heroListComp ) . toBeDefined ( '<hero-list> must exist' ) ;
18
- var heroTags = heroListComp . all ( by . tagName ( 'li' ) ) ;
19
- expect ( heroTags . count ( ) ) . toBe ( _initialHeroCount ) ;
20
20
} ) ;
21
-
21
+
22
+ it ( 'should display ' + initialHeroCount + ' heroes after init' , function ( ) {
23
+ expect ( heroTags . count ( ) ) . toBe ( initialHeroCount ) ;
24
+ } ) ;
25
+
22
26
it ( 'should not add hero with empty name' , function ( ) {
23
- var myTohComp = element ( by . tagName ( 'my-toh' ) ) ;
24
- expect ( myTohComp ) . toBeDefined ( '<my-toh> must exist' ) ;
25
- var addButton = myTohComp . element ( by . tagName ( 'button' ) ) ;
26
27
expect ( addButton ) . toBeDefined ( '"Add Hero" button must be defined' ) ;
27
28
addButton . click ( ) . then ( function ( ) {
28
- var heroListComp = myTohComp . element ( by . tagName ( 'hero-list' ) ) ;
29
- var heroTags = heroListComp . all ( by . tagName ( 'li' ) ) ;
30
- expect ( heroTags . count ( ) ) . toBe ( _initialHeroCount , 'No new hero should be added' ) ;
29
+ expect ( heroTags . count ( ) ) . toBe ( initialHeroCount , 'No new hero should be added' ) ;
31
30
} ) ;
32
31
} )
33
32
34
33
it ( 'should add a new hero to the list' , function ( ) {
35
- var myTohComp = element ( by . tagName ( 'my-toh' ) ) ;
36
- expect ( myTohComp ) . toBeDefined ( '<my-toh> must exist' ) ;
37
- var heroNameInput = myTohComp . element ( by . tagName ( 'input' ) ) ;
38
34
expect ( heroNameInput ) . toBeDefined ( '<input> for hero name must exist' ) ;
39
- var addButton = myTohComp . element ( by . tagName ( 'button' ) ) ;
40
35
expect ( addButton ) . toBeDefined ( '"Add Hero" button must be defined' ) ;
41
- sendKeys ( heroNameInput , _newHeroName ) ;
36
+ sendKeys ( heroNameInput , newHeroName ) ;
42
37
addButton . click ( ) . then ( function ( ) {
43
- var heroListComp = myTohComp . element ( by . tagName ( 'hero-list' ) ) ;
44
- var heroTags = heroListComp . all ( by . tagName ( 'li' ) ) ;
45
- expect ( heroTags . count ( ) ) . toBe ( _heroCountAfterAdd , 'A new hero should be added' ) ;
46
- var newHeroInList = heroTags . get ( _heroCountAfterAdd - 1 ) . getText ( ) ;
47
- expect ( newHeroInList ) . toBe ( _newHeroName , 'The hero should be added to the end of the list' ) ;
38
+ expect ( heroTags . count ( ) ) . toBe ( heroCountAfterAdd , 'A new hero should be added' ) ;
39
+ var newHeroInList = heroTags . get ( heroCountAfterAdd - 1 ) . getText ( ) ;
40
+ expect ( newHeroInList ) . toBe ( newHeroName , 'The hero should be added to the end of the list' ) ;
48
41
} ) ;
49
42
} )
50
43
} ) ;
51
-
52
- describe ( 'Wikipedia Demo e2e tests ' , function ( ) {
53
-
44
+
45
+ describe ( 'Wikipedia Demo' , function ( ) {
46
+
54
47
it ( 'should initialize the demo with empty result list' , function ( ) {
55
48
var myWikiComp = element ( by . tagName ( 'my-wiki' ) ) ;
56
49
expect ( myWikiComp ) . toBeDefined ( '<my-wiki> must exist' ) ;
57
50
var resultList = myWikiComp . all ( by . tagName ( 'li' ) ) ;
58
51
expect ( resultList . count ( ) ) . toBe ( 0 , 'result list must be empty' ) ;
59
52
} ) ;
60
-
53
+
61
54
describe ( 'Fetches after each keystroke' , function ( ) {
62
55
it ( 'should fetch results after "B"' , function ( done ) {
63
56
testForRefreshedResult ( 'B' , done ) ;
64
57
} ) ;
65
-
58
+
66
59
it ( 'should fetch results after "Ba"' , function ( done ) {
67
60
testForRefreshedResult ( 'a' , done ) ;
68
61
} ) ;
69
-
62
+
70
63
it ( 'should fetch results after "Bas"' , function ( done ) {
71
64
testForRefreshedResult ( 's' , done ) ;
72
65
} ) ;
@@ -75,13 +68,13 @@ describe('Server Communication', function () {
75
68
testForRefreshedResult ( 'ic' , done ) ;
76
69
} ) ;
77
70
} ) ;
78
-
71
+
79
72
function testForRefreshedResult ( keyPressed , done ) {
80
73
testForResult ( 'my-wiki' , keyPressed , false , done )
81
74
}
82
75
} ) ;
83
-
84
- describe ( 'Smarter Wikipedia Demo e2e tests ' , function ( ) {
76
+
77
+ describe ( 'Smarter Wikipedia Demo' , function ( ) {
85
78
86
79
it ( 'should initialize the demo with empty result list' , function ( ) {
87
80
var myWikiSmartComp = element ( by . tagName ( 'my-wiki-smart' ) ) ;
@@ -93,40 +86,40 @@ describe('Server Communication', function () {
93
86
it ( 'should fetch results after "Java"' , function ( done ) {
94
87
testForNewResult ( 'Java' , done ) ;
95
88
} ) ;
96
-
89
+
97
90
it ( 'should fetch results after "JavaS"' , function ( done ) {
98
91
testForStaleResult ( 'S' , done ) ;
99
92
} ) ;
100
-
93
+
101
94
it ( 'should fetch results after "JavaSc"' , function ( done ) {
102
95
testForStaleResult ( 'c' , done ) ;
103
96
} ) ;
104
-
97
+
105
98
it ( 'should fetch results after "JavaScript"' , function ( done ) {
106
99
testForStaleResult ( 'ript' , done ) ;
107
100
} ) ;
108
101
109
-
102
+
110
103
function testForNewResult ( keyPressed , done ) {
111
104
testForResult ( 'my-wiki-smart' , keyPressed , false , done )
112
105
}
113
106
114
107
function testForStaleResult ( keyPressed , done ) {
115
- testForResult ( 'my-wiki-smart' , keyPressed , true , done )
108
+ testForResult ( 'my-wiki-smart' , keyPressed , true , done )
116
109
}
117
110
118
111
} ) ;
119
-
112
+
120
113
function testForResult ( componentTagName , keyPressed , hasListBeforeSearch , done ) {
121
114
var searchWait = 1000 ; // Wait for wikipedia but not so long that tests timeout
122
115
var wikiComponent = element ( by . tagName ( componentTagName ) ) ;
123
116
expect ( wikiComponent ) . toBeDefined ( '<' + componentTagName + '> must exist' ) ;
124
117
var searchBox = wikiComponent . element ( by . tagName ( 'input' ) ) ;
125
118
expect ( searchBox ) . toBeDefined ( '<input> for search must exist' ) ;
126
-
119
+
127
120
searchBox . sendKeys ( keyPressed ) . then ( function ( ) {
128
121
var resultList = wikiComponent . all ( by . tagName ( 'li' ) ) ;
129
-
122
+
130
123
if ( hasListBeforeSearch ) {
131
124
expect ( resultList . count ( ) ) . toBeGreaterThan ( 0 , 'result list should not be empty before search' ) ;
132
125
}
@@ -137,5 +130,5 @@ describe('Server Communication', function () {
137
130
} , searchWait ) ;
138
131
} ) ;
139
132
}
140
-
133
+
141
134
} ) ;
0 commit comments