diff --git a/addons/web/static/src/js/search.js b/addons/web/static/src/js/search.js index 945b83256f2..0ec63b890e9 100644 --- a/addons/web/static/src/js/search.js +++ b/addons/web/static/src/js/search.js @@ -846,11 +846,11 @@ instance.web.SearchViewDrawer = instance.web.Widget.extend({ filters.push(new instance.web.search.Filter(item, group)); break; case 'group': - self.inputs.push(new instance.web.search.Separator(this)) + self.add_separator(); self.make_widgets(item.children, fields, new instance.web.search.Group(group, 'w', item)); + self.add_separator(); break; - self.inputs.push(new instance.web.search.Separator(this)) case 'field': var field = this.make_field( item, fields[item['attrs'].name], group); @@ -865,6 +865,11 @@ instance.web.SearchViewDrawer = instance.web.Widget.extend({ group.push(new instance.web.search.FilterGroup(filters, this)); } }, + + add_separator: function () { + if (!(_.last(this.inputs) instanceof instance.web.search.Separator)) + new instance.web.search.Separator(this); + }, /** * Creates a field for the provided field descriptor item (which comes * from fields_view_get) diff --git a/addons/web/static/test/search.js b/addons/web/static/test/search.js index d6490abee22..5faf13b2599 100644 --- a/addons/web/static/test/search.js +++ b/addons/web/static/test/search.js @@ -571,7 +571,7 @@ openerp.testing.section('search.completions', { ok(bob.label, "should have a label"); }); }); - test("M2O expand", {asserts: 13}, function (instance, $s, mock) { + test("M2O expand", {asserts: 11}, function (instance, $s, mock) { mock('dummy.model:name_search', function (args, kwargs) { deepEqual(args, []); strictEqual(kwargs.name, 'bob'); @@ -583,19 +583,16 @@ openerp.testing.section('search.completions', { {attrs: {string: 'Dummy'}}, {relation: 'dummy.model'}, view); return f.expand("bob") .done(function (c) { - equal(c.length, 3, "should return results + title"); - var title = c[0]; - equal(title.label, f.attrs.string, "title should match field name"); - ok(!title.facet, "title should not have a facet"); + equal(c.length, 2, "should return results"); - var f1 = new instance.web.search.Facet(c[1].facet); - equal(c[1].label, "choice 1"); + var f1 = new instance.web.search.Facet(c[0].facet); + equal(c[0].label, "choice 1"); equal(f1.get('category'), f.attrs.string); equal(f1.get('field'), f); deepEqual(f1.values.toJSON(), [{label: 'choice 1', value: 42}]); - var f2 = new instance.web.search.Facet(c[2].facet); - equal(c[2].label, "choice @"); + var f2 = new instance.web.search.Facet(c[1].facet); + equal(c[1].label, "choice @"); equal(f2.get('category'), f.attrs.string); equal(f2.get('field'), f); deepEqual(f2.values.toJSON(), [{label: 'choice @', value: 43}]); @@ -635,7 +632,7 @@ openerp.testing.section('search.completions', { {relation: 'dummy.model'}, view); return f.expand("bob"); }); - test("M2O custom operator", {asserts: 10}, function (instance, $s, mock) { + test("M2O custom operator", {asserts: 8}, function (instance, $s, mock) { mock('dummy.model:name_search', function (args, kwargs) { deepEqual(args, [], "should have no positional arguments"); // the operator is meant for the final search term generation, not the autocompletion @@ -650,13 +647,10 @@ openerp.testing.section('search.completions', { return f.expand('bob') .done(function (c) { - equal(c.length, 2, "should return result + title"); - var title = c[0]; - equal(title.label, f.attrs.string, "title should match field name"); - ok(!title.facet, "title should not have a facet"); + equal(c.length, 1, "should return result"); - var f1 = new instance.web.search.Facet(c[1].facet); - equal(c[1].label, "Match"); + var f1 = new instance.web.search.Facet(c[0].facet); + equal(c[0].label, "Match"); equal(f1.get('category'), f.attrs.string); equal(f1.get('field'), f); deepEqual(f1.values.toJSON(), [{label: 'Match', value: 42}]); @@ -1223,13 +1217,14 @@ openerp.testing.section('search.groupby', { var view = makeSearchView(instance); return view.appendTo($fix) .done(function () { - // 3 filters, 3 filtergroups, 1 custom filter, 1 advanced, 1 Filters + // 3 filters, 3 filtergroups, 1 custom filter, 1 advanced, 1 Filters, // and 1 SaveFilter widget equal(view.drawer.inputs.length, 10, "should have 10 inputs total"); var groups = _.filter(view.drawer.inputs, function (f) { return f instanceof instance.web.search.GroupbyGroup; }); + equal(groups.length, 3, "should have 3 GroupbyGroups"); groups[0].toggle(groups[0].filters[0]); @@ -1562,10 +1557,11 @@ openerp.testing.section('search.invisible', { var done = $.Deferred(); view.complete_global_search({term: 'filter'}, function (compls) { done.resolve(); - strictEqual(compls.length, 2, - "should have 2 completions"); + console.log("completions", compls); + strictEqual(compls.length, 5, + "should have 5 completions"); // 2 filters and 3 separators deepEqual(_.pluck(compls, 'label'), - ['Field 0', 'Filter on: Filter 0'], + [undefined, 'Field 0', 'Filter on: Filter 0', undefined, undefined], "should complete on field 0 and filter 0"); }); return done;