OLD | NEW |
| (Empty) |
1 <!DOCTYPE html> | |
2 <!-- | |
3 Copyright (c) 2014 The Chromium Authors. All rights reserved. | |
4 Use of this source code is governed by a BSD-style license that can be | |
5 found in the LICENSE file. | |
6 --> | |
7 <link rel="import" href="/tracing/ui/base/list_and_associated_view.html"> | |
8 <script> | |
9 'use strict'; | |
10 | |
11 tr.b.unittest.testSuite(function() { | |
12 const ListAndAssociatedView = tr.ui.b.ListAndAssociatedView; | |
13 | |
14 const SimpleView = tr.ui.b.define('div'); | |
15 SimpleView.prototype = { | |
16 __proto__: HTMLDivElement.prototype, | |
17 | |
18 decorate() { | |
19 this.item_ = undefined; | |
20 }, | |
21 | |
22 set item(item) { | |
23 this.item_ = item; | |
24 }, | |
25 get item() { | |
26 return this.item_; | |
27 } | |
28 }; | |
29 | |
30 test('listViewNamingWithField', function() { | |
31 const lav = new ListAndAssociatedView(); | |
32 const list = [ | |
33 {x: '1'}, | |
34 {x: '2'}, | |
35 {x: '3'} | |
36 ]; | |
37 const view = new SimpleView(); | |
38 | |
39 lav.list = list; | |
40 lav.listProperty = 'x'; | |
41 lav.view = view; | |
42 lav.viewProperty = 'item'; | |
43 | |
44 const lavListView = lav.listView; | |
45 assert.strictEqual(lavListView.children.length, 3); | |
46 assert.strictEqual(Polymer.dom(lavListView.children[0]).textContent, '1'); | |
47 }); | |
48 | |
49 test('listViewNamingWithProperty', function() { | |
50 const lav = new ListAndAssociatedView(); | |
51 | |
52 function X(x) { | |
53 this.x = x; | |
54 } | |
55 X.prototype = { | |
56 get title() { | |
57 return this.x; | |
58 } | |
59 }; | |
60 | |
61 const list = [ | |
62 new X('1'), | |
63 new X('2'), | |
64 new X('3') | |
65 ]; | |
66 const view = new SimpleView(); | |
67 | |
68 lav.list = list; | |
69 lav.listProperty = 'title'; | |
70 lav.view = view; | |
71 lav.viewProperty = 'item'; | |
72 | |
73 const lavListView = lav.listView; | |
74 assert.strictEqual(lavListView.children.length, 3); | |
75 assert.strictEqual(Polymer.dom(lavListView.children[0]).textContent, '1'); | |
76 }); | |
77 | |
78 test('selectionChangesView', function() { | |
79 const lav = new ListAndAssociatedView(); | |
80 const list = [ | |
81 {x: '1'}, | |
82 {x: '2'}, | |
83 {x: '3'} | |
84 ]; | |
85 const view = new SimpleView(); | |
86 | |
87 lav.list = list; | |
88 lav.listProperty = 'x'; | |
89 lav.view = view; | |
90 lav.viewProperty = 'item'; | |
91 const lavListView = lav.listView; | |
92 | |
93 assert.strictEqual(list[0], view.item); | |
94 lavListView.children[1].selected = true; | |
95 assert.strictEqual(list[1], view.item); | |
96 }); | |
97 }); | |
98 </script> | |
OLD | NEW |