Skip to content

Commit 6d45153

Browse files
committed
fix(benchmarks): fix scrolling benchmark; add more tests
1 parent 6197ab0 commit 6d45153

File tree

3 files changed

+51
-4
lines changed

3 files changed

+51
-4
lines changed

modules/benchmarks/e2e_test/naive_infinite_scroll_spec.es6

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,57 @@ var testUtil = require('angular2/e2e_test/test_util');
22

33
describe('ng2 naive infinite scroll benchmark', function () {
44

5-
var URL = 'benchmarks/src/naive_infinite_scroll/index.html';
5+
var URL = 'benchmarks/src/naive_infinite_scroll/index.html?appSize=3';
66

77
afterEach(testUtil.verifyNoBrowserErrors);
88

99
it('should not throw errors', function() {
1010
browser.get(URL);
11+
var expectedRowCount = 18;
12+
var expectedCellsPerRow = 11;
13+
var allScrollItems = 'scroll-app /deep/ #testArea /deep/ scroll-item';
14+
var cells = `${ allScrollItems } /deep/ .row *`;
15+
var stageButtons =
16+
`${ allScrollItems } /deep/ .row stage-buttons /deep/ button`;
17+
18+
var count = function(selector) {
19+
return browser.executeScript(
20+
`return document.querySelectorAll("${ selector }").length;`
21+
);
22+
}
23+
24+
var clickFirstOf = function(selector) {
25+
return browser.executeScript(
26+
`document.querySelector("${ selector }").click();`
27+
);
28+
}
29+
30+
var firstTextOf = function(selector) {
31+
return browser.executeScript(
32+
`return document.querySelector("${ selector }").innerText;`
33+
);
34+
}
35+
36+
// Make sure rows are rendered
37+
count(allScrollItems).then(function(c) {
38+
expect(c).toBe(expectedRowCount);
39+
});
40+
41+
// Make sure cells are rendered
42+
count(cells).then(function(c) {
43+
expect(c).toBe(expectedRowCount * expectedCellsPerRow);
44+
});
45+
46+
// Click on first enabled button and verify stage changes
47+
firstTextOf(`${ stageButtons }:enabled`).then(function(text) {
48+
expect(text).toBe('Pitched');
49+
clickFirstOf(`${ stageButtons }:enabled`).then(function() {
50+
firstTextOf(`${ stageButtons }:enabled`).then(function(text) {
51+
expect(text).toBe('Won');
52+
})
53+
});
54+
})
55+
1156
browser.executeScript(
1257
'document.querySelector("scroll-app /deep/ #reset-btn").click()');
1358
browser.executeScript(

modules/benchmarks/src/naive_infinite_scroll/index.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@ import {MapWrapper} from 'angular2/src/facade/collection';
44

55
import {Parser, Lexer, ChangeDetector, ChangeDetection}
66
from 'angular2/change_detection';
7-
import {bootstrap, Component, Viewport, Template, ViewContainer, Compiler}
8-
from 'angular2/angular2';
7+
import {
8+
bootstrap, Component, Viewport, Template, ViewContainer, Compiler, onChange
9+
} from 'angular2/angular2';
910
import {reflector} from 'angular2/src/reflection/reflection';
1011
import {CompilerCache} from 'angular2/src/core/compiler/compiler';
1112
import {DirectiveMetadataReader} from 'angular2/src/core/compiler/directive_metadata_reader';
@@ -166,6 +167,7 @@ export function setupReflectorForAngular() {
166167
'parameters': [[ViewContainer]],
167168
'annotations' : [new Viewport({
168169
selector: '[foreach]',
170+
lifecycle: [onChange],
169171
bind: {
170172
'in': 'iterable[]'
171173
}

modules/benchmarks/src/naive_infinite_scroll/scroll_item.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ export function setupReflectorForScrollItem() {
6565
FormattedCellComponent
6666
],
6767
inline: `
68-
<div [style]="itemStyle">
68+
<div class="row" [style]="itemStyle">
6969
<company-name [company]="offering.company"
7070
[cell-width]="companyNameWidth">
7171
</company-name>

0 commit comments

Comments
 (0)