[FIX] desactivated test creating random false positive
[odoo/odoo.git] / addons / web / static / test / data.js
1 openerp.testing.section('data.model.group_by', {
2     rpc: 'mock',
3     dependencies: ['web.data'],
4 }, function (test) {
5     var group_result = [{
6         bar: 3, bar_count: 5, __context: {}, __domain: [['bar', '=', 3]],
7     }, {
8         bar: 5, bar_count: 3, __context: {}, __domain: [['bar', '=', 5]],
9     }, {
10         bar: 8, bar_count: 0, __context: {}, __domain: [['bar', '=', 8]],
11     }];
12     test('basic', {asserts: 7}, function (instance, $fix, mock) {
13         var m = new instance.web.Model('foo');
14         mock('foo:read_group', function (args, kwargs) {
15             deepEqual(kwargs.fields, ['bar'],
16                       "should read grouping field");
17             deepEqual(kwargs.groupby, ['bar'],
18                       "should have single grouping field");
19             return group_result;
20         });
21         mock('/web/dataset/search_read', function (args) {
22             deepEqual(args.params.domain, [['bar', '=', 3]],
23                       "should have domain matching that of group_by result");
24             return {records: [
25                 {bar: 3, id: 1},
26                 {bar: 3, id: 2},
27                 {bar: 3, id: 4},
28                 {bar: 3, id: 8},
29                 {bar: 3, id: 16}
30             ], length: 5};
31         });
32
33         return m.query().group_by('bar')
34         .then(function (groups) {
35             ok(groups, "should have data");
36             equal(groups.length, 3, "should have three results");
37             var first = groups[0];
38             ok(first.attributes.has_children, "should have children");
39             return  first.query().all();
40         }).done(function (first) {
41             equal(first.length, 5, "should have 5 records");
42         });
43     });
44     test('noleaf', {asserts: 5}, function (instance, $fix, mock) {
45         var m = new instance.web.Model('foo', {group_by_no_leaf: true});
46         mock('foo:read_group', function (args, kwargs) {
47             deepEqual(kwargs.fields, ['bar'],
48                       "should read grouping field");
49             deepEqual(kwargs.groupby, ['bar'],
50                       "should have single grouping field");
51
52             return  group_result;
53         });
54         return m.query().group_by('bar')
55         .then(function (groups) {
56             ok(groups, "should have data");
57             equal(groups.length, 3, "should have three results");
58             ok(!groups[0].attributes.has_children,
59                 "should not have children because no_leaf");
60         });
61     });
62     test('nogroup', {rpc: false}, function (instance, $f, mock) {
63         var m = new instance.web.Model('foo');
64         strictEqual(m.query().group_by(), null, "should not group");
65     });
66     test('empty.noleaf', {asserts: 1}, function (instance, $f, mock) {
67         var m = new instance.web.Model('foo',  {group_by_no_leaf: true});
68         mock('foo:read_group', function (args, kwargs) {
69             return [{__context: [], __domain: []}];
70         });
71         return m.query().group_by().done(function (groups) {
72             strictEqual(groups.length, 1,
73                         "should generate a single fake-ish group");
74         });
75     });
76 });