diff --git a/test/dom/NodeListAdapter.html b/test/dom/NodeListAdapter.html index dfd6da9..86f2608 100644 --- a/test/dom/NodeListAdapter.html +++ b/test/dom/NodeListAdapter.html @@ -30,7 +30,8 @@ function compareById (a, b) { return a.id - b.id; } function symbolizeById (a) { return a.id; } - function querySelector (selector, node) { return node.querySelector(selector); } + function querySelector (selector, node) { return (node||document).querySelector(selector); } + function querySelectorAll (selector, node) { return (node||document).querySelectorAll(selector); } function init () { @@ -41,24 +42,26 @@ } doh.register('the basics', [ - function canHandle (doh) { + function shouldHandleNodes (doh) { + doh.assertTrue(NodeListAdapter.canHandle(getNode('test')), 'DOMNode'); + }, + function shouldNotHandleNonNodes (doh) { doh.assertFalse(NodeListAdapter.canHandle(), 'undefined'); doh.assertFalse(NodeListAdapter.canHandle(null), 'null'); doh.assertFalse(NodeListAdapter.canHandle(function(){}), 'function'); doh.assertFalse(NodeListAdapter.canHandle([]), 'array'); doh.assertFalse(NodeListAdapter.canHandle({}), 'object'); - doh.assertTrue(NodeListAdapter.canHandle(getNode('test')), 'DOMNode'); } ]); - doh.register('add', [ - function add (doh) { + doh.register('events', [ + function shouldAddNodeForEachItem (doh) { var item, adapted, options; init(); options = { querySelector: querySelector, itemTemplateSelector: itemNode, comparator: compareById, - symbolizer: symbolizeById + identifier: symbolizeById }; adapted = new NodeListAdapter(rootNode, options); item = { id: 1 }; @@ -66,50 +69,42 @@ adapted.add({ id: 9 }); adapted.add({ id: 3 }); doh.assertEqual(3, rootNode.querySelectorAll('fieldset').length); - } - ]); - doh.register('events', [ - function add (doh) { - var item, adapted, dfd, options; + }, + function shouldUpdateNode (doh) { + var item, adapted, options; init(); options = { querySelector: querySelector, itemTemplateSelector: itemNode, comparator: compareById, - symbolizer: symbolizeById + identifier: symbolizeById, + bindings: { + name: { node: '', prop: 'name' } + } }; adapted = new NodeListAdapter(rootNode, options); - dfd = new doh.Deferred(); - item = { id: 1 }; - adapted.watch( - function (addedItem) { - dfd.callback(addedItem == item); - } - ); + item = { id: 1, name: 'bar' }; adapted.add(item); - return dfd; + adapted.update({ id: 1, name: 'foo' }); + doh.assertEqual('foo', querySelector(itemNode).name); }, - function remove (doh) { - var item, adapted, dfd; + function shouldRemoveNode (doh) { + var item, adapted; init(); options = { querySelector: querySelector, itemTemplateSelector: itemNode, comparator: compareById, - symbolizer: symbolizeById + identifier: symbolizeById }; adapted = new NodeListAdapter(rootNode, options); - dfd = new doh.Deferred(); + rootNode.innerHTML = ''; // clear out previous tests item = { id: 1 }; adapted.add(item); - adapted.watch( - null, - function (removedItem) { - dfd.callback(removedItem == item); - } - ); + adapted.add({ id: 2 }); + adapted.add({ id: 3 }); adapted.remove(item); - return dfd; + doh.assertEqual(2, querySelectorAll(itemNode, rootNode).length, 'two items remain in list') } ]);