| 
									
										
										
										
											2016-10-06 23:25:52 +01:00
										 |  |  | import { browser, element, by } from 'protractor'; | 
					
						
							|  |  |  | import { appLang, describeIf } from '../protractor-helpers'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | describeIf(appLang.appIsTs || appLang.appIsJs, 'Forms Tests', function () { | 
					
						
							| 
									
										
										
										
											2015-12-20 13:17:16 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   beforeEach(function () { | 
					
						
							|  |  |  |     browser.get(''); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   it('should display correct title', function () { | 
					
						
							|  |  |  |     expect(element.all(by.css('h1')).get(0).getText()).toEqual('Hero Form'); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   it('should not display message before submit', function () { | 
					
						
							| 
									
										
										
										
											2016-05-30 11:05:09 -07:00
										 |  |  |     let ele = element(by.css('h2')); | 
					
						
							| 
									
										
										
										
											2015-12-20 13:17:16 -08:00
										 |  |  |     expect(ele.isDisplayed()).toBe(false); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   it('should hide form after submit', function () { | 
					
						
							| 
									
										
										
										
											2016-05-30 11:05:09 -07:00
										 |  |  |     let ele = element.all(by.css('h1')).get(0); | 
					
						
							| 
									
										
										
										
											2015-12-20 13:17:16 -08:00
										 |  |  |     expect(ele.isDisplayed()).toBe(true); | 
					
						
							| 
									
										
										
										
											2016-05-30 11:05:09 -07:00
										 |  |  |     let b = element.all(by.css('button[type=submit]')).get(0); | 
					
						
							| 
									
										
										
										
											2015-12-20 13:17:16 -08:00
										 |  |  |     b.click().then(function() { | 
					
						
							|  |  |  |       expect(ele.isDisplayed()).toBe(false); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   it('should display message after submit', function () { | 
					
						
							| 
									
										
										
										
											2016-05-30 11:05:09 -07:00
										 |  |  |     let b = element.all(by.css('button[type=submit]')).get(0); | 
					
						
							| 
									
										
										
										
											2015-12-20 13:17:16 -08:00
										 |  |  |     b.click().then(function() { | 
					
						
							|  |  |  |       expect(element(by.css('h2')).getText()).toContain('You submitted the following'); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   it('should hide form after submit', function () { | 
					
						
							| 
									
										
										
										
											2016-06-19 11:50:27 -04:00
										 |  |  |     let alterEgoEle = element.all(by.css('input[name=alterEgo]')).get(0); | 
					
						
							| 
									
										
										
										
											2015-12-20 13:17:16 -08:00
										 |  |  |     expect(alterEgoEle.isDisplayed()).toBe(true); | 
					
						
							| 
									
										
										
										
											2016-05-30 11:05:09 -07:00
										 |  |  |     let submitButtonEle = element.all(by.css('button[type=submit]')).get(0); | 
					
						
							| 
									
										
										
										
											2015-12-20 13:17:16 -08:00
										 |  |  |     submitButtonEle.click().then(function() { | 
					
						
							|  |  |  |       expect(alterEgoEle.isDisplayed()).toBe(false); | 
					
						
							| 
									
										
										
										
											2016-05-30 11:05:09 -07:00
										 |  |  |     }); | 
					
						
							| 
									
										
										
										
											2015-12-20 13:17:16 -08:00
										 |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   it('should reflect submitted data after submit', function () { | 
					
						
							| 
									
										
										
										
											2016-05-30 11:05:09 -07:00
										 |  |  |     let test = 'testing 1 2 3'; | 
					
						
							|  |  |  |     let newValue: string; | 
					
						
							| 
									
										
										
										
											2016-06-19 11:50:27 -04:00
										 |  |  |     let alterEgoEle = element.all(by.css('input[name=alterEgo]')).get(0); | 
					
						
							| 
									
										
										
										
											2016-10-06 23:25:52 +01:00
										 |  |  |     alterEgoEle.getAttribute('value').then(function(value: string) { | 
					
						
							|  |  |  |       alterEgoEle.sendKeys(test); | 
					
						
							| 
									
										
										
										
											2015-12-20 13:17:16 -08:00
										 |  |  |       newValue = value + test; | 
					
						
							|  |  |  |       expect(alterEgoEle.getAttribute('value')).toEqual(newValue); | 
					
						
							| 
									
										
										
										
											2016-05-30 11:05:09 -07:00
										 |  |  |       let b = element.all(by.css('button[type=submit]')).get(0); | 
					
						
							| 
									
										
										
										
											2015-12-20 13:17:16 -08:00
										 |  |  |       return b.click(); | 
					
						
							|  |  |  |     }).then(function() { | 
					
						
							| 
									
										
										
										
											2016-05-30 11:05:09 -07:00
										 |  |  |       let alterEgoTextEle = element(by.cssContainingText('div', 'Alter Ego')); | 
					
						
							| 
									
										
										
										
											2015-12-20 13:17:16 -08:00
										 |  |  |       expect(alterEgoTextEle.isPresent()).toBe(true, 'cannot locate "Alter Ego" label'); | 
					
						
							| 
									
										
										
										
											2016-05-30 11:05:09 -07:00
										 |  |  |       let divEle = element(by.cssContainingText('div', newValue)); | 
					
						
							| 
									
										
										
										
											2015-12-20 13:17:16 -08:00
										 |  |  |       expect(divEle.isPresent()).toBe(true, 'cannot locate div with this text: ' + newValue); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | }); | 
					
						
							|  |  |  | 
 |