| 
									
										
										
										
											2016-05-30 11:05:09 -07:00
										 |  |  | /// <reference path='../_protractor/e2e.d.ts' />
 | 
					
						
							| 
									
										
										
										
											2016-06-16 02:01:03 +01:00
										 |  |  | 'use strict'; | 
					
						
							| 
									
										
										
										
											2016-01-27 14:49:02 -08:00
										 |  |  | describe('Angular 1 to 2 Quick Reference Tests', function () { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   beforeAll(function () { | 
					
						
							|  |  |  |     browser.get(''); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   it('should display no poster images after bootstrap', function () { | 
					
						
							|  |  |  |     testImagesAreDisplayed(false); | 
					
						
							|  |  |  |   }); | 
					
						
							| 
									
										
										
										
											2016-04-08 02:20:37 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-27 14:49:02 -08:00
										 |  |  |   it('should display proper movie data', function () { | 
					
						
							|  |  |  |     // We check only a few samples
 | 
					
						
							| 
									
										
										
										
											2016-05-30 11:05:09 -07:00
										 |  |  |     let expectedSamples: any[] = [ | 
					
						
							| 
									
										
										
										
											2016-01-27 14:49:02 -08:00
										 |  |  |       {row: 0, column: 0, element: 'img', attr: 'src', value: 'images/hero.png', contains: true}, | 
					
						
							|  |  |  |       {row: 0, column: 2, value: 'Celeritas'}, | 
					
						
							| 
									
										
										
										
											2016-04-08 02:20:37 +01:00
										 |  |  |       {row: 1, column: 3, matches: /Dec 1[678], 2015/}, // absorb timezone dif; we care about date format
 | 
					
						
							| 
									
										
										
										
											2016-01-27 14:49:02 -08:00
										 |  |  |       {row: 1, column: 5, value: '$14.95'}, | 
					
						
							|  |  |  |       {row: 2, column: 4, value: 'PG-13'}, | 
					
						
							|  |  |  |       {row: 2, column: 7, value: '100%'}, | 
					
						
							|  |  |  |       {row: 2, column: 0, element: 'img', attr: 'src', value: 'images/ng-logo.png', contains: true}, | 
					
						
							|  |  |  |     ]; | 
					
						
							| 
									
										
										
										
											2016-04-08 02:20:37 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-27 14:49:02 -08:00
										 |  |  |     // Go through the samples
 | 
					
						
							| 
									
										
										
										
											2016-05-30 11:05:09 -07:00
										 |  |  |     let movieRows = getMovieRows(); | 
					
						
							|  |  |  |     for (let i = 0; i < expectedSamples.length; i++) { | 
					
						
							|  |  |  |       let sample = expectedSamples[i]; | 
					
						
							|  |  |  |       let tableCell = movieRows.get(sample.row) | 
					
						
							| 
									
										
										
										
											2016-01-27 14:49:02 -08:00
										 |  |  |         .all(by.tagName('td')).get(sample.column); | 
					
						
							|  |  |  |       // Check the cell or its nested element
 | 
					
						
							| 
									
										
										
										
											2016-05-30 11:05:09 -07:00
										 |  |  |       let elementToCheck = sample.element | 
					
						
							| 
									
										
										
										
											2016-01-27 14:49:02 -08:00
										 |  |  |         ? tableCell.element(by.tagName(sample.element)) | 
					
						
							|  |  |  |         : tableCell; | 
					
						
							| 
									
										
										
										
											2016-04-08 02:20:37 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-27 14:49:02 -08:00
										 |  |  |       // Check element attribute or text
 | 
					
						
							| 
									
										
										
										
											2016-05-30 11:05:09 -07:00
										 |  |  |       let valueToCheck = sample.attr | 
					
						
							| 
									
										
										
										
											2016-01-27 14:49:02 -08:00
										 |  |  |         ? elementToCheck.getAttribute(sample.attr) | 
					
						
							|  |  |  |         : elementToCheck.getText(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-08 02:20:37 +01:00
										 |  |  |       // Test for equals/contains/match
 | 
					
						
							| 
									
										
										
										
											2016-01-27 14:49:02 -08:00
										 |  |  |       if (sample.contains) { | 
					
						
							|  |  |  |         expect(valueToCheck).toContain(sample.value); | 
					
						
							| 
									
										
										
										
											2016-04-08 02:20:37 +01:00
										 |  |  |       } else if (sample.matches) { | 
					
						
							|  |  |  |         expect(valueToCheck).toMatch(sample.matches); | 
					
						
							| 
									
										
										
										
											2016-01-27 14:49:02 -08:00
										 |  |  |       } else { | 
					
						
							|  |  |  |         expect(valueToCheck).toEqual(sample.value); | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   it('should display images after Show Poster', function () { | 
					
						
							| 
									
										
										
										
											2016-05-30 11:05:09 -07:00
										 |  |  |     testPosterButtonClick('Show Poster', true); | 
					
						
							| 
									
										
										
										
											2016-01-27 14:49:02 -08:00
										 |  |  |   }); | 
					
						
							| 
									
										
										
										
											2016-04-08 02:20:37 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-27 14:49:02 -08:00
										 |  |  |   it('should hide images after Hide Poster', function () { | 
					
						
							| 
									
										
										
										
											2016-05-30 11:05:09 -07:00
										 |  |  |     testPosterButtonClick('Hide Poster', false); | 
					
						
							| 
									
										
										
										
											2016-01-27 14:49:02 -08:00
										 |  |  |   }); | 
					
						
							| 
									
										
										
										
											2016-04-08 02:20:37 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-27 14:49:02 -08:00
										 |  |  |   it('should display no movie when no favorite hero is specified', function () { | 
					
						
							| 
									
										
										
										
											2016-05-30 11:05:09 -07:00
										 |  |  |     testFavoriteHero(null, 'Please enter your favorite hero.'); | 
					
						
							| 
									
										
										
										
											2016-01-27 14:49:02 -08:00
										 |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   it('should display no movie for Magneta', function () { | 
					
						
							| 
									
										
										
										
											2016-05-30 11:05:09 -07:00
										 |  |  |     testFavoriteHero('Magneta', 'No movie, sorry!'); | 
					
						
							| 
									
										
										
										
											2016-01-27 14:49:02 -08:00
										 |  |  |   }); | 
					
						
							| 
									
										
										
										
											2016-04-08 02:20:37 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-27 14:49:02 -08:00
										 |  |  |   it('should display a movie for Mr. Nice', function () { | 
					
						
							| 
									
										
										
										
											2016-05-30 11:05:09 -07:00
										 |  |  |     testFavoriteHero('Mr. Nice', 'Excellent choice!'); | 
					
						
							| 
									
										
										
										
											2016-01-27 14:49:02 -08:00
										 |  |  |   }); | 
					
						
							| 
									
										
										
										
											2016-04-08 02:20:37 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-30 11:05:09 -07:00
										 |  |  |   function testImagesAreDisplayed(isDisplayed: boolean) { | 
					
						
							|  |  |  |     let expectedMovieCount = 3; | 
					
						
							| 
									
										
										
										
											2016-04-08 02:20:37 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-30 11:05:09 -07:00
										 |  |  |     let movieRows = getMovieRows(); | 
					
						
							| 
									
										
										
										
											2016-01-27 14:49:02 -08:00
										 |  |  |     expect(movieRows.count()).toBe(expectedMovieCount); | 
					
						
							| 
									
										
										
										
											2016-05-30 11:05:09 -07:00
										 |  |  |     for (let i = 0; i < expectedMovieCount; i++) { | 
					
						
							|  |  |  |       let movieImage = movieRows.get(i).element(by.css('td > img')); | 
					
						
							| 
									
										
										
										
											2016-01-27 14:49:02 -08:00
										 |  |  |       expect(movieImage.isDisplayed()).toBe(isDisplayed); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2016-04-08 02:20:37 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-30 11:05:09 -07:00
										 |  |  |   function testPosterButtonClick(expectedButtonText: string, isDisplayed: boolean) { | 
					
						
							|  |  |  |     let posterButton = element(by.css('movie-list tr > th > button')); | 
					
						
							| 
									
										
										
										
											2016-01-27 14:49:02 -08:00
										 |  |  |     expect(posterButton.getText()).toBe(expectedButtonText); | 
					
						
							| 
									
										
										
										
											2016-04-08 02:20:37 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-27 14:49:02 -08:00
										 |  |  |     posterButton.click().then(function () { | 
					
						
							|  |  |  |       testImagesAreDisplayed(isDisplayed); | 
					
						
							| 
									
										
										
										
											2016-06-08 01:06:25 +02:00
										 |  |  |     }); | 
					
						
							| 
									
										
										
										
											2016-01-27 14:49:02 -08:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2016-04-08 02:20:37 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-27 14:49:02 -08:00
										 |  |  |   function getMovieRows() { | 
					
						
							|  |  |  |     return element.all(by.css('movie-list tbody > tr')); | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2016-04-08 02:20:37 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-30 11:05:09 -07:00
										 |  |  |   function testFavoriteHero(heroName: string, expectedLabel: string) { | 
					
						
							|  |  |  |     let movieListComp = element(by.tagName('movie-list')); | 
					
						
							|  |  |  |     let heroInput = movieListComp.element(by.tagName('input')); | 
					
						
							|  |  |  |     let favoriteHeroLabel = movieListComp.element(by.tagName('h3')); | 
					
						
							|  |  |  |     let resultLabel = movieListComp.element(by.css('span > p')); | 
					
						
							| 
									
										
										
										
											2016-04-08 02:20:37 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-27 14:49:02 -08:00
										 |  |  |     heroInput.clear().then(function () { | 
					
						
							|  |  |  |       sendKeys(heroInput, heroName || '').then(function () { | 
					
						
							|  |  |  |         expect(resultLabel.getText()).toBe(expectedLabel); | 
					
						
							|  |  |  |         if (heroName) { | 
					
						
							|  |  |  |           expect(favoriteHeroLabel.isDisplayed()).toBe(true); | 
					
						
							|  |  |  |           expect(favoriteHeroLabel.getText()).toContain(heroName); | 
					
						
							|  |  |  |         } else { | 
					
						
							|  |  |  |           expect(favoriteHeroLabel.isDisplayed()).toBe(false); | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2016-06-08 01:06:25 +02:00
										 |  |  |       }); | 
					
						
							|  |  |  |     }); | 
					
						
							| 
									
										
										
										
											2016-01-27 14:49:02 -08:00
										 |  |  |   } | 
					
						
							|  |  |  | }); |