diff --git a/addons/web/static/src/js/views/control_panel/control_panel_model.js b/addons/web/static/src/js/views/control_panel/control_panel_model.js index 0229daa41ee..f7cd21b8b7d 100644 --- a/addons/web/static/src/js/views/control_panel/control_panel_model.js +++ b/addons/web/static/src/js/views/control_panel/control_panel_model.js @@ -407,7 +407,17 @@ var ControlPanelModel = mvc.Model.extend({ // we need to deactivate all groups when activating a favorite if (filter.type === 'favorite') { this.query.forEach(function (groupId) { - self.groups[groupId].activeFilterIds = []; + var group = self.groups[groupId]; + group.activeFilterIds.forEach(function (id) { + var filter = self.filters[id]; + if (filter.autoCompleteValues) { + filter.autoCompleteValues = []; + } + if (filter.currentOptionId) { + filter.currentOptionId = false; + } + }) + group.activeFilterIds = []; }); this.query = []; } diff --git a/addons/web/static/tests/views/search_view_tests.js b/addons/web/static/tests/views/search_view_tests.js index f8837cdfe29..7fddde6c11a 100644 --- a/addons/web/static/tests/views/search_view_tests.js +++ b/addons/web/static/tests/views/search_view_tests.js @@ -119,6 +119,14 @@ QUnit.module('Search View', { type: 'ir.actions.act_window', views: [[2, 'list']], search_view_id: [8, 'search'], + }, + { + id: 12, + name: 'Partners Action 12', + res_model: 'partner', + type: 'ir.actions.act_window', + views: [[2, 'list']], + search_view_id: [9, 'search'], } ]; @@ -198,6 +206,11 @@ QUnit.module('Search View', { '' + '' + '', + 'partner,9,search': ''+ + '' + + '' + + '' + + '', }; @@ -959,6 +972,85 @@ QUnit.module('Search View', { controlPanel.destroy(); }); + QUnit.test('toggle favorite correctly clears filter, groupbys and field "options"', async function (assert) { + assert.expect(8); + + const actionManager = await createActionManager({ + actions: this.actions, + archs: this.archs, + data: this.data, + intercepts: { + load_filters: function (event) { + return Promise.resolve([{ + context: "{}", + domain: "[]", + id: 7, + is_default: false, + name: "My favorite", + sort: "[]", + user_id: [2, "Mitchell Admin"], + }]).then(event.data.on_success); + }, + }, + }); + + await actionManager.doAction(12); + + // activate Foo a + await testUtils.fields.triggerKey('press', $('.o_searchview_input'), 97); + await testUtils.fields.triggerKey('up', $('.o_searchview_input'), 'enter'); + + // activate Date Filter with This Month + await testUtils.dom.click($('button .fa-filter')); + await testUtils.dom.click($('.o_filters_menu .o_menu_item a')); + await testUtils.dom.click($('.o_item_option[data-option_id="this_month"]')); + + // activate Date Groupby with Year + await testUtils.dom.click($('button .fa-bars')); + await testUtils.dom.click($('.o_group_by_menu .o_menu_item a')); + await testUtils.dom.click($('.o_item_option[data-option_id="year"]')); + + assert.strictEqual($('.o_searchview_input_container .o_facet_values').eq(0).text().trim(), + "a", + "There should be a filter Foo a"); + + assert.strictEqual($('.o_searchview_input_container .o_facet_values').eq(1).text().trim(), + "Date Field Filter: This Month", + "There should be a filter facet with label 'Date Field Filter: This Month'"); + + assert.strictEqual($('.o_searchview_input_container .o_facet_values').eq(2).text().trim(), + "Date Field Groupby: Year", + "There should be a groupby facet with label 'Date Field Groupby: Year'"); + + // activate the favorite + await testUtils.dom.click($('button .fa-star')); + await testUtils.dom.click($('.o_favorites_menu .o_menu_item a')); + + assert.containsOnce(actionManager, '.o_searchview_input_container .o_facet_values', + "There should be a unique facet in the search bar"); + assert.strictEqual($('.o_searchview_input_container .o_facet_values').eq(0).text().trim(), + "My favorite", + "There should be a facet with label 'My favorite''"); + + await testUtils.dom.click($('button .fa-filter')); + await testUtils.dom.click($('.o_filters_menu .o_menu_item a')); + assert.doesNotHaveClass($('.o_item_option[data-option_id="this_month"]'), 'selected', + "The Date Filter option 'This Month' should be deactivated"); + + await testUtils.dom.click($('button .fa-bars')); + await testUtils.dom.click($('.o_group_by_menu .o_menu_item a')); + assert.doesNotHaveClass($('.o_item_option[data-option_id="year"]'), 'selected', + "The Date Groupby option 'Year' should be deactivated"); + + await testUtils.fields.triggerKey('press', $('.o_searchview_input'), 98); + await testUtils.fields.triggerKey('up', $('.o_searchview_input'), 'enter'); + assert.strictEqual($('.o_searchview_input_container .o_facet_values').eq(1).text().trim(), + "b", + "There should be a filter Foo b"); + + actionManager.destroy(); + }); + QUnit.module('Search Arch'); QUnit.test('arch order of groups of filters preserved', async function (assert) {