| 
									
										
										
										
											2016-10-23 22:37:15 +02:00
										 |  |  | /** | 
					
						
							|  |  |  |  * @license | 
					
						
							|  |  |  |  * Copyright Google Inc. All Rights Reserved. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Use of this source code is governed by an MIT-style license that can be | 
					
						
							|  |  |  |  * found in the LICENSE file at https://angular.io/license
 | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-28 17:50:03 -07:00
										 |  |  | import {verifyNoBrowserErrors} from '@angular/testing/src/e2e_util'; | 
					
						
							|  |  |  | import {runClickBenchmark} from '@angular/testing/src/perf_util'; | 
					
						
							| 
									
										
										
										
											2015-05-29 21:40:15 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | describe('ng2 naive infinite scroll benchmark', function() { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-11-12 14:08:58 +01:00
										 |  |  |   const URL = 'benchmarks/src/naive_infinite_scroll/index.html?appSize=3'; | 
					
						
							| 
									
										
										
										
											2015-05-29 21:40:15 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-05-30 08:17:27 -07:00
										 |  |  |   afterEach(verifyNoBrowserErrors); | 
					
						
							| 
									
										
										
										
											2015-05-29 21:40:15 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |   it('should not throw errors', function() { | 
					
						
							|  |  |  |     browser.get(URL); | 
					
						
							| 
									
										
										
										
											2016-11-12 14:08:58 +01:00
										 |  |  |     const expectedRowCount = 18; | 
					
						
							|  |  |  |     const expectedCellsPerRow = 27; | 
					
						
							|  |  |  |     const allScrollItems = 'scroll-app #testArea scroll-item'; | 
					
						
							|  |  |  |     const cells = `${ allScrollItems } .row *`; | 
					
						
							|  |  |  |     const stageButtons = `${ allScrollItems } .row stage-buttons button`; | 
					
						
							| 
									
										
										
										
											2015-05-29 21:40:15 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-11-12 14:08:58 +01:00
										 |  |  |     const count = function(selector) { | 
					
						
							| 
									
										
										
										
											2016-08-26 15:44:05 -07:00
										 |  |  |       return browser.executeScript( | 
					
						
							|  |  |  |           `return ` + | 
					
						
							|  |  |  |           `document.querySelectorAll("${ selector }").length;`); | 
					
						
							| 
									
										
										
										
											2015-06-19 10:18:44 -07:00
										 |  |  |     }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-11-12 14:08:58 +01:00
										 |  |  |     const clickFirstOf = function(selector) { | 
					
						
							| 
									
										
										
										
											2015-06-19 10:18:44 -07:00
										 |  |  |       return browser.executeScript(`document.querySelector("${ selector }").click();`); | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-11-12 14:08:58 +01:00
										 |  |  |     const firstTextOf = function(selector) { | 
					
						
							| 
									
										
										
										
											2016-08-26 15:44:05 -07:00
										 |  |  |       return browser.executeScript( | 
					
						
							|  |  |  |           `return ` + | 
					
						
							|  |  |  |           `document.querySelector("${ selector }").innerText;`); | 
					
						
							| 
									
										
										
										
											2015-06-19 10:18:44 -07:00
										 |  |  |     }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // Make sure rows are rendered
 | 
					
						
							|  |  |  |     count(allScrollItems).then(function(c) { expect(c).toEqual(expectedRowCount); }); | 
					
						
							| 
									
										
										
										
											2015-05-29 21:40:15 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |     // Make sure cells are rendered
 | 
					
						
							| 
									
										
										
										
											2015-05-30 08:17:27 -07:00
										 |  |  |     count(cells).then(function(c) { expect(c).toEqual(expectedRowCount * expectedCellsPerRow); }); | 
					
						
							| 
									
										
										
										
											2015-05-29 21:40:15 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |     // Click on first enabled button and verify stage changes
 | 
					
						
							| 
									
										
										
										
											2016-08-26 15:44:05 -07:00
										 |  |  |     firstTextOf(`${ stageButtons }:enabled`).then(function(text) { | 
					
						
							|  |  |  |       expect(text).toEqual('Pitched'); | 
					
						
							|  |  |  |       clickFirstOf(`${ stageButtons }:enabled`).then(function() { | 
					
						
							| 
									
										
										
										
											2016-10-23 22:52:57 +02:00
										 |  |  |         firstTextOf(`${ stageButtons }:enabled`).then((text) => expect(text).toEqual('Won')); | 
					
						
							| 
									
										
										
										
											2016-08-26 15:44:05 -07:00
										 |  |  |       }); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     $('#reset-btn').click(); | 
					
						
							|  |  |  |     $('#run-btn').click(); | 
					
						
							| 
									
										
										
										
											2015-05-29 21:40:15 -07:00
										 |  |  |     browser.wait(() => { | 
					
						
							|  |  |  |       return $('#done').getText().then(function() { return true; }, function() { return false; }); | 
					
						
							|  |  |  |     }, 10000); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | }); |