| 
									
										
										
										
											2017-04-12 21:53:18 +02:00
										 |  |  | 'use strict'; // necessary for es6 output in node
 | 
					
						
							| 
									
										
										
										
											2017-02-22 18:13:21 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | import { browser, element, by } from 'protractor'; | 
					
						
							| 
									
										
										
										
											2017-10-03 10:38:43 +01:00
										 |  |  | const { version: angularVersion } = require('@angular/core/package.json'); | 
					
						
							| 
									
										
										
										
											2017-02-22 18:13:21 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | describe('Pipes', function () { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   beforeAll(function () { | 
					
						
							|  |  |  |     browser.get(''); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   it('should open correctly', function () { | 
					
						
							|  |  |  |     expect(element.all(by.tagName('h1')).get(0).getText()).toEqual('Pipes'); | 
					
						
							| 
									
										
										
										
											2017-08-22 21:31:15 +02:00
										 |  |  |     expect(element(by.css('app-hero-birthday p')).getText()).toEqual(`The hero's birthday is Apr 15, 1988`); | 
					
						
							| 
									
										
										
										
											2017-02-22 18:13:21 +00:00
										 |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   it('should show 4 heroes', function () { | 
					
						
							| 
									
										
										
										
											2017-08-22 21:31:15 +02:00
										 |  |  |     expect(element.all(by.css('app-hero-list div')).count()).toEqual(4); | 
					
						
							| 
									
										
										
										
											2017-02-22 18:13:21 +00:00
										 |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   it('should show a familiar hero in json', function () { | 
					
						
							| 
									
										
										
										
											2017-08-22 21:31:15 +02:00
										 |  |  |     expect(element(by.cssContainingText('app-hero-list p', 'Heroes as JSON')).getText()).toContain('Bombasto'); | 
					
						
							| 
									
										
										
										
											2017-02-22 18:13:21 +00:00
										 |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   it('should show alternate birthday formats', function () { | 
					
						
							| 
									
										
										
										
											2017-08-22 21:31:15 +02:00
										 |  |  |     expect(element(by.cssContainingText('app-root > p', `The hero's birthday is Apr 15, 1988`)).isDisplayed()).toBe(true); | 
					
						
							|  |  |  |     expect(element(by.cssContainingText('app-root > p', `The hero's birthday is 04/15/88`)).isDisplayed()).toBe(true); | 
					
						
							| 
									
										
										
										
											2017-02-22 18:13:21 +00:00
										 |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   it('should be able to toggle birthday formats', function () { | 
					
						
							| 
									
										
										
										
											2017-08-22 21:31:15 +02:00
										 |  |  |     let birthDayEle = element(by.css('app-hero-birthday2 > p')); | 
					
						
							| 
									
										
										
										
											2017-10-03 10:38:43 +01:00
										 |  |  |     if (angularVersion.indexOf('4.') === 0) { // Breaking change between v4 and v5 (https://github.com/angular/angular/commit/079d884)
 | 
					
						
							|  |  |  |       expect(birthDayEle.getText()).toEqual(`The hero's birthday is 4/15/1988`); | 
					
						
							|  |  |  |     } else { | 
					
						
							|  |  |  |       expect(birthDayEle.getText()).toEqual(`The hero's birthday is 4/15/88`); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2017-08-22 21:31:15 +02:00
										 |  |  |     let buttonEle = element(by.cssContainingText('app-hero-birthday2 > button', 'Toggle Format')); | 
					
						
							| 
									
										
										
										
											2017-02-22 18:13:21 +00:00
										 |  |  |     expect(buttonEle.isDisplayed()).toBe(true); | 
					
						
							|  |  |  |     buttonEle.click().then(function() { | 
					
						
							|  |  |  |       expect(birthDayEle.getText()).toEqual(`The hero's birthday is Friday, April 15, 1988`); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   it('should be able to chain and compose pipes', function () { | 
					
						
							| 
									
										
										
										
											2017-08-22 21:31:15 +02:00
										 |  |  |     let chainedPipeEles = element.all(by.cssContainingText('app-root p', `The chained hero's`)); | 
					
						
							| 
									
										
										
										
											2017-02-22 18:13:21 +00:00
										 |  |  |     expect(chainedPipeEles.count()).toBe(3, 'should have 3 chained pipe examples'); | 
					
						
							|  |  |  |     expect(chainedPipeEles.get(0).getText()).toContain('APR 15, 1988'); | 
					
						
							|  |  |  |     expect(chainedPipeEles.get(1).getText()).toContain('FRIDAY, APRIL 15, 1988'); | 
					
						
							|  |  |  |     expect(chainedPipeEles.get(2).getText()).toContain('FRIDAY, APRIL 15, 1988'); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   it('should be able to use ExponentialStrengthPipe pipe', function () { | 
					
						
							| 
									
										
										
										
											2017-08-22 21:31:15 +02:00
										 |  |  |     let ele = element(by.css('app-power-booster p')); | 
					
						
							| 
									
										
										
										
											2017-02-22 18:13:21 +00:00
										 |  |  |     expect(ele.getText()).toContain('Super power boost: 1024'); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   it('should be able to use the exponential calculator', function () { | 
					
						
							| 
									
										
										
										
											2017-08-22 21:31:15 +02:00
										 |  |  |     let eles = element.all(by.css('app-power-boost-calculator input')); | 
					
						
							| 
									
										
										
										
											2017-02-22 18:13:21 +00:00
										 |  |  |     let baseInputEle = eles.get(0); | 
					
						
							|  |  |  |     let factorInputEle = eles.get(1); | 
					
						
							| 
									
										
										
										
											2017-08-22 21:31:15 +02:00
										 |  |  |     let outputEle = element(by.css('app-power-boost-calculator p')); | 
					
						
							| 
									
										
										
										
											2017-02-22 18:13:21 +00:00
										 |  |  |     baseInputEle.clear().then(function() { | 
					
						
							|  |  |  |       baseInputEle.sendKeys('7'); | 
					
						
							|  |  |  |       return factorInputEle.clear(); | 
					
						
							|  |  |  |     }).then(function() { | 
					
						
							|  |  |  |       factorInputEle.sendKeys('3'); | 
					
						
							|  |  |  |       expect(outputEle.getText()).toContain('343'); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-12 21:53:18 +02:00
										 |  |  |   it('should support flying heroes (pure) ', function () { | 
					
						
							| 
									
										
										
										
											2017-08-22 21:31:15 +02:00
										 |  |  |     let nameEle = element(by.css('app-flying-heroes input[type="text"]')); | 
					
						
							|  |  |  |     let canFlyCheckEle = element(by.css('app-flying-heroes #can-fly')); | 
					
						
							|  |  |  |     let mutateCheckEle = element(by.css('app-flying-heroes #mutate')); | 
					
						
							|  |  |  |     let resetEle = element(by.css('app-flying-heroes button')); | 
					
						
							|  |  |  |     let flyingHeroesEle = element.all(by.css('app-flying-heroes #flyers div')); | 
					
						
							| 
									
										
										
										
											2017-02-22 18:13:21 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     expect(canFlyCheckEle.getAttribute('checked')).toEqual('true', 'should default to "can fly"'); | 
					
						
							|  |  |  |     expect(mutateCheckEle.getAttribute('checked')).toEqual('true', 'should default to mutating array'); | 
					
						
							|  |  |  |     expect(flyingHeroesEle.count()).toEqual(2, 'only two of the original heroes can fly'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     nameEle.sendKeys('test1\n'); | 
					
						
							|  |  |  |     expect(flyingHeroesEle.count()).toEqual(2, 'no change while mutating array'); | 
					
						
							|  |  |  |     mutateCheckEle.click().then(function() { | 
					
						
							|  |  |  |       nameEle.sendKeys('test2\n'); | 
					
						
							|  |  |  |       expect(flyingHeroesEle.count()).toEqual(4, 'not mutating; should see both adds'); | 
					
						
							|  |  |  |       expect(flyingHeroesEle.get(2).getText()).toContain('test1'); | 
					
						
							|  |  |  |       expect(flyingHeroesEle.get(3).getText()).toContain('test2'); | 
					
						
							|  |  |  |       return resetEle.click(); | 
					
						
							|  |  |  |     }) | 
					
						
							|  |  |  |     .then(function() { | 
					
						
							| 
									
										
										
										
											2017-07-07 16:55:17 -07:00
										 |  |  |        expect(flyingHeroesEle.count()).toEqual(2, 'reset should restore original flying heroes'); | 
					
						
							| 
									
										
										
										
											2017-02-22 18:13:21 +00:00
										 |  |  |     }); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-12 21:53:18 +02:00
										 |  |  |   it('should support flying heroes (impure) ', function () { | 
					
						
							| 
									
										
										
										
											2017-08-22 21:31:15 +02:00
										 |  |  |     let nameEle = element(by.css('app-flying-heroes-impure input[type="text"]')); | 
					
						
							|  |  |  |     let canFlyCheckEle = element(by.css('app-flying-heroes-impure #can-fly')); | 
					
						
							|  |  |  |     let mutateCheckEle = element(by.css('app-flying-heroes-impure #mutate')); | 
					
						
							|  |  |  |     let flyingHeroesEle = element.all(by.css('app-flying-heroes-impure #flyers div')); | 
					
						
							| 
									
										
										
										
											2017-02-22 18:13:21 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     expect(canFlyCheckEle.getAttribute('checked')).toEqual('true', 'should default to "can fly"'); | 
					
						
							|  |  |  |     expect(mutateCheckEle.getAttribute('checked')).toEqual('true', 'should default to mutating array'); | 
					
						
							|  |  |  |     expect(flyingHeroesEle.count()).toEqual(2, 'only two of the original heroes can fly'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     nameEle.sendKeys('test1\n'); | 
					
						
							|  |  |  |     expect(flyingHeroesEle.count()).toEqual(3, 'new flying hero should show in mutating array'); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   it('should show an async hero message', function () { | 
					
						
							| 
									
										
										
										
											2017-08-22 21:31:15 +02:00
										 |  |  |     expect(element.all(by.tagName('app-hero-message')).get(0).getText()).toContain('hero'); | 
					
						
							| 
									
										
										
										
											2017-02-22 18:13:21 +00:00
										 |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | }); |