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 208f3b7ee19..836a4eceb59 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 @@ -409,7 +409,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 = []; + const group = self.groups[groupId]; + group.activeFilterIds.forEach(id => { + const filter = self.filters[id[0]]; + if (filter.autoCompleteValues) { + filter.autoCompleteValues = []; + } + if (filter.currentOptionIds) { + filter.currentOptionIds.clear(); + } + }) + 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 e24a0c46bfc..658e1472d49 100644 --- a/addons/web/static/tests/views/search_view_tests.js +++ b/addons/web/static/tests/views/search_view_tests.js @@ -209,6 +209,11 @@ QUnit.module('Search View', { 'partner,9,search': ''+ '' + '', + 'partner,10,search': ''+ + '' + + '' + + '' + + '', }; @@ -1080,6 +1085,89 @@ QUnit.module('Search View', { controlPanel.destroy(); }); + QUnit.test('toggle favorite correctly clears filter, groupbys and field "options"', async function (assert) { + assert.expect(8); + + const unpatchDate = patchDate(2019,6,31,13,43,0); + + 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); + }, + }, + }); + + this.actions[11].search_view_id = [10, 'search']; + 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: July 2019", + "There should be a filter facet with label 'Date Field Filter: July 2019'"); + + 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(); + unpatchDate(); + }); + QUnit.module('Search Arch'); QUnit.test('arch order of groups of filters preserved', async function (assert) {