@@ -16,7 +16,7 @@ describe('TOH Http Chapter', function () {
16
16
myHeroesHref : hrefEles . get ( 1 ) ,
17
17
myHeroesParent : element ( by . css ( 'my-app my-heroes' ) ) ,
18
18
allHeroes : element . all ( by . css ( 'my-app my-heroes li .hero-element' ) ) ,
19
-
19
+
20
20
firstDeleteButton : element . all ( by . buttonText ( 'Delete' ) ) . get ( 0 ) ,
21
21
22
22
addButton : element . all ( by . buttonText ( 'Add New Hero' ) ) . get ( 0 ) ,
@@ -28,21 +28,21 @@ describe('TOH Http Chapter', function () {
28
28
it ( 'should be able to add a hero from the "Heroes" view' , function ( ) {
29
29
var page = getPageStruct ( ) ;
30
30
var heroCount ;
31
-
31
+
32
32
page . myHeroesHref . click ( ) . then ( function ( ) {
33
33
browser . waitForAngular ( ) ;
34
34
heroCount = page . allHeroes . count ( ) ;
35
- expect ( heroCount ) . toBe ( 4 , 'should show 4 ' ) ;
35
+ expect ( heroCount ) . toBe ( 10 , 'should show 10 ' ) ;
36
36
} ) . then ( function ( ) {
37
37
return page . addButton . click ( ) ;
38
38
} ) . then ( function ( ) {
39
39
return save ( page , '' , 'The New Hero' ) ;
40
40
} ) . then ( function ( ) {
41
41
browser . waitForAngular ( ) ;
42
-
42
+
43
43
heroCount = page . allHeroes . count ( ) ;
44
- expect ( heroCount ) . toBe ( 5 , 'should show 5 ' ) ;
45
-
44
+ expect ( heroCount ) . toBe ( 11 , 'should show 11 ' ) ;
45
+
46
46
var newHero = element ( by . xpath ( '//span[@class="hero-element" and contains(text(),"The New Hero")]' ) ) ;
47
47
expect ( newHero ) . toBeDefined ( ) ;
48
48
} ) ;
@@ -51,17 +51,17 @@ describe('TOH Http Chapter', function () {
51
51
it ( 'should be able to delete hero from "Heroes" view' , function ( ) {
52
52
var page = getPageStruct ( ) ;
53
53
var heroCount ;
54
-
54
+
55
55
page . myHeroesHref . click ( ) . then ( function ( ) {
56
56
browser . waitForAngular ( ) ;
57
57
heroCount = page . allHeroes . count ( ) ;
58
- expect ( heroCount ) . toBe ( 4 , 'should show 4 ' ) ;
58
+ expect ( heroCount ) . toBe ( 10 , 'should show 10 ' ) ;
59
59
} ) . then ( function ( ) {
60
60
return page . firstDeleteButton . click ( ) ;
61
61
} ) . then ( function ( ) {
62
62
browser . waitForAngular ( ) ;
63
63
heroCount = page . allHeroes . count ( ) ;
64
- expect ( heroCount ) . toBe ( 3 , 'should show 3 ' ) ;
64
+ expect ( heroCount ) . toBe ( 9 , 'should show 9 ' ) ;
65
65
} ) ;
66
66
} ) ;
67
67
@@ -71,7 +71,7 @@ describe('TOH Http Chapter', function () {
71
71
var heroEle = page . topHeroes . get ( 2 ) ;
72
72
var heroDescrEle = heroEle . element ( by . css ( 'h4' ) ) ;
73
73
var heroDescr ;
74
-
74
+
75
75
return heroDescrEle . getText ( ) . then ( function ( text ) {
76
76
heroDescr = text ;
77
77
return heroEle . click ( ) ;
@@ -89,10 +89,10 @@ describe('TOH Http Chapter', function () {
89
89
90
90
it ( 'should be able to save details from "Heroes" view' , function ( ) {
91
91
var page = getPageStruct ( ) ;
92
-
92
+
93
93
var viewDetailsButtonEle = page . myHeroesParent . element ( by . cssContainingText ( 'button' , 'View Details' ) ) ;
94
94
var heroEle , heroDescr ;
95
-
95
+
96
96
page . myHeroesHref . click ( ) . then ( function ( ) {
97
97
expect ( page . myDashboardParent . isPresent ( ) ) . toBe ( false , 'dashboard element should NOT be present' ) ;
98
98
expect ( page . myHeroesParent . isPresent ( ) ) . toBe ( true , 'myHeroes element should be present' ) ;
@@ -130,4 +130,94 @@ describe('TOH Http Chapter', function () {
130
130
return saveButtonEle . click ( ) ;
131
131
} ) ;
132
132
}
133
+
134
+ it ( 'should be able to see the start screen' , function ( ) {
135
+ var page = getPageStruct ( ) ;
136
+ expect ( page . hrefs . count ( ) ) . toEqual ( 2 , 'should be two dashboard choices' ) ;
137
+ expect ( page . myDashboardHref . getText ( ) ) . toEqual ( "Dashboard" ) ;
138
+ expect ( page . myHeroesHref . getText ( ) ) . toEqual ( "Heroes" ) ;
139
+ } ) ;
140
+
141
+ it ( 'should be able to see dashboard choices' , function ( ) {
142
+ var page = getPageStruct ( ) ;
143
+ expect ( page . topHeroes . count ( ) ) . toBe ( 4 , "should be 4 dashboard hero choices" ) ;
144
+ } ) ;
145
+
146
+ it ( 'should be able to toggle the views' , function ( ) {
147
+ var page = getPageStruct ( ) ;
148
+
149
+ expect ( page . myDashboardParent . element ( by . css ( 'h3' ) ) . getText ( ) ) . toEqual ( 'Top Heroes' ) ;
150
+ page . myHeroesHref . click ( ) . then ( function ( ) {
151
+ expect ( page . myDashboardParent . isPresent ( ) ) . toBe ( false , 'should no longer see dashboard element' ) ;
152
+ expect ( page . allHeroes . count ( ) ) . toBeGreaterThan ( 4 , "should be more than 4 heroes shown" ) ;
153
+ return page . myDashboardHref . click ( ) ;
154
+ } ) . then ( function ( ) {
155
+ expect ( page . myDashboardParent . isPresent ( ) ) . toBe ( true , 'should once again see the dashboard element' ) ;
156
+ } ) ;
157
+
158
+ } ) ;
159
+
160
+ it ( 'should be able to edit details from "Dashboard" view' , function ( ) {
161
+ var page = getPageStruct ( ) ;
162
+ expect ( page . myDashboardParent . isPresent ( ) ) . toBe ( true , 'dashboard element should be available' ) ;
163
+ var heroEle = page . topHeroes . get ( 3 ) ;
164
+ var heroDescrEle = heroEle . element ( by . css ( 'h4' ) ) ;
165
+ var heroDescr ;
166
+ return heroDescrEle . getText ( ) . then ( function ( text ) {
167
+ heroDescr = text ;
168
+ return heroEle . click ( ) ;
169
+ } ) . then ( function ( ) {
170
+ return editDetails ( page , heroDescr , '-foo' ) ;
171
+ } ) . then ( function ( ) {
172
+ expect ( page . myDashboardParent . isPresent ( ) ) . toBe ( true , 'dashboard element should be back' ) ;
173
+ expect ( heroDescrEle . getText ( ) ) . toEqual ( heroDescr + '-foo' ) ;
174
+ } ) ;
175
+ } ) ;
176
+
177
+ it ( 'should be able to edit details from "Heroes" view' , function ( ) {
178
+ var page = getPageStruct ( ) ;
179
+ expect ( page . myDashboardParent . isPresent ( ) ) . toBe ( true , 'dashboard element should be present' ) ;
180
+ var viewDetailsButtonEle = page . myHeroesParent . element ( by . cssContainingText ( 'button' , 'View Details' ) ) ;
181
+ var heroEle , heroDescr ;
182
+ page . myHeroesHref . click ( ) . then ( function ( ) {
183
+ expect ( page . myDashboardParent . isPresent ( ) ) . toBe ( false , 'dashboard element should NOT be present' ) ;
184
+ expect ( page . myHeroesParent . isPresent ( ) ) . toBe ( true , 'myHeroes element should be present' ) ;
185
+ expect ( viewDetailsButtonEle . isPresent ( ) ) . toBe ( false , 'viewDetails button should not yet be present' ) ;
186
+ heroEle = page . allHeroes . get ( 2 ) ;
187
+ return heroEle . getText ( ) ;
188
+ } ) . then ( function ( text ) {
189
+ // remove leading 'id' from the element
190
+ heroDescr = text . substr ( text . indexOf ( ' ' ) + 1 ) ;
191
+ return heroEle . click ( ) ;
192
+ } ) . then ( function ( ) {
193
+ expect ( viewDetailsButtonEle . isDisplayed ( ) ) . toBe ( true , 'viewDetails button should now be visible' ) ;
194
+ return viewDetailsButtonEle . click ( ) ;
195
+ } ) . then ( function ( ) {
196
+ return editDetails ( page , heroDescr , '-bar' ) ;
197
+ } ) . then ( function ( ) {
198
+ expect ( page . myHeroesParent . isPresent ( ) ) . toBe ( true , 'myHeroes element should be back' ) ;
199
+ expect ( heroEle . getText ( ) ) . toContain ( heroDescr + '-bar' ) ;
200
+ expect ( viewDetailsButtonEle . isPresent ( ) ) . toBe ( false , 'viewDetails button should again NOT be present' ) ;
201
+ } ) ;
202
+ } ) ;
203
+
204
+ function editDetails ( page , origValue , textToAdd ) {
205
+ expect ( page . myDashboardParent . isPresent ( ) ) . toBe ( false , 'dashboard element should NOT be present' ) ;
206
+ expect ( page . myHeroesParent . isPresent ( ) ) . toBe ( false , 'myHeroes element should NOT be present' ) ;
207
+ expect ( page . heroDetail . isDisplayed ( ) ) . toBe ( true , 'should be able to see hero-details' ) ;
208
+ var inputEle = page . heroDetail . element ( by . css ( 'input' ) ) ;
209
+ expect ( inputEle . isDisplayed ( ) ) . toBe ( true , 'should be able to see the input box' ) ;
210
+ var buttons = page . heroDetail . all ( by . css ( 'button' ) ) ;
211
+ var backButtonEle = buttons . get ( 0 ) ;
212
+ var saveButtonEle = buttons . get ( 1 ) ;
213
+ expect ( backButtonEle . isDisplayed ( ) ) . toBe ( true , 'should be able to see the back button' ) ;
214
+ expect ( saveButtonEle . isDisplayed ( ) ) . toBe ( true , 'should be able to see the save button' ) ;
215
+ var detailTextEle = page . heroDetail . element ( by . css ( 'div h2' ) ) ;
216
+ expect ( detailTextEle . getText ( ) ) . toContain ( origValue ) ;
217
+ return sendKeys ( inputEle , textToAdd ) . then ( function ( ) {
218
+ expect ( detailTextEle . getText ( ) ) . toContain ( origValue + textToAdd ) ;
219
+ return saveButtonEle . click ( ) ;
220
+ } ) ;
221
+ }
222
+
133
223
} ) ;
0 commit comments