| 
									
										
										
										
											2017-02-22 18:13:21 +00:00
										 |  |  | import { browser, element, by } from 'protractor'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // Angular E2E Testing Guide:
 | 
					
						
							|  |  |  | // https://docs.angularjs.org/guide/e2e-testing
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-30 13:03:13 +03:00
										 |  |  | describe('PhoneCat Application', () => { | 
					
						
							| 
									
										
										
										
											2017-02-22 18:13:21 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |   // #docregion redirect
 | 
					
						
							| 
									
										
										
										
											2020-07-30 13:03:13 +03:00
										 |  |  |   it('should redirect `index.html` to `index.html#!/phones', () => { | 
					
						
							| 
									
										
										
										
											2017-02-22 18:13:21 +00:00
										 |  |  |     browser.get('index.html'); | 
					
						
							|  |  |  |     browser.waitForAngular(); | 
					
						
							| 
									
										
										
										
											2020-07-30 13:03:13 +03:00
										 |  |  |     browser.getCurrentUrl().then((url: string) => { | 
					
						
							| 
									
										
										
										
											2017-02-22 18:13:21 +00:00
										 |  |  |       expect(url.endsWith('/phones')).toBe(true); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  |   // #enddocregion redirect
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-30 13:03:13 +03:00
										 |  |  |   describe('View: Phone list', () => { | 
					
						
							| 
									
										
										
										
											2017-02-22 18:13:21 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-30 13:03:13 +03:00
										 |  |  |     beforeEach(() => { | 
					
						
							| 
									
										
										
										
											2017-02-22 18:13:21 +00:00
										 |  |  |       browser.get('index.html#!/phones'); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-30 13:03:13 +03:00
										 |  |  |     it('should filter the phone list as a user types into the search box', () => { | 
					
						
							| 
									
										
										
										
											2020-07-30 13:03:19 +03:00
										 |  |  |       const phoneList = element.all(by.css('.phones li')); | 
					
						
							|  |  |  |       const query = element(by.css('input')); | 
					
						
							| 
									
										
										
										
											2017-02-22 18:13:21 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |       expect(phoneList.count()).toBe(20); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       query.sendKeys('nexus'); | 
					
						
							|  |  |  |       expect(phoneList.count()).toBe(1); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       query.clear(); | 
					
						
							|  |  |  |       query.sendKeys('motorola'); | 
					
						
							|  |  |  |       expect(phoneList.count()).toBe(8); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-30 13:03:13 +03:00
										 |  |  |     it('should be possible to control phone order via the drop-down menu', () => { | 
					
						
							| 
									
										
										
										
											2020-07-30 13:03:19 +03:00
										 |  |  |       const queryField = element(by.css('input')); | 
					
						
							|  |  |  |       const orderSelect = element(by.css('select')); | 
					
						
							|  |  |  |       const nameOption = orderSelect.element(by.css('option[value="name"]')); | 
					
						
							|  |  |  |       const phoneNameColumn = element.all(by.css('.phones .name')); | 
					
						
							| 
									
										
										
										
											2017-02-22 18:13:21 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |       function getNames() { | 
					
						
							| 
									
										
										
										
											2020-07-30 13:03:13 +03:00
										 |  |  |         return phoneNameColumn.map((elem) => elem.getText()); | 
					
						
							| 
									
										
										
										
											2017-02-22 18:13:21 +00:00
										 |  |  |       } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       queryField.sendKeys('tablet');   // Let's narrow the dataset to make the assertions shorter
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       expect(getNames()).toEqual([ | 
					
						
							|  |  |  |         'Motorola XOOM\u2122 with Wi-Fi', | 
					
						
							|  |  |  |         'MOTOROLA XOOM\u2122' | 
					
						
							|  |  |  |       ]); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       nameOption.click(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       expect(getNames()).toEqual([ | 
					
						
							|  |  |  |         'MOTOROLA XOOM\u2122', | 
					
						
							|  |  |  |         'Motorola XOOM\u2122 with Wi-Fi' | 
					
						
							|  |  |  |       ]); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // #docregion links
 | 
					
						
							| 
									
										
										
										
											2020-07-30 13:03:13 +03:00
										 |  |  |     it('should render phone specific links', () => { | 
					
						
							| 
									
										
										
										
											2020-07-30 13:03:19 +03:00
										 |  |  |       const query = element(by.css('input')); | 
					
						
							| 
									
										
										
										
											2017-02-22 18:13:21 +00:00
										 |  |  |       query.sendKeys('nexus'); | 
					
						
							|  |  |  |       element.all(by.css('.phones li a')).first().click(); | 
					
						
							| 
									
										
										
										
											2020-07-30 13:03:13 +03:00
										 |  |  |       browser.getCurrentUrl().then((url: string) => { | 
					
						
							| 
									
										
										
										
											2017-02-22 18:13:21 +00:00
										 |  |  |         expect(url.endsWith('/phones/nexus-s')).toBe(true); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  |     // #enddocregion links
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-30 13:03:13 +03:00
										 |  |  |   describe('View: Phone detail', () => { | 
					
						
							| 
									
										
										
										
											2017-02-22 18:13:21 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-30 13:03:13 +03:00
										 |  |  |     beforeEach(() => { | 
					
						
							| 
									
										
										
										
											2017-02-22 18:13:21 +00:00
										 |  |  |       browser.get('index.html#!/phones/nexus-s'); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-30 13:03:13 +03:00
										 |  |  |     it('should display the `nexus-s` page', () => { | 
					
						
							| 
									
										
										
										
											2017-02-22 18:13:21 +00:00
										 |  |  |       expect(element(by.css('h1')).getText()).toBe('Nexus S'); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-30 13:03:13 +03:00
										 |  |  |     it('should display the first phone image as the main phone image', () => { | 
					
						
							| 
									
										
										
										
											2020-07-30 13:03:19 +03:00
										 |  |  |       const mainImage = element(by.css('img.phone.selected')); | 
					
						
							| 
									
										
										
										
											2017-02-22 18:13:21 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |       expect(mainImage.getAttribute('src')).toMatch(/img\/phones\/nexus-s.0.jpg/); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-30 13:03:13 +03:00
										 |  |  |     it('should swap the main image when clicking on a thumbnail image', () => { | 
					
						
							| 
									
										
										
										
											2020-07-30 13:03:19 +03:00
										 |  |  |       const mainImage = element(by.css('img.phone.selected')); | 
					
						
							|  |  |  |       const thumbnails = element.all(by.css('.phone-thumbs img')); | 
					
						
							| 
									
										
										
										
											2017-02-22 18:13:21 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |       thumbnails.get(2).click(); | 
					
						
							|  |  |  |       expect(mainImage.getAttribute('src')).toMatch(/img\/phones\/nexus-s.2.jpg/); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       thumbnails.get(0).click(); | 
					
						
							|  |  |  |       expect(mainImage.getAttribute('src')).toMatch(/img\/phones\/nexus-s.0.jpg/); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | }); |