summaryrefslogtreecommitdiff
path: root/addons/web/static/test/list-utils.js
diff options
context:
space:
mode:
authorXavier Morel <xmo@openerp.com>2012-07-10 15:12:05 +0200
committerXavier Morel <xmo@openerp.com>2012-07-10 15:12:05 +0200
commit5b6df7ebebbc80c83ed094388f7b85459dae8668 (patch)
tree4a6a8c2e4d447b7510ef40dadc62cfce73e21110 /addons/web/static/test/list-utils.js
parent079e90afbbe657d8c6c746a5911e27446302facd (diff)
[ADD] Collection#pred as well, while we're at it
bzr revid: xmo@openerp.com-20120710131205-voi1nc5rkvewjr2f
Diffstat (limited to 'addons/web/static/test/list-utils.js')
-rw-r--r--addons/web/static/test/list-utils.js41
1 files changed, 41 insertions, 0 deletions
diff --git a/addons/web/static/test/list-utils.js b/addons/web/static/test/list-utils.js
index 18069943b2d..baec728528e 100644
--- a/addons/web/static/test/list-utils.js
+++ b/addons/web/static/test/list-utils.js
@@ -278,6 +278,9 @@ $(document).ready(function () {
root.at(0).attributes,
"should return index 0 as successor to last record if" +
" wraparound is set");
+ deepEqual(root.succ(root.at(2), {wraparound: true}).attributes,
+ root.at(3).attributes,
+ "wraparound should have no effect if not succ(last_record)");
});
test('successor', function () {
var root = new openerp.web.list.Collection();
@@ -295,6 +298,44 @@ $(document).ready(function () {
root.get(3).attributes,
"should wraparound within a collection");
});
+ test('degenerate-predecessor', function () {
+ var root = new openerp.web.list.Collection([
+ {id: 1, value: 1},
+ {id: 2, value: 2},
+ {id: 3, value: 3},
+ {id: 4, value: 5},
+ {id: 5, value: 8},
+ ]);
+
+ deepEqual(root.pred(root.at(2)).attributes,
+ root.at(1).attributes,
+ "should return the record at (index - 1) from the pivot");
+ equal(root.pred(root.at(0)), null,
+ "should return null as predecessor to first record");
+ deepEqual(root.pred(root.at(0), {wraparound: true}).attributes,
+ root.at(4).attributes,
+ "should return last record as predecessor to first record" +
+ " if wraparound is set");
+ deepEqual(root.pred(root.at(1), {wraparound: true}).attributes,
+ root.at(0).attributes,
+ "wraparound should have no effect if not pred(first_record)");
+ });
+ test('predecessor', function () {
+ var root = new openerp.web.list.Collection();
+ root.proxy('first').add([{id: 1, value: 1}, {id: 2, value: 2}]);
+ root.proxy('second').add([{id: 3, value: 3}, {id: 4, value: 5}]);
+ root.proxy('third').add([{id: 5, value: 8}, {id: 6, value: 13}]);
+
+ deepEqual(root.pred(root.get(4)).attributes,
+ root.get(3).attributes,
+ "should get predecessor");
+ equal(root.pred(root.get(3)),
+ null,
+ "predecessor do not cross collections");
+ deepEqual(root.pred(root.get(3), {wraparound: true}).attributes,
+ root.get(4).attributes,
+ "should wraparound within a collection");
+ });
module('list-hofs', {
setup: function () {