| 
									
										
										
										
											2017-05-03 19:31:02 +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-07-04 10:58:20 -04:00
										 |  |  | describe('NgModule-example', function () { | 
					
						
							| 
									
										
										
										
											2017-02-22 18:13:21 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |   // helpers
 | 
					
						
							| 
									
										
										
										
											2017-07-04 10:58:20 -04:00
										 |  |  |   const lightgray = 'rgba(239, 238, 237, 1)'; | 
					
						
							| 
									
										
										
										
											2017-02-22 18:13:21 +00:00
										 |  |  |   const white = 'rgba(0, 0, 0, 0)'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   function getCommonsSectionStruct() { | 
					
						
							|  |  |  |     const buttons = element.all(by.css('nav a')); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return { | 
					
						
							|  |  |  |       title: element.all(by.tagName('h1')).get(0), | 
					
						
							| 
									
										
										
										
											2019-01-22 14:11:35 -05:00
										 |  |  |       subtitle: element.all(by.css('app-root p i')).get(0), | 
					
						
							| 
									
										
										
										
											2017-02-22 18:13:21 +00:00
										 |  |  |       contactButton: buttons.get(0), | 
					
						
							| 
									
										
										
										
											2017-07-04 10:58:20 -04:00
										 |  |  |       itemButton: buttons.get(1), | 
					
						
							|  |  |  |       customersButton: buttons.get(2) | 
					
						
							| 
									
										
										
										
											2017-02-22 18:13:21 +00:00
										 |  |  |     }; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   function getContactSectionStruct() { | 
					
						
							|  |  |  |     const buttons = element.all(by.css('app-contact form button')); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return { | 
					
						
							|  |  |  |       header: element.all(by.css('app-contact h2')).get(0), | 
					
						
							|  |  |  |       popupMessage: element.all(by.css('app-contact div')).get(0), | 
					
						
							|  |  |  |       contactNameHeader: element.all(by.css('app-contact form h3')).get(0), | 
					
						
							|  |  |  |       input: element.all(by.css('app-contact form input')).get(0), | 
					
						
							|  |  |  |       validationError: element.all(by.css('app-contact form .alert')).get(0), | 
					
						
							|  |  |  |       saveButton: buttons.get(0), // can't be tested
 | 
					
						
							|  |  |  |       nextContactButton: buttons.get(1), | 
					
						
							|  |  |  |       newContactButton: buttons.get(2) | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-07-04 10:58:20 -04:00
										 |  |  |   function getItemSectionStruct() { | 
					
						
							| 
									
										
										
										
											2017-02-22 18:13:21 +00:00
										 |  |  |     return { | 
					
						
							|  |  |  |       title: element.all(by.css('ng-component h3')).get(0), | 
					
						
							|  |  |  |       items: element.all(by.css('ng-component a')), | 
					
						
							|  |  |  |       itemId: element.all(by.css('ng-component div')).get(0), | 
					
						
							|  |  |  |       listLink: element.all(by.css('ng-component a')).get(0), | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-07-04 10:58:20 -04:00
										 |  |  |   function getCustomersSectionStruct() { | 
					
						
							| 
									
										
										
										
											2017-02-22 18:13:21 +00:00
										 |  |  |     return { | 
					
						
							|  |  |  |       header: element.all(by.css('ng-component h2')).get(0), | 
					
						
							|  |  |  |       title: element.all(by.css('ng-component h3')).get(0), | 
					
						
							|  |  |  |       items: element.all(by.css('ng-component a')), | 
					
						
							|  |  |  |       itemId: element.all(by.css('ng-component ng-component div div')).get(0), | 
					
						
							|  |  |  |       itemInput: element.all(by.css('ng-component ng-component input')).get(0), | 
					
						
							|  |  |  |       listLink: element.all(by.css('ng-component ng-component a')).get(0), | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   // tests
 | 
					
						
							|  |  |  |   function appTitleTests(color: string, name?: string) { | 
					
						
							|  |  |  |     return function() { | 
					
						
							|  |  |  |       it('should have a gray header', function() { | 
					
						
							|  |  |  |         const commons = getCommonsSectionStruct(); | 
					
						
							|  |  |  |         expect(commons.title.getCssValue('backgroundColor')).toBe(color); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       it('should welcome us', function () { | 
					
						
							|  |  |  |         const commons = getCommonsSectionStruct(); | 
					
						
							| 
									
										
										
										
											2019-01-22 14:11:35 -05:00
										 |  |  |         expect(commons.subtitle.getText()).toBe('Welcome, ' + (name ||  'Miss Marple')); | 
					
						
							| 
									
										
										
										
											2017-02-22 18:13:21 +00:00
										 |  |  |       }); | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   function contactTests(color: string, name?: string) { | 
					
						
							|  |  |  |     return function() { | 
					
						
							|  |  |  |       it('shows the contact\'s owner', function() { | 
					
						
							|  |  |  |         const contacts = getContactSectionStruct(); | 
					
						
							| 
									
										
										
										
											2019-01-22 14:11:35 -05:00
										 |  |  |         expect(contacts.header.getText()).toBe((name ||  'Miss Marple') + '\'s Contacts'); | 
					
						
							| 
									
										
										
										
											2017-02-22 18:13:21 +00:00
										 |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       it('can cycle between contacts', function () { | 
					
						
							|  |  |  |         const contacts = getContactSectionStruct(); | 
					
						
							|  |  |  |         const nextButton = contacts.nextContactButton; | 
					
						
							| 
									
										
										
										
											2017-07-04 10:58:20 -04:00
										 |  |  |         expect(contacts.contactNameHeader.getText()).toBe('Awesome Yasha'); | 
					
						
							| 
									
										
										
										
											2017-02-22 18:13:21 +00:00
										 |  |  |         expect(contacts.contactNameHeader.getCssValue('backgroundColor')).toBe(color); | 
					
						
							|  |  |  |         nextButton.click().then(function () { | 
					
						
							| 
									
										
										
										
											2017-07-04 10:58:20 -04:00
										 |  |  |           expect(contacts.contactNameHeader.getText()).toBe('Awesome Iulia'); | 
					
						
							| 
									
										
										
										
											2017-02-22 18:13:21 +00:00
										 |  |  |           return nextButton.click(); | 
					
						
							|  |  |  |         }).then(function () { | 
					
						
							| 
									
										
										
										
											2017-07-04 10:58:20 -04:00
										 |  |  |           expect(contacts.contactNameHeader.getText()).toBe('Awesome Karina'); | 
					
						
							| 
									
										
										
										
											2017-02-22 18:13:21 +00:00
										 |  |  |         }); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       it('can create a new contact', function () { | 
					
						
							|  |  |  |         const contacts = getContactSectionStruct(); | 
					
						
							|  |  |  |         const newContactButton = contacts.newContactButton; | 
					
						
							| 
									
										
										
										
											2019-01-22 14:11:35 -05:00
										 |  |  |         const nextButton = contacts.nextContactButton; | 
					
						
							|  |  |  |         const input = contacts.input; | 
					
						
							|  |  |  |         const saveButton = contacts.saveButton; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-22 18:13:21 +00:00
										 |  |  |         newContactButton.click().then(function () { | 
					
						
							| 
									
										
										
										
											2019-01-22 14:11:35 -05:00
										 |  |  |           input.click(); | 
					
						
							|  |  |  |           nextButton.click() | 
					
						
							|  |  |  |           expect(contacts.validationError.getText()).toBe('Name is required.'); | 
					
						
							|  |  |  |           input.click(); | 
					
						
							|  |  |  |           contacts.input.sendKeys('Watson'); | 
					
						
							|  |  |  |           saveButton.click() | 
					
						
							|  |  |  |           expect(contacts.contactNameHeader.getText()).toBe('Awesome Watson'); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-22 18:13:21 +00:00
										 |  |  |         }); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   describe('index.html', function () { | 
					
						
							|  |  |  |     beforeEach(function () { | 
					
						
							|  |  |  |       browser.get(''); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     describe('app-title', appTitleTests(white, 'Miss Marple')); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     describe('contact', contactTests(lightgray, 'Miss Marple')); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-07-04 10:58:20 -04:00
										 |  |  |     describe('item center', function () { | 
					
						
							| 
									
										
										
										
											2017-02-22 18:13:21 +00:00
										 |  |  |       beforeEach(function () { | 
					
						
							| 
									
										
										
										
											2017-07-04 10:58:20 -04:00
										 |  |  |         getCommonsSectionStruct().itemButton.click(); | 
					
						
							| 
									
										
										
										
											2017-02-22 18:13:21 +00:00
										 |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-07-04 10:58:20 -04:00
										 |  |  |       it('shows a list of items', function () { | 
					
						
							|  |  |  |         const item = getItemSectionStruct(); | 
					
						
							|  |  |  |         expect(item.title.getText()).toBe('Items List'); | 
					
						
							|  |  |  |         expect(item.items.count()).toBe(4); | 
					
						
							|  |  |  |         expect(item.items.get(0).getText()).toBe('1 - Sticky notes'); | 
					
						
							| 
									
										
										
										
											2017-02-22 18:13:21 +00:00
										 |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-07-04 10:58:20 -04:00
										 |  |  |       it('can navigate to one item details', function () { | 
					
						
							|  |  |  |         const item = getItemSectionStruct(); | 
					
						
							|  |  |  |         item.items.get(0).click().then(function() { | 
					
						
							|  |  |  |           expect(item.itemId.getText()).toBe('Item id: 1'); | 
					
						
							|  |  |  |           return item.listLink.click(); | 
					
						
							| 
									
										
										
										
											2017-02-22 18:13:21 +00:00
										 |  |  |         }).then(function () { | 
					
						
							|  |  |  |           // We are back to the list
 | 
					
						
							| 
									
										
										
										
											2017-07-04 10:58:20 -04:00
										 |  |  |           expect(item.items.count()).toBe(4); | 
					
						
							| 
									
										
										
										
											2017-02-22 18:13:21 +00:00
										 |  |  |         }); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-07-04 10:58:20 -04:00
										 |  |  |     describe('customers', function () { | 
					
						
							| 
									
										
										
										
											2017-02-22 18:13:21 +00:00
										 |  |  |       beforeEach(function () { | 
					
						
							| 
									
										
										
										
											2017-07-04 10:58:20 -04:00
										 |  |  |         getCommonsSectionStruct().customersButton.click(); | 
					
						
							| 
									
										
										
										
											2017-02-22 18:13:21 +00:00
										 |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-07-04 10:58:20 -04:00
										 |  |  |       it('shows a list of customers', function() { | 
					
						
							|  |  |  |         const customers = getCustomersSectionStruct(); | 
					
						
							|  |  |  |         expect(customers.header.getText()).toBe('Customers of Miss Marple times 2'); | 
					
						
							|  |  |  |         expect(customers.title.getText()).toBe('Customer List'); | 
					
						
							|  |  |  |         expect(customers.items.count()).toBe(6); | 
					
						
							|  |  |  |         expect(customers.items.get(0).getText()).toBe('11 - Julian'); | 
					
						
							| 
									
										
										
										
											2017-02-22 18:13:21 +00:00
										 |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-07-04 10:58:20 -04:00
										 |  |  |       it('can navigate and edit one customer details', function () { | 
					
						
							|  |  |  |         const customers = getCustomersSectionStruct(); | 
					
						
							|  |  |  |         customers.items.get(0).click().then(function () { | 
					
						
							|  |  |  |           expect(customers.itemId.getText()).toBe('Id: 11'); | 
					
						
							|  |  |  |           customers.itemInput.sendKeys(' try'); | 
					
						
							|  |  |  |           return customers.listLink.click(); | 
					
						
							| 
									
										
										
										
											2017-02-22 18:13:21 +00:00
										 |  |  |         }).then(function () { | 
					
						
							|  |  |  |           // We are back to the list
 | 
					
						
							| 
									
										
										
										
											2017-07-04 10:58:20 -04:00
										 |  |  |           expect(customers.items.count()).toBe(6); | 
					
						
							|  |  |  |           expect(customers.items.get(0).getText()).toBe('11 - Julian try'); | 
					
						
							| 
									
										
										
										
											2017-02-22 18:13:21 +00:00
										 |  |  |         }); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | }); |