blob: 83c5fdb317d1baf9c2f12092c5a1f1a48b4b0e67 [file] [log] [blame]
<!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="/base/ui/list_and_associated_view.html">
<script>
'use strict';
tr.b.unittest.testSuite(function() {
var ListAndAssociatedView = tr.b.ui.ListAndAssociatedView;
var SimpleView = tr.b.ui.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>