From 36abc4641cd0a223c537ddf9018008f73f07724a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Hrub=C3=BD?= Date: Mon, 3 Jun 2019 12:50:06 +0000 Subject: [PATCH] [FIX] web: keep the search options visibility state The search buttons visibility is saved in the local storage. Rev. 6448420 changed the API of the LocalStorage servive (by JSON parsing the values), and didn't adapt the calls done for the search buttons. Closes #33833 closes odoo/odoo#34206 Signed-off-by: VincentSchippefilt --- .../static/src/js/views/search/search_view.js | 4 +- .../static/tests/views/search_view_tests.js | 42 +++++++++++++++++++ doc/cla/individual/jakubhruby.md | 11 +++++ 3 files changed, 55 insertions(+), 2 deletions(-) create mode 100644 doc/cla/individual/jakubhruby.md diff --git a/addons/web/static/src/js/views/search/search_view.js b/addons/web/static/src/js/views/search/search_view.js index 69a45649793..ec18b89c943 100644 --- a/addons/web/static/src/js/views/search/search_view.js +++ b/addons/web/static/src/js/views/search/search_view.js @@ -304,7 +304,7 @@ var SearchView = Widget.extend({ 'click .o_searchview_more': function (e) { $(e.target).toggleClass('fa-search-plus fa-search-minus'); var visibleSearchMenu = this.call('local_storage', 'getItem', 'visible_search_menu'); - this.call('local_storage', 'setItem', 'visible_search_menu', visibleSearchMenu !== 'true'); + this.call('local_storage', 'setItem', 'visible_search_menu', visibleSearchMenu === false); this.toggle_buttons(); }, 'keydown .o_searchview_input, .o_searchview_facet': function (e) { @@ -395,7 +395,7 @@ var SearchView = Widget.extend({ this.timeRanges = options.action && options.action.context ? options.action.context.time_ranges : undefined; var visibleSearchMenu = this.call('local_storage', 'getItem', 'visible_search_menu'); - this.visible_filters = (visibleSearchMenu !== 'false'); + this.visible_filters = (visibleSearchMenu !== false); this.input_subviews = []; // for user input in searchbar this.search_defaults = this.options.search_defaults || {}; this.headless = this.options.hidden && _.isEmpty(this.search_defaults); diff --git a/addons/web/static/tests/views/search_view_tests.js b/addons/web/static/tests/views/search_view_tests.js index 6281236e74b..a2698a5ede3 100644 --- a/addons/web/static/tests/views/search_view_tests.js +++ b/addons/web/static/tests/views/search_view_tests.js @@ -1,7 +1,9 @@ odoo.define('web.search_view_tests', function (require) { "use strict"; +var AbstractStorageService = require('web.AbstractStorageService'); var FormView = require('web.FormView'); +var RamStorage = require('web.RamStorage'); var testUtils = require('web.test_utils'); var testUtilsDom = require('web.test_utils_dom'); var createActionManager = testUtils.createActionManager; @@ -1087,5 +1089,45 @@ QUnit.module('Search View', { form.destroy(); }); + QUnit.module('Misc'); + + QUnit.test('search buttons visibility is stored in/retrieved from local storage', async function (assert) { + assert.expect(9); + + var RamStorageService = AbstractStorageService.extend({ + storage: new RamStorage(), + }); + + var actionManager = createActionManager({ + actions: this.actions, + archs: this.archs, + data: this.data, + services: { + local_storage: RamStorageService, + }, + }); + + testUtils.intercept(actionManager, 'call_service', function (ev) { + if (ev.data.service === 'local_storage' && ev.data.args[0] === 'visible_search_menu') { + assert.step(`${ev.data.method} ${ev.data.args.length > 1 ? ev.data.args[1] : ''}`); + } + }, true); + + await actionManager.doAction(1); + + assert.isVisible($('.o_search_options .o_dropdown_toggler_btn:first')); + + await testUtils.dom.click($('.o_searchview_more')); + + assert.isNotVisible($('.o_search_options .o_dropdown_toggler_btn:first')); + assert.verifySteps(['getItem ', 'getItem ', 'setItem false']); + + await actionManager.doAction(2); + + assert.isNotVisible($('.o_search_options .o_dropdown_toggler_btn:first')); + assert.verifySteps(['getItem ', 'getItem ', 'setItem false', 'getItem ']); + + actionManager.destroy(); + }); }); }); diff --git a/doc/cla/individual/jakubhruby.md b/doc/cla/individual/jakubhruby.md new file mode 100644 index 00000000000..46d2ff703d4 --- /dev/null +++ b/doc/cla/individual/jakubhruby.md @@ -0,0 +1,11 @@ +Czech Republic, 2019-06-03 + +I hereby agree to the terms of the Odoo Individual Contributor License +Agreement v1.0. + +I declare that I am authorized and able to make this agreement and sign this +declaration. + +Signed, + +Jakub HrubĂ˝ jakub@jhruby.cz https://github.com/jakubhruby