| 
									
										
										
										
											2016-02-08 17:47:08 +01:00
										 |  |  | describe('Server Communication', function () { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   beforeAll(function () { | 
					
						
							|  |  |  |     browser.get(''); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-17 21:25:41 -07:00
										 |  |  |   describe('Tour of Heroes (Observable)', function () { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     var initialHeroCount = 4; | 
					
						
							|  |  |  |     var newHeroName = 'Mr. IQ'; | 
					
						
							|  |  |  |     var heroCountAfterAdd = 5; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     var heroListComp = element(by.tagName('hero-list')); | 
					
						
							|  |  |  |     var addButton = heroListComp.element(by.tagName('button')); | 
					
						
							|  |  |  |     var heroTags = heroListComp.all(by.tagName('li')); | 
					
						
							|  |  |  |     var heroNameInput = heroListComp.element(by.tagName('input')); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it('should exist', function() { | 
					
						
							| 
									
										
										
										
											2016-02-08 17:47:08 +01:00
										 |  |  |       expect(heroListComp).toBeDefined('<hero-list> must exist'); | 
					
						
							|  |  |  |     }); | 
					
						
							| 
									
										
										
										
											2016-05-17 21:25:41 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |     it('should display ' + initialHeroCount + ' heroes after init', function () { | 
					
						
							|  |  |  |       expect(heroTags.count()).toBe(initialHeroCount); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-02-08 17:47:08 +01:00
										 |  |  |     it('should not add hero with empty name', function () { | 
					
						
							|  |  |  |       expect(addButton).toBeDefined('"Add Hero" button must be defined'); | 
					
						
							|  |  |  |       addButton.click().then(function() { | 
					
						
							| 
									
										
										
										
											2016-05-17 21:25:41 -07:00
										 |  |  |         expect(heroTags.count()).toBe(initialHeroCount, 'No new hero should be added'); | 
					
						
							| 
									
										
										
										
											2016-02-08 17:47:08 +01:00
										 |  |  |       }); | 
					
						
							|  |  |  |     }) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it('should add a new hero to the list', function () { | 
					
						
							|  |  |  |       expect(heroNameInput).toBeDefined('<input> for hero name must exist'); | 
					
						
							|  |  |  |       expect(addButton).toBeDefined('"Add Hero" button must be defined'); | 
					
						
							| 
									
										
										
										
											2016-05-17 21:25:41 -07:00
										 |  |  |       sendKeys(heroNameInput, newHeroName); | 
					
						
							| 
									
										
										
										
											2016-02-08 17:47:08 +01:00
										 |  |  |       addButton.click().then(function() { | 
					
						
							| 
									
										
										
										
											2016-05-17 21:25:41 -07:00
										 |  |  |         expect(heroTags.count()).toBe(heroCountAfterAdd, 'A new hero should be added'); | 
					
						
							|  |  |  |         var newHeroInList = heroTags.get(heroCountAfterAdd - 1).getText(); | 
					
						
							|  |  |  |         expect(newHeroInList).toBe(newHeroName, 'The hero should be added to the end of the list'); | 
					
						
							| 
									
										
										
										
											2016-02-08 17:47:08 +01:00
										 |  |  |       }); | 
					
						
							|  |  |  |     }) | 
					
						
							|  |  |  |   }); | 
					
						
							| 
									
										
										
										
											2016-05-17 21:25:41 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |   describe('Wikipedia Demo', function () { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-02-08 17:47:08 +01:00
										 |  |  |     it('should initialize the demo with empty result list', function () { | 
					
						
							|  |  |  |       var myWikiComp = element(by.tagName('my-wiki')); | 
					
						
							|  |  |  |       expect(myWikiComp).toBeDefined('<my-wiki> must exist'); | 
					
						
							|  |  |  |       var resultList = myWikiComp.all(by.tagName('li')); | 
					
						
							|  |  |  |       expect(resultList.count()).toBe(0, 'result list must be empty'); | 
					
						
							|  |  |  |     }); | 
					
						
							| 
									
										
										
										
											2016-05-17 21:25:41 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-02-08 17:47:08 +01:00
										 |  |  |     describe('Fetches after each keystroke', function () { | 
					
						
							|  |  |  |       it('should fetch results after "B"', function(done) { | 
					
						
							|  |  |  |         testForRefreshedResult('B', done); | 
					
						
							|  |  |  |       }); | 
					
						
							| 
									
										
										
										
											2016-05-17 21:25:41 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-02-08 17:47:08 +01:00
										 |  |  |       it('should fetch results after "Ba"', function(done) { | 
					
						
							|  |  |  |         testForRefreshedResult('a', done); | 
					
						
							|  |  |  |       }); | 
					
						
							| 
									
										
										
										
											2016-05-17 21:25:41 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-02-08 17:47:08 +01:00
										 |  |  |       it('should fetch results after "Bas"', function(done) { | 
					
						
							|  |  |  |         testForRefreshedResult('s', done); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       it('should fetch results after "Basic"', function(done) { | 
					
						
							|  |  |  |         testForRefreshedResult('ic', done); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |     }); | 
					
						
							| 
									
										
										
										
											2016-05-17 21:25:41 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-02-08 17:47:08 +01:00
										 |  |  |     function testForRefreshedResult(keyPressed, done) { | 
					
						
							|  |  |  |       testForResult('my-wiki', keyPressed, false, done) | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   }); | 
					
						
							| 
									
										
										
										
											2016-05-17 21:25:41 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |   describe('Smarter Wikipedia Demo', function () { | 
					
						
							| 
									
										
										
										
											2016-02-08 17:47:08 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     it('should initialize the demo with empty result list', function () { | 
					
						
							|  |  |  |       var myWikiSmartComp = element(by.tagName('my-wiki-smart')); | 
					
						
							|  |  |  |       expect(myWikiSmartComp).toBeDefined('<my-wiki-smart> must exist'); | 
					
						
							|  |  |  |       var resultList = myWikiSmartComp.all(by.tagName('li')); | 
					
						
							|  |  |  |       expect(resultList.count()).toBe(0, 'result list must be empty'); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it('should fetch results after "Java"', function(done) { | 
					
						
							|  |  |  |       testForNewResult('Java', done); | 
					
						
							|  |  |  |     }); | 
					
						
							| 
									
										
										
										
											2016-05-17 21:25:41 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-02-08 17:47:08 +01:00
										 |  |  |     it('should fetch results after "JavaS"', function(done) { | 
					
						
							|  |  |  |       testForStaleResult('S', done); | 
					
						
							|  |  |  |     }); | 
					
						
							| 
									
										
										
										
											2016-05-17 21:25:41 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-02-08 17:47:08 +01:00
										 |  |  |     it('should fetch results after "JavaSc"', function(done) { | 
					
						
							|  |  |  |       testForStaleResult('c', done); | 
					
						
							|  |  |  |     }); | 
					
						
							| 
									
										
										
										
											2016-05-17 21:25:41 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-02-08 17:47:08 +01:00
										 |  |  |     it('should fetch results after "JavaScript"', function(done) { | 
					
						
							|  |  |  |       testForStaleResult('ript', done); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-17 21:25:41 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-02-08 17:47:08 +01:00
										 |  |  |     function testForNewResult(keyPressed, done) { | 
					
						
							|  |  |  |       testForResult('my-wiki-smart', keyPressed, false, done) | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     function testForStaleResult(keyPressed, done) { | 
					
						
							| 
									
										
										
										
											2016-05-17 21:25:41 -07:00
										 |  |  |       testForResult('my-wiki-smart', keyPressed, true, done) | 
					
						
							| 
									
										
										
										
											2016-02-08 17:47:08 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   }); | 
					
						
							| 
									
										
										
										
											2016-05-17 21:25:41 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-02-08 17:47:08 +01:00
										 |  |  |   function testForResult(componentTagName, keyPressed, hasListBeforeSearch, done) { | 
					
						
							|  |  |  |     var searchWait = 1000; // Wait for wikipedia but not so long that tests timeout
 | 
					
						
							|  |  |  |     var wikiComponent = element(by.tagName(componentTagName)); | 
					
						
							|  |  |  |     expect(wikiComponent).toBeDefined('<' + componentTagName + '> must exist'); | 
					
						
							|  |  |  |     var searchBox = wikiComponent.element(by.tagName('input')); | 
					
						
							|  |  |  |     expect(searchBox).toBeDefined('<input> for search must exist'); | 
					
						
							| 
									
										
										
										
											2016-05-17 21:25:41 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-02-08 17:47:08 +01:00
										 |  |  |     searchBox.sendKeys(keyPressed).then(function () { | 
					
						
							|  |  |  |       var resultList = wikiComponent.all(by.tagName('li')); | 
					
						
							| 
									
										
										
										
											2016-05-17 21:25:41 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-02-08 17:47:08 +01:00
										 |  |  |       if (hasListBeforeSearch) { | 
					
						
							|  |  |  |         expect(resultList.count()).toBeGreaterThan(0, 'result list should not be empty before search'); | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       setTimeout(function() { | 
					
						
							|  |  |  |         expect(resultList.count()).toBeGreaterThan(0, 'result list should not be empty after search'); | 
					
						
							|  |  |  |         done(); | 
					
						
							|  |  |  |       }, searchWait); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2016-05-17 21:25:41 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-02-08 17:47:08 +01:00
										 |  |  | }); |