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