| 
									
										
										
										
											2016-10-20 00:02:47 -05:00
										 |  |  | 'use strict'; // necessary for es6 output in node
 | 
					
						
							| 
									
										
										
										
											2016-10-06 23:25:52 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | import { browser, element, by, ElementFinder } from 'protractor'; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-03 11:32:57 -08:00
										 |  |  | describe('Router', function () { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   beforeAll(function () { | 
					
						
							|  |  |  |     browser.get(''); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   function getPageStruct() { | 
					
						
							| 
									
										
										
										
											2016-06-01 18:11:58 +02:00
										 |  |  |     let hrefEles = element.all(by.css('my-app a')); | 
					
						
							| 
									
										
										
										
											2016-01-03 11:32:57 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  |     return { | 
					
						
							|  |  |  |       hrefs: hrefEles, | 
					
						
							| 
									
										
										
										
											2016-08-09 17:38:25 +01:00
										 |  |  |       routerParent: element(by.css('my-app > ng-component')), | 
					
						
							|  |  |  |       routerTitle: element(by.css('my-app > ng-component > h2')), | 
					
						
							| 
									
										
										
										
											2016-01-03 11:32:57 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  |       crisisHref: hrefEles.get(0), | 
					
						
							| 
									
										
										
										
											2016-08-09 17:38:25 +01:00
										 |  |  |       crisisList: element.all(by.css('my-app > ng-component > ng-component li')), | 
					
						
							| 
									
										
										
										
											2016-08-26 23:19:27 -05:00
										 |  |  |       crisisDetail: element(by.css('my-app > ng-component > ng-component > ng-component > div')), | 
					
						
							|  |  |  |       crisisDetailTitle: element(by.css('my-app > ng-component > ng-component > ng-component > div > h3')), | 
					
						
							| 
									
										
										
										
											2016-01-03 11:32:57 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  |       heroesHref: hrefEles.get(1), | 
					
						
							| 
									
										
										
										
											2016-08-09 17:38:25 +01:00
										 |  |  |       heroesList: element.all(by.css('my-app > ng-component li')), | 
					
						
							|  |  |  |       heroDetail: element(by.css('my-app > ng-component > div')), | 
					
						
							|  |  |  |       heroDetailTitle: element(by.css('my-app > ng-component > div > h3')), | 
					
						
							| 
									
										
										
										
											2016-01-03 11:32:57 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-17 22:55:36 -04:00
										 |  |  |       adminHref: hrefEles.get(2), | 
					
						
							| 
									
										
										
										
											2016-10-20 00:02:47 -05:00
										 |  |  |       adminPreloadList: element.all(by.css('my-app > ng-component > ng-component > ul > li')), | 
					
						
							|  |  |  |       loginHref: hrefEles.get(3), | 
					
						
							|  |  |  |       loginButton: element.all(by.css('my-app > ng-component > p > button')), | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-08 01:06:25 +02:00
										 |  |  |     }; | 
					
						
							| 
									
										
										
										
											2016-01-03 11:32:57 -08:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   it('should be able to see the start screen', function () { | 
					
						
							| 
									
										
										
										
											2016-05-30 11:05:09 -07:00
										 |  |  |     let page = getPageStruct(); | 
					
						
							| 
									
										
										
										
											2016-08-09 17:38:25 +01:00
										 |  |  |     expect(page.hrefs.count()).toEqual(4, 'should be 4 dashboard choices'); | 
					
						
							| 
									
										
										
										
											2016-06-08 01:06:25 +02:00
										 |  |  |     expect(page.crisisHref.getText()).toEqual('Crisis Center'); | 
					
						
							|  |  |  |     expect(page.heroesHref.getText()).toEqual('Heroes'); | 
					
						
							| 
									
										
										
										
											2016-08-26 23:19:27 -05:00
										 |  |  |     expect(page.adminHref.getText()).toEqual('Admin'); | 
					
						
							| 
									
										
										
										
											2016-06-17 22:55:36 -04:00
										 |  |  |     expect(page.loginHref.getText()).toEqual('Login'); | 
					
						
							| 
									
										
										
										
											2016-01-03 11:32:57 -08:00
										 |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   it('should be able to see crises center items', function () { | 
					
						
							| 
									
										
										
										
											2016-05-30 11:05:09 -07:00
										 |  |  |     let page = getPageStruct(); | 
					
						
							| 
									
										
										
										
											2016-08-09 17:38:25 +01:00
										 |  |  |     page.crisisHref.click().then(function() { | 
					
						
							|  |  |  |       expect(page.crisisList.count()).toBe(4, 'should be 4 crisis center entries at start'); | 
					
						
							|  |  |  |     }); | 
					
						
							| 
									
										
										
										
											2016-01-03 11:32:57 -08:00
										 |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   it('should be able to see hero items', function () { | 
					
						
							| 
									
										
										
										
											2016-05-30 11:05:09 -07:00
										 |  |  |     let page = getPageStruct(); | 
					
						
							| 
									
										
										
										
											2016-01-03 11:32:57 -08:00
										 |  |  |     page.heroesHref.click().then(function() { | 
					
						
							|  |  |  |       expect(page.routerTitle.getText()).toContain('HEROES'); | 
					
						
							| 
									
										
										
										
											2016-06-08 01:06:25 +02:00
										 |  |  |       expect(page.heroesList.count()).toBe(6, 'should be 6 heroes'); | 
					
						
							| 
									
										
										
										
											2016-01-03 11:32:57 -08:00
										 |  |  |     }); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   it('should be able to toggle the views', function () { | 
					
						
							| 
									
										
										
										
											2016-05-30 11:05:09 -07:00
										 |  |  |     let page = getPageStruct(); | 
					
						
							| 
									
										
										
										
											2016-01-03 11:32:57 -08:00
										 |  |  |     page.crisisHref.click().then(function() { | 
					
						
							| 
									
										
										
										
											2016-06-08 01:06:25 +02:00
										 |  |  |       expect(page.crisisList.count()).toBe(4, 'should be 4 crisis center entries'); | 
					
						
							| 
									
										
										
										
											2016-01-03 11:32:57 -08:00
										 |  |  |       return page.heroesHref.click(); | 
					
						
							|  |  |  |     }).then(function() { | 
					
						
							| 
									
										
										
										
											2016-06-08 01:06:25 +02:00
										 |  |  |       expect(page.heroesList.count()).toBe(6, 'should be 6 heroes'); | 
					
						
							| 
									
										
										
										
											2016-01-03 11:32:57 -08:00
										 |  |  |     }); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   it('should be able to edit and save details from the crisis center view', function () { | 
					
						
							| 
									
										
										
										
											2016-08-09 17:38:25 +01:00
										 |  |  |     let page = getPageStruct(); | 
					
						
							|  |  |  |     page.crisisHref.click().then(function() { | 
					
						
							|  |  |  |       crisisCenterEdit(2, true); | 
					
						
							|  |  |  |     }); | 
					
						
							| 
									
										
										
										
											2016-01-03 11:32:57 -08:00
										 |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-22 14:30:15 +01:00
										 |  |  |   xit('should be able to edit and cancel details from the crisis center view', function () { | 
					
						
							| 
									
										
										
										
											2016-08-09 17:38:25 +01:00
										 |  |  |     let page = getPageStruct(); | 
					
						
							|  |  |  |     page.crisisHref.click().then(function() { | 
					
						
							|  |  |  |       crisisCenterEdit(3, false); | 
					
						
							|  |  |  |     }); | 
					
						
							| 
									
										
										
										
											2016-01-03 11:32:57 -08:00
										 |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   it('should be able to edit and save details from the heroes view', function () { | 
					
						
							| 
									
										
										
										
											2016-05-30 11:05:09 -07:00
										 |  |  |     let page = getPageStruct(); | 
					
						
							| 
									
										
										
										
											2016-10-06 23:25:52 +01:00
										 |  |  |     let heroEle: ElementFinder; | 
					
						
							| 
									
										
										
										
											2016-06-01 18:11:58 +02:00
										 |  |  |     let heroText: string; | 
					
						
							| 
									
										
										
										
											2016-01-03 11:32:57 -08:00
										 |  |  |     page.heroesHref.click().then(function() { | 
					
						
							|  |  |  |       heroEle = page.heroesList.get(4); | 
					
						
							|  |  |  |       return heroEle.getText(); | 
					
						
							| 
									
										
										
										
											2016-10-06 23:25:52 +01:00
										 |  |  |     }).then(function(text: string) { | 
					
						
							| 
									
										
										
										
											2016-01-03 11:32:57 -08:00
										 |  |  |       expect(text.length).toBeGreaterThan(0, 'should have some text'); | 
					
						
							|  |  |  |       // remove leading id from text
 | 
					
						
							|  |  |  |       heroText = text.substr(text.indexOf(' ')).trim(); | 
					
						
							|  |  |  |       return heroEle.click(); | 
					
						
							|  |  |  |     }).then(function() { | 
					
						
							| 
									
										
										
										
											2016-06-08 01:06:25 +02:00
										 |  |  |       expect(page.heroesList.count()).toBe(0, 'should no longer see crisis center entries'); | 
					
						
							| 
									
										
										
										
											2016-01-03 11:32:57 -08:00
										 |  |  |       expect(page.heroDetail.isPresent()).toBe(true, 'should be able to see crisis detail'); | 
					
						
							|  |  |  |       expect(page.heroDetailTitle.getText()).toContain(heroText); | 
					
						
							| 
									
										
										
										
											2016-05-30 11:05:09 -07:00
										 |  |  |       let inputEle = page.heroDetail.element(by.css('input')); | 
					
						
							| 
									
										
										
										
											2016-10-06 23:25:52 +01:00
										 |  |  |       inputEle.sendKeys('-foo'); | 
					
						
							| 
									
										
										
										
											2016-01-03 11:32:57 -08:00
										 |  |  |       expect(page.heroDetailTitle.getText()).toContain(heroText + '-foo'); | 
					
						
							| 
									
										
										
										
											2016-05-30 11:05:09 -07:00
										 |  |  |       let buttonEle = page.heroDetail.element(by.css('button')); | 
					
						
							| 
									
										
										
										
											2016-01-03 11:32:57 -08:00
										 |  |  |       return buttonEle.click(); | 
					
						
							|  |  |  |     }).then(function() { | 
					
						
							|  |  |  |       expect(heroEle.getText()).toContain(heroText + '-foo'); | 
					
						
							| 
									
										
										
										
											2016-06-08 01:06:25 +02:00
										 |  |  |     }); | 
					
						
							| 
									
										
										
										
											2016-01-03 11:32:57 -08:00
										 |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-20 00:02:47 -05:00
										 |  |  |   it('should be able to see the preloaded modules', function () { | 
					
						
							|  |  |  |     let page = getPageStruct(); | 
					
						
							|  |  |  |     page.loginHref.click().then(function() { | 
					
						
							|  |  |  |       return page.loginButton.click(); | 
					
						
							|  |  |  |     }).then(function() { | 
					
						
							|  |  |  |       expect(page.adminPreloadList.count()).toBe(1, 'should be 1 preloaded module'); | 
					
						
							|  |  |  |       expect(page.adminPreloadList.first().getText()).toBe('crisis-center', 'first preload should be crisis center'); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-01 18:11:58 +02:00
										 |  |  |   function crisisCenterEdit(index: number, shouldSave: boolean) { | 
					
						
							| 
									
										
										
										
											2016-05-30 11:05:09 -07:00
										 |  |  |     let page = getPageStruct(); | 
					
						
							| 
									
										
										
										
											2016-10-06 23:25:52 +01:00
										 |  |  |     let crisisEle: ElementFinder; | 
					
						
							| 
									
										
										
										
											2016-06-01 18:11:58 +02:00
										 |  |  |     let crisisText: string; | 
					
						
							| 
									
										
										
										
											2016-05-03 12:19:50 -06:00
										 |  |  |     page.crisisHref.click() | 
					
						
							|  |  |  |     .then(function () { | 
					
						
							| 
									
										
										
										
											2016-01-03 11:32:57 -08:00
										 |  |  |       crisisEle = page.crisisList.get(index); | 
					
						
							|  |  |  |       return crisisEle.getText(); | 
					
						
							| 
									
										
										
										
											2016-10-06 23:25:52 +01:00
										 |  |  |     }).then(function(text: string) { | 
					
						
							| 
									
										
										
										
											2016-01-03 11:32:57 -08:00
										 |  |  |       expect(text.length).toBeGreaterThan(0, 'should have some text'); | 
					
						
							|  |  |  |       // remove leading id from text
 | 
					
						
							|  |  |  |       crisisText = text.substr(text.indexOf(' ')).trim(); | 
					
						
							|  |  |  |       return crisisEle.click(); | 
					
						
							|  |  |  |     }).then(function () { | 
					
						
							|  |  |  |       expect(page.crisisDetail.isPresent()).toBe(true, 'should be able to see crisis detail'); | 
					
						
							|  |  |  |       expect(page.crisisDetailTitle.getText()).toContain(crisisText); | 
					
						
							| 
									
										
										
										
											2016-05-30 11:05:09 -07:00
										 |  |  |       let inputEle = page.crisisDetail.element(by.css('input')); | 
					
						
							| 
									
										
										
										
											2016-10-06 23:25:52 +01:00
										 |  |  |       inputEle.sendKeys('-foo'); | 
					
						
							| 
									
										
										
										
											2016-01-03 11:32:57 -08:00
										 |  |  |       expect(page.crisisDetailTitle.getText()).toContain(crisisText + '-foo'); | 
					
						
							| 
									
										
										
										
											2016-05-30 11:05:09 -07:00
										 |  |  |       let buttonEle = page.crisisDetail.element(by.cssContainingText('button', shouldSave ? 'Save' : 'Cancel')); | 
					
						
							| 
									
										
										
										
											2016-01-03 11:32:57 -08:00
										 |  |  |       return buttonEle.click(); | 
					
						
							|  |  |  |     }).then(function () { | 
					
						
							|  |  |  |       if (shouldSave) { | 
					
						
							|  |  |  |         expect(crisisEle.getText()).toContain(crisisText + '-foo'); | 
					
						
							|  |  |  |       } else { | 
					
						
							|  |  |  |         expect(crisisEle.getText()).not.toContain(crisisText + '-foo'); | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | }); |