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: {
21 var fuck_that_shit = {
26 set_toolbar: function () {}
33 openerp = window.openerp.init(true);
34 window.openerp.base.chrome(openerp);
36 window.openerp.base.data(openerp);
37 window.openerp.base.views(openerp);
38 window.openerp.base.list(openerp);
39 window.openerp.base.form(openerp);
43 test('render selection checkboxes', 2, function () {
44 var listview = new openerp.base.ListView(
46 'qunit-fixture', {model: null, ids: [null, null, null], index: 0});
48 listview.on_loaded(fvg);
50 listview.do_fill_table({records: [
51 {data: {id: {value: null}}},
52 {data: {id: {value: null}}},
53 {data: {id: {value: null}}}
56 ok(are(listview.$element.find('tbody th'),
57 '.oe-record-selector'));
58 ok(are(listview.$element.find('tbody th input'),
59 ':checkbox:not([name])'));
61 test('render no checkbox if selectable=false', 1, function () {
62 var listview = new openerp.base.ListView(
64 'qunit-fixture', {model: null, ids: [null, null, null], index: 0}, false,
67 listview.on_loaded(fvg);
69 listview.do_fill_table({records: [
70 {data: {id: {value: null}}},
71 {data: {id: {value: null}}},
72 {data: {id: {value: null}}}
74 equal(listview.$element.find('tbody th').length, 0);
76 test('select a bunch of records', 2, function () {
77 var listview = new openerp.base.ListView(
78 fuck_that_shit, null, 'qunit-fixture',
79 {model: null, ids: [1, 2, 3], index: 0});
80 listview.on_loaded(fvg);
82 listview.do_fill_table({records: [
83 {data: {id: {value: 1}}},
84 {data: {id: {value: 2}}},
85 {data: {id: {value: 3}}}
87 // TODO: find less intrusive way to get selection count of list view?
88 listview.$element.find('tbody th input:eq(2)')
89 .attr('checked', true);
90 deepEqual(listview.list.get_selection(), [3]);
91 listview.$element.find('tbody th input:eq(1)')
92 .attr('checked', true);
93 deepEqual(listview.list.get_selection(), [2, 3]);
95 test('render deletion button if list is deletable', 1, function () {
96 var listview = new openerp.base.ListView(
97 fuck_that_shit, null, 'qunit-fixture',
98 {model: null, ids: [null, null, null], index: 0});
100 listview.on_loaded(fvg);
102 listview.do_fill_table({records: [
103 {data: {id: {value: null}}},
104 {data: {id: {value: null}}},
105 {data: {id: {value: null}}}
108 listview.$element.find('tbody tr td.oe-record-delete button').length,
111 test('deletion button should lead on deletion in the dataset',
114 var listview = new openerp.base.ListView(
115 fuck_that_shit, null, 'qunit-fixture',
116 {model: null, unlink: function (ids) {
118 }, ids: [1, 2, 3], index: 0});
120 listview.on_loaded(fvg);
122 listview.do_fill_table({records: [
123 {data: {id: {value: 1}}},
124 {data: {id: {value: 2}}},
125 {data: {id: {value: 3}}}
127 listview.$element.find('tbody td.oe-record-delete:eq(2) button').click();
128 deepEqual(deleted, [3]);
129 listview.$element.find('tbody td.oe-record-delete:eq(0) button').click();
130 deepEqual(deleted, [1]);
132 test('multiple records deletion', 1, function () {
134 var listview = new openerp.base.ListView(
135 fuck_that_shit, null, 'qunit-fixture',
136 {model: null, unlink: function (ids) {
138 }, ids: [1, 2, 3], index: 0});
140 listview.on_loaded(fvg);
142 listview.do_fill_table({records: [
143 {data: {id: {value: 1}}},
144 {data: {id: {value: 2}}},
145 {data: {id: {value: 3}}}
147 listview.$element.find('tbody th input:eq(2)')
148 .attr('checked', true);
149 listview.$element.find('tbody th input:eq(1)')
150 .attr('checked', true);
152 listview.$element.find('#oe-list-delete').click();
153 deepEqual(deleted, [2, 3]);