1 $(document).ready(function () {
3 * Tests a jQuery collection against a selector ("ands" the .is() of each
4 * member of the collection, instead of "or"-ing them)
6 * @param {jQuery} $c a jQuery collection object
7 * @param {String} selector the selector to test the collection against
9 var are = function ($c, selector) {
10 return ($c.filter(function () { return $(this).is(selector); }).length
14 var fvg = {fields_view: {
24 openerp = window.openerp.init(true);
25 window.openerp.base.chrome(openerp);
27 window.openerp.base.views(openerp);
28 window.openerp.base.list(openerp);
32 asyncTest('render selection checkboxes', 2, function () {
33 var listview = new openerp.base.ListView(
35 'qunit-fixture', {model: null});
37 listview.on_loaded(fvg);
39 listview.do_fill_table([{}, {}, {}]).then(function () {
40 ok(are(listview.$element.find('tbody th'),
41 '.oe-record-selector'));
42 ok(are(listview.$element.find('tbody th input'),
43 ':checkbox:not([name])'));
47 asyncTest('render no checkbox if selectable=false', 1, function () {
48 var listview = new openerp.base.ListView(
50 'qunit-fixture', {model: null}, false,
53 listview.on_loaded(fvg);
55 listview.do_fill_table([{}, {}, {}]).then(function () {
56 equal(listview.$element.find('tbody th').length, 0);
60 asyncTest('select a bunch of records', 2, function () {
61 var listview = new openerp.base.ListView(
62 {}, null, 'qunit-fixture', {model: null});
63 listview.on_loaded(fvg);
65 listview.do_fill_table([{id: 1}, {id: 2}, {id: 3}]).then(function () {
66 listview.$element.find('tbody th input:eq(2)')
67 .attr('checked', true);
68 deepEqual(listview.get_selection(), [3]);
69 listview.$element.find('tbody th input:eq(1)')
70 .attr('checked', true);
71 deepEqual(listview.get_selection(), [2, 3]);
75 asyncTest('render deletion button if list is deletable', 1, function () {
76 var listview = new openerp.base.ListView(
77 {}, null, 'qunit-fixture', {model: null});
79 listview.on_loaded(fvg);
81 listview.do_fill_table([{id: 1}, {id: 2}, {id: 3}]).then(function () {
83 listview.$element.find('tbody tr td.oe-record-delete button').length,
88 asyncTest('deletion button should lead on deletion in the dataset',
91 var listview = new openerp.base.ListView(
92 {}, null, 'qunit-fixture', {model: null, unlink: function (ids) {
96 listview.on_loaded(fvg);
98 listview.do_fill_table([{id: 1}, {id: 2}, {id: 3}]).then(function () {
99 listview.$element.find('tbody td.oe-record-delete:eq(2) button').click();
100 deepEqual(deleted, [3]);
101 listview.$element.find('tbody td.oe-record-delete:eq(0) button').click();
102 deepEqual(deleted, [1]);