[FIX] web: toggle favorite correctly updates other filters status

When toggling a favorite filter, the options used by
the active date filters/groupbys and the field created
via autocompletion were not correctly cleared, leading
to strange situations. This is fixed by this commit.
This commit is contained in:
Mathieu Duckerts-Antoine
2019-08-07 15:10:57 +00:00
parent 5d64a5114e
commit 691a8a690c
2 changed files with 103 additions and 1 deletions
@@ -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 = [];
}
@@ -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', {
'<filter string="Date Field Filter" name="positive" date="date_field"/>' +
'<filter string="Date Field Groupby" name="coolName" context="{\'group_by\': \'date_field:day\'}"/>' +
'</search>',
'partner,9,search': '<search>'+
'<field string="Foo" name="foo"/>' +
'<filter string="Date Field Filter" name="positive" date="date_field"/>' +
'<filter string="Date Field Groupby" name="coolName" context="{\'group_by\': \'date_field:day\'}"/>' +
'</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) {