diff --git a/addons/web/static/test/search.js b/addons/web/static/test/search.js index 9d5669e6f64..d5d2eedf74f 100644 --- a/addons/web/static/test/search.js +++ b/addons/web/static/test/search.js @@ -1407,179 +1407,3 @@ openerp.testing.section('search.advanced', { }); -openerp.testing.section('search.invisible', { - dependencies: ['web.search'], - rpc: 'mock', - templates: true, -}, function (test) { - var registerTestField = function (instance, methods) { - instance.testing.TestWidget = instance.web.search.Field.extend(methods); - instance.web.search.fields.add('test', 'instance.testing.TestWidget'); - }; - var makeView = function (instance, mock, fields, arch, defaults) { - mock('ir.filters:get_filters', function () { return []; }); - mock('test.model:fields_get', function () { return fields; }); - mock('test.model:fields_view_get', function () { - return { type: 'search', fields: fields, arch: arch }; - }); - var ds = new instance.web.DataSet(null, 'test.model'); - return new instance.web.SearchView(null, ds, false, defaults); - }; - // Invisible fields should not auto-complete - test('invisible-field-no-autocomplete', {asserts: 1}, function (instance, $fix, mock) { - registerTestField(instance, { - complete: function () { - return $.when([{label: this.attrs.string}]); - }, - }); - var view = makeView(instance, mock, { - field0: {type: 'test', string: 'Field 0'}, - field1: {type: 'test', string: 'Field 1'}, - }, ['', - '', - '', - ''].join('')); - return view.appendTo($fix) - .then(function () { - var done = $.Deferred(); - view.complete_global_search({term: 'test'}, function (comps) { - done.resolve(comps); - }); - return done; - }).then(function (completions) { - deepEqual(completions, [{label: 'Field 0'}], - "should only complete the visible field"); - }); - }); - // Invisible filters should not appear in the drawer - test('invisible-filter-no-drawer', {asserts: 4}, function (instance, $fix, mock) { - var view = makeView(instance, mock, {}, [ - '', - '', - '', - ''].join('')); - return view.appendTo($fix) - .then(function () { - var $fs = $fix.find('.oe_searchview_filters ul'); - strictEqual($fs.children().length, - 1, - "should only display one filter"); - strictEqual(_.str.trim($fs.children().text()), - "filter 0", - "should only display filter 0"); - var done = $.Deferred(); - view.complete_global_search({term: 'filter'}, function (comps) { - done.resolve(); - strictEqual(comps.length, 1, "should only complete visible filter"); - strictEqual(comps[0].label, "Filter on: filter 0", - "should complete filter 0"); - }); - return done; - }); - }); - test('invisible-previous-sibling', {asserts: 3}, function (instance, $fix, mock) { - var view = makeView(instance, mock, {}, [ - '', - '', - '', - '', - '', - ''].join('')); - return view.appendTo($fix) - .done(function () { - // Select filter 3 - $fix.find('.oe_searchview_filters ul li:contains("filter 3")').click(); - equal(view.query.length, 1, "should have selected a filter"); - var facet = view.query.at(0); - strictEqual(facet.values.at(0).get('label'), "filter 3", - "should have correctly labelled the facet"); - deepEqual(view.build_search_data().contexts, [{test: 3}], - "should have built correct context"); - }); - }); - // Invisible filter groups should not appear in the drawer - // Group invisibility should be inherited by children - test('group-invisibility', {asserts: 6}, function (instance, $fix, mock) { - registerTestField(instance, { - complete: function () { - return $.when([{label: this.attrs.string}]); - }, - }); - var view = makeView(instance, mock, { - field0: {type: 'test', string: 'Field 0'}, - field1: {type: 'test', string: 'Field 1'}, - }, [ - '', - '', - '', - '', - '', - '', - '', - '', - '', - '' - ].join('')); - return view.appendTo($fix) - .then(function () { - strictEqual($fix.find('.oe_searchview_filters dt').length, - 1, - "should only display one group"); - strictEqual($fix.find('.oe_searchview_filters dt').text(), - 'w Visibles', - "should only display the Visibles group (and its icon char)"); - - var $fs = $fix.find('.oe_searchview_filters ul'); - strictEqual($fs.children().length, 1, - "should only have one filter in the drawer"); - strictEqual(_.str.trim($fs.text()), "Filter 0", - "should have filter 0 as sole filter"); - - var done = $.Deferred(); - view.complete_global_search({term: 'filter'}, function (compls) { - done.resolve(); - console.log("completions", compls); - strictEqual(compls.length, 5, - "should have 5 completions"); // 2 filters and 3 separators - deepEqual(_.pluck(compls, 'label'), - [undefined, 'Field 0', 'Filter on: Filter 0', undefined, undefined], - "should complete on field 0 and filter 0"); - }); - return done; - }); - }); - // Default on invisible fields should still work, for fields and filters both - test('invisible-defaults', {asserts: 1}, function (instance, $fix, mock) { - var view = makeView(instance, mock, { - field: {type: 'char', string: "Field"}, - field2: {type: 'char', string: "Field 2"}, - }, [ - '', - '', - '', - '', - '', - '', - '', - '' - ].join(''), {field: "foo", filter: true}); - - return view.appendTo($fix) - .then(function () { - deepEqual(view.build_search_data(), { - errors: [], - groupbys: [], - contexts: [], - domains: [ - // Generated from field - [['field', 'ilike', 'foo']], - // generated from filter - "[['whee', '=', '42']]" - ], - }, "should yield invisible fields selected by defaults"); - }); - }); -}); -