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.core(openerp);
26 window.openerp.base.chrome(openerp);
28 window.openerp.base.data(openerp);
29 window.openerp.base.views(openerp);
30 window.openerp.base.list(openerp);
31 window.openerp.base.form(openerp);
35 test('render selection checkboxes', 2, function () {
36 var listview = new openerp.base.ListView(
37 null, 'qunit-fixture', {model: null, ids: [null, null, null], index: 0});
39 listview.on_loaded(fvg);
41 listview.do_fill_table({records: [
42 {data: {id: {value: null}}},
43 {data: {id: {value: null}}},
44 {data: {id: {value: null}}}
47 ok(are(listview.$element.find('tbody th'),
48 '.oe-record-selector'));
49 ok(are(listview.$element.find('tbody th input'),
50 ':checkbox:not([name])'));
52 test('render no checkbox if selectable=false', 1, function () {
53 var listview = new openerp.base.ListView(
54 null, 'qunit-fixture', {model: null, ids: [null, null, null], index: 0}, false,
57 listview.on_loaded(fvg);
59 listview.do_fill_table({records: [
60 {data: {id: {value: null}}},
61 {data: {id: {value: null}}},
62 {data: {id: {value: null}}}
64 equal(listview.$element.find('tbody th').length, 0);
66 test('select a bunch of records', 2, function () {
67 var listview = new openerp.base.ListView(
68 null, 'qunit-fixture', {model: null, ids: [1, 2, 3], index: 0});
69 listview.on_loaded(fvg);
71 listview.do_fill_table({records: [
72 {data: {id: {value: 1}}},
73 {data: {id: {value: 2}}},
74 {data: {id: {value: 3}}}
76 // TODO: find less intrusive way to get selection count of list view?
77 listview.$element.find('tbody th input:eq(2)')
78 .attr('checked', true);
79 deepEqual(listview.list.get_selection(), [3]);
80 listview.$element.find('tbody th input:eq(1)')
81 .attr('checked', true);
82 deepEqual(listview.list.get_selection(), [2, 3]);
84 test('render deletion button if list is deletable', 1, function () {
85 var listview = new openerp.base.ListView(
86 null, 'qunit-fixture', {model: null, ids: [null, null, null], index: 0});
88 listview.on_loaded(fvg);
90 listview.do_fill_table({records: [
91 {data: {id: {value: null}}},
92 {data: {id: {value: null}}},
93 {data: {id: {value: null}}}
96 listview.$element.find('tbody tr td.oe-record-delete button').length,
99 test('deletion button should lead on deletion in the dataset',
102 var listview = new openerp.base.ListView(
103 null, 'qunit-fixture',
104 {model: null, unlink: function (ids) {
106 }, ids: [1, 2, 3], index: 0});
108 listview.on_loaded(fvg);
110 listview.do_fill_table({records: [
111 {data: {id: {value: 1}}},
112 {data: {id: {value: 2}}},
113 {data: {id: {value: 3}}}
115 listview.$element.find('tbody td.oe-record-delete:eq(2) button').click();
116 deepEqual(deleted, [3]);
117 listview.$element.find('tbody td.oe-record-delete:eq(0) button').click();
118 deepEqual(deleted, [1]);
120 test('multiple records deletion', 1, function () {
122 var listview = new openerp.base.ListView(
123 null, 'qunit-fixture',
124 {model: null, unlink: function (ids) {
126 }, ids: [1, 2, 3], index: 0});
128 listview.on_loaded(fvg);
130 listview.do_fill_table({records: [
131 {data: {id: {value: 1}}},
132 {data: {id: {value: 2}}},
133 {data: {id: {value: 3}}}
135 listview.$element.find('tbody th input:eq(2)')
136 .attr('checked', true);
137 listview.$element.find('tbody th input:eq(1)')
138 .attr('checked', true);
140 listview.$element.find('.oe-list-delete').click();
141 deepEqual(deleted, [2, 3]);