blob: 691cc379b4fb16307ca8a604893988a2ce4b2b38 [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="/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>