[FIX] fix tests in autocompletion
[odoo/odoo.git] / addons / web / static / test / list.js
1 openerp.testing.section('list.buttons', {
2     dependencies: ['web.list', 'web.form'],
3     rpc: 'mock',
4     templates: true
5 }, function (test) {
6     test('record-deletion', {asserts: 2}, function (instance, $fix, mock) {
7         mock('demo:fields_view_get', function () {
8             return {
9                 type: 'tree',
10                 fields: {
11                     a: {type: 'char', string: "A"}
12                 },
13                 arch: '<tree><field name="a"/><button type="object" name="foo"/></tree>',
14             };
15         });
16         mock('demo:read', function (args, kwargs) {
17             if (_.isEqual(args[0], [1, 2, 3])) {
18                 return [
19                     {id: 1, a: 'foo'}, {id: 2, a: 'bar'}, {id: 3, a: 'baz'}
20                 ];
21             }
22             throw new Error(JSON.stringify(_.toArray(arguments)));
23         });
24         mock('demo:search_read', function (args, kwargs) {
25             console.log(args);
26             if (_.isEqual(args[0], [['id', 'in', [2]]])) {
27                 return [];
28             }
29             throw new Error(JSON.stringify(_.toArray(arguments)));
30         });
31         mock('/web/dataset/call_button', function () { return false; });
32         var ds = new instance.web.DataSetStatic(null, 'demo', null, [1, 2, 3]);
33         var l = new instance.web.ListView({
34             do_action: openerp.testing.noop
35         }, ds, false, {editable: 'top'});
36         return l.appendTo($fix)
37         .then(l.proxy('reload_content'))
38         .then(function () {
39             var d = $.Deferred();
40             l.records.bind('remove', function () {
41                 d.resolve();
42             });
43             $fix.find('table tbody tr:eq(1) button').click();
44             return d.promise();
45         })
46         .then(function () {
47             strictEqual(l.records.length, 2,
48                         "should have 2 records left");
49             strictEqual($fix.find('table tbody tr[data-id]').length, 2,
50                         "should have 2 rows left");
51         });
52     });
53 });