Skip to content

Commit cd532b0

Browse files
test(e2e): fix error setting style property of DOM element
Fixes the following error in e2e tests: "Cannot set property style of \#<HTMLElement> which has only a getter". Closes angular#2874
1 parent 81abc39 commit cd532b0

File tree

3 files changed

+36
-47
lines changed

3 files changed

+36
-47
lines changed

modules/benchmarks/src/naive_infinite_scroll/cells.ts

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,50 @@
1-
import {List, ListWrapper, Map, MapWrapper} from 'angular2/src/facade/collection';
1+
import {List, ListWrapper, Map} from 'angular2/src/facade/collection';
22
import {Company, Opportunity, Offering, Account, CustomDate, STATUS_LIST} from './common';
33
import {NgFor} from 'angular2/directives';
44

55
import {Component, Directive, View} from 'angular2/angular2';
66

77
export class HasStyle {
8-
style: Map<any, any>;
8+
cellWidth: int;
99

10-
constructor() { this.style = new Map(); }
10+
constructor() {}
1111

12-
set width(w) { this.style.set('width', w); }
12+
set width(w: int) { this.cellWidth = w; }
1313
}
1414

1515
@Component({selector: 'company-name', properties: ['width: cell-width', 'company']})
16-
@View({directives: [], template: `<div [style]="style">{{company.name}}</div>`})
16+
@View({directives: [], template: `<div [style.width.px]="cellWidth">{{company.name}}</div>`})
1717
export class CompanyNameComponent extends HasStyle {
1818
company: Company;
1919
}
2020

2121
@Component({selector: 'opportunity-name', properties: ['width: cell-width', 'opportunity']})
22-
@View({directives: [], template: `<div [style]="style">{{opportunity.name}}</div>`})
22+
@View({directives: [], template: `<div [style.width.px]="cellWidth">{{opportunity.name}}</div>`})
2323
export class OpportunityNameComponent extends HasStyle {
2424
opportunity: Opportunity;
2525
}
2626

2727
@Component({selector: 'offering-name', properties: ['width: cell-width', 'offering']})
28-
@View({directives: [], template: `<div [style]="style">{{offering.name}}</div>`})
28+
@View({directives: [], template: `<div [style.width.px]="cellWidth">{{offering.name}}</div>`})
2929
export class OfferingNameComponent extends HasStyle {
3030
offering: Offering;
3131
}
3232

3333
export class Stage {
3434
name: string;
3535
isDisabled: boolean;
36-
style: Map<string, string>;
36+
backgroundColor: string;
3737
apply: Function;
3838
}
3939

4040
@Component({selector: 'stage-buttons', properties: ['width: cell-width', 'offering']})
4141
@View({
4242
directives: [NgFor],
4343
template: `
44-
<div [style]="style">
44+
<div [style.width.px]="cellWidth">
4545
<button template="ng-for #stage of stages"
4646
[disabled]="stage.isDisabled"
47-
[style]="stage.style"
47+
[style.background-color]="stage.backgroundColor"
4848
on-click="setStage(stage)">
4949
{{stage.name}}
5050
</button>
@@ -73,9 +73,7 @@ export class StageButtonsComponent extends HasStyle {
7373
var stage = new Stage();
7474
stage.name = status;
7575
stage.isDisabled = disabled;
76-
var stageStyle = new Map<string, string>();
77-
stageStyle.set('background-color', disabled ? '#DDD' : isCurrent ? '#DDF' : '#FDD');
78-
stage.style = stageStyle;
76+
stage.backgroundColor = disabled ? '#DDD' : isCurrent ? '#DDF' : '#FDD';
7977
if (isCurrent) {
8078
disabled = false;
8179
}
@@ -88,7 +86,7 @@ export class StageButtonsComponent extends HasStyle {
8886
@View({
8987
directives: [],
9088
template: `
91-
<div [style]="style">
89+
<div [style.width.px]="cellWidth">
9290
<a href="/account/{{account.accountId}}">
9391
{{account.accountId}}
9492
</a>
@@ -99,7 +97,7 @@ export class AccountCellComponent extends HasStyle {
9997
}
10098

10199
@Component({selector: 'formatted-cell', properties: ['width: cell-width', 'value']})
102-
@View({directives: [], template: `<div [style]="style">{{formattedValue}}</div>`})
100+
@View({directives: [], template: `<div [style.width.px]="cellWidth">{{formattedValue}}</div>`})
103101
export class FormattedCellComponent extends HasStyle {
104102
formattedValue: string;
105103

modules/benchmarks/src/naive_infinite_scroll/scroll_area.ts

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {ListWrapper, MapWrapper} from 'angular2/src/facade/collection';
1+
import {ListWrapper} from 'angular2/src/facade/collection';
22
import {Math} from 'angular2/src/facade/math';
33

44
import {Component, Directive, View} from 'angular2/angular2';
@@ -24,7 +24,8 @@ import {NgFor} from 'angular2/directives';
2424
template: `
2525
<div>
2626
<div id="scrollDiv"
27-
[style]="scrollDivStyle"
27+
[style.height.px]="viewPortHeight"
28+
style="width: 1000px; border: 1px solid #000; overflow: scroll"
2829
on-scroll="onScroll($event)">
2930
<div id="padding"></div>
3031
<div id="inner">
@@ -40,19 +41,14 @@ export class ScrollAreaComponent {
4041
_fullList: List<Offering>;
4142
visibleItems: List<Offering>;
4243

43-
scrollDivStyle;
44+
viewPortHeight: number;
4445
paddingDiv;
4546
innerDiv;
4647

4748
constructor() {
4849
this._fullList = generateOfferings(ITEMS);
4950
this.visibleItems = [];
50-
this.scrollDivStyle = MapWrapper.createFromPairs([
51-
['height', `${VIEW_PORT_HEIGHT}px`],
52-
['width', '1000px'],
53-
['border', '1px solid #000'],
54-
['overflow', 'scroll']
55-
]);
51+
this.viewPortHeight = VIEW_PORT_HEIGHT;
5652
this.onScroll(null);
5753
}
5854

modules/benchmarks/src/naive_infinite_scroll/scroll_item.ts

Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import {ListWrapper, MapWrapper} from 'angular2/src/facade/collection';
21
import {
32
CompanyNameComponent,
43
OpportunityNameComponent,
@@ -37,7 +36,10 @@ import {
3736
FormattedCellComponent
3837
],
3938
template: `
40-
<div class="row" [style]="itemStyle">
39+
<div class="row"
40+
[style.height.px]="itemHeight"
41+
[style.line-height.px]="itemHeight"
42+
style="font-size: 18px; display: flex; justify-content: space-between;">
4143
<company-name [company]="offering.company"
4244
[cell-width]="companyNameWidth">
4345
</company-name>
@@ -75,27 +77,20 @@ import {
7577
})
7678
export class ScrollItemComponent {
7779
offering: Offering;
78-
itemStyle;
7980

80-
constructor() {
81-
this.itemStyle = MapWrapper.createFromPairs([
82-
['height', `${ITEM_HEIGHT}px`],
83-
['line-height', `${ITEM_HEIGHT}px`],
84-
['font-size', '18px'],
85-
['display', 'flex'],
86-
['justify-content', 'space-between']
87-
]);
88-
}
81+
itemHeight: number;
8982

90-
get companyNameWidth() { return `${COMPANY_NAME_WIDTH}px`; }
91-
get opportunityNameWidth() { return `${OPPORTUNITY_NAME_WIDTH}px`; }
92-
get offeringNameWidth() { return `${OFFERING_NAME_WIDTH}px`; }
93-
get accountCellWidth() { return `${ACCOUNT_CELL_WIDTH}px`; }
94-
get basePointsWidth() { return `${BASE_POINTS_WIDTH}px`; }
95-
get kickerPointsWidth() { return `${KICKER_POINTS_WIDTH}px`; }
96-
get stageButtonsWidth() { return `${STAGE_BUTTONS_WIDTH}px`; }
97-
get bundlesWidth() { return `${BUNDLES_WIDTH}px`; }
98-
get dueDateWidth() { return `${DUE_DATE_WIDTH}px`; }
99-
get endDateWidth() { return `${END_DATE_WIDTH}px`; }
100-
get aatStatusWidth() { return `${AAT_STATUS_WIDTH}px`; }
83+
constructor() { this.itemHeight = ITEM_HEIGHT; }
84+
85+
get companyNameWidth() { return COMPANY_NAME_WIDTH; }
86+
get opportunityNameWidth() { return OPPORTUNITY_NAME_WIDTH; }
87+
get offeringNameWidth() { return OFFERING_NAME_WIDTH; }
88+
get accountCellWidth() { return ACCOUNT_CELL_WIDTH; }
89+
get basePointsWidth() { return BASE_POINTS_WIDTH; }
90+
get kickerPointsWidth() { return KICKER_POINTS_WIDTH; }
91+
get stageButtonsWidth() { return STAGE_BUTTONS_WIDTH; }
92+
get bundlesWidth() { return BUNDLES_WIDTH; }
93+
get dueDateWidth() { return DUE_DATE_WIDTH; }
94+
get endDateWidth() { return END_DATE_WIDTH; }
95+
get aatStatusWidth() { return AAT_STATUS_WIDTH; }
10196
}

0 commit comments

Comments
 (0)