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
|
<!DOCTYPE html>
<!--
Copyright (c) 2014 The Chromium Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file.
-->
<link rel="import" href="/tracing/ui/base/list_and_associated_view.html">
<script>
'use strict';
tr.b.unittest.testSuite(function() {
var ListAndAssociatedView = tr.ui.b.ListAndAssociatedView;
var SimpleView = tr.ui.b.define('div');
SimpleView.prototype = {
__proto__: HTMLDivElement.prototype,
decorate: function() {
this.item_ = undefined;
},
set item(item) {
this.item_ = item;
},
get item() {
return this.item_;
}
};
test('listViewNamingWithField', function() {
var lav = new ListAndAssociatedView();
var list = [
{x: '1'},
{x: '2'},
{x: '3'}
];
var view = new SimpleView();
lav.list = list;
lav.listProperty = 'x';
lav.view = view;
lav.viewProperty = 'item';
var lavListView = lav.listView;
assert.equal(lavListView.children.length, 3);
assert.equal(lavListView.children[0].textContent, '1');
});
test('listViewNamingWithProperty', function() {
var lav = new ListAndAssociatedView();
function X(x) {
this.x = x;
}
X.prototype = {
get title() {
return this.x;
}
};
var list = [
new X('1'),
new X('2'),
new X('3')
];
var view = new SimpleView();
lav.list = list;
lav.listProperty = 'title';
lav.view = view;
lav.viewProperty = 'item';
var lavListView = lav.listView;
assert.equal(lavListView.children.length, 3);
assert.equal(lavListView.children[0].textContent, '1');
});
test('selectionChangesView', function() {
var lav = new ListAndAssociatedView();
var list = [
{x: '1'},
{x: '2'},
{x: '3'}
];
var view = new SimpleView();
lav.list = list;
lav.listProperty = 'x';
lav.view = view;
lav.viewProperty = 'item';
var lavListView = lav.listView;
assert.equal(list[0], view.item);
lavListView.children[1].selected = true;
assert.equal(list[1], view.item);
});
});
</script>
|