-
Notifications
You must be signed in to change notification settings - Fork 155
/
array-data-source.html
122 lines (101 loc) · 2.95 KB
/
array-data-source.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>iron-list test</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0">
<script src="../../webcomponentsjs/webcomponents-lite.js"></script>
<script src="../../web-component-tester/browser.js"></script>
<link rel="import" href="helpers.html">
<link rel="import" href="../vaadin-grid.html">
</head>
<body>
<test-fixture id="default">
<template>
<vaadin-grid>
<vaadin-grid-column>
<template is="header">First</template>
<template>[[item.name.first]]</template>
</vaadin-grid-column>
<vaadin-grid-column>
<template is="header">Last</template>
<template>[[item.name.last]]</template>
</vaadin-grid-column>
</vaadin-grid>
</template>
</test-fixture>
<script>
describe('array data source', function() {
var grid, body;
function getContent(row, column) {
return getCellContent(getCell(row, column)).innerText;
}
function getCell(row, column) {
return getRowCells(getRows(body)[row])[column];
}
beforeEach(function(done) {
grid = fixture('default');
grid.items = [{
name: {
first: 'foo',
last: 'bar'
}
}, {
name: {
first: 'baz',
last: 'qux'
}
}];
body = grid.$.scroller.$.items;
done();
});
it('should have right amount of data', function() {
var bodyRows = getRows(body);
expect(bodyRows).to.have.length(2);
});
it('should have the right data', function() {
expect(getContent(0, 0)).to.equal('foo');
expect(getContent(1, 0)).to.equal('baz');
});
it('should be observed for shift', function() {
grid.unshift('items', {
name: {
first: 'a',
last: 'b'
}
});
expect(grid.size).to.equal(3);
expect(getContent(0, 0)).to.equal('a');
});
it('should be observed for mutation', function() {
grid.set('items.0.name.first', 'new');
expect(getContent(0, 0)).to.equal('new');
});
it('should handle null', function() {
grid.items = null;
expect(grid.size).to.equal(0);
});
it('should set array data source', function() {
expect(grid.dataSource).to.equal(grid._arrayDataSource);
});
it('should not override custom data source', function() {
var ds = grid.dataSource = function() {};
grid.items = [1, 2, 3];
expect(grid.dataSource).to.equal(ds);
});
it('should handle new array of same length', function() {
grid.items = [{
name: {
first: 'a'
}
}, {
name: {
first: 'b'
}
}];
expect(getContent(0, 0)).to.equal('a');
});
});
</script>
</body>
</html>