[FIX] web: favorites have unique descriptions

In the favorites menu, it was possible to create two
favorites with the same name (contrarily to the
specifications). The root cause of the problem was that
the submenus of the favorites menu were not updated at
all. This commit fixes that situation.

closes odoo/odoo#35495

Signed-off-by: Géry Debongnie (ged) <ged@openerp.com>
This commit is contained in:
Mathieu Duckerts-Antoine
2019-08-07 15:24:06 +00:00
parent 691a8a690c
commit ba4ce71bf5
3 changed files with 93 additions and 0 deletions
@@ -39,6 +39,12 @@ var AddNewFavoriteMenu = Widget.extend({
// Public
//--------------------------------------------------------------------------
/**
* @param {Object} params
*/
update: function (params) {
this.favorites = params.favorites;
},
/**
* Close the menu and re-render the widget.
*/
@@ -48,6 +48,18 @@ var FavoriteMenu = DropdownMenu.extend({
});
},
//--------------------------------------------------------------------------
// Public
//--------------------------------------------------------------------------
/**
* @override
*/
update: function (items) {
this._super.apply(this, arguments);
_.invoke(this.subMenus, 'update', { favorites: this.items });
},
//--------------------------------------------------------------------------
// Private
//--------------------------------------------------------------------------
@@ -8,6 +8,7 @@ var createActionManager = testUtils.createActionManager;
var createControlPanel = testUtils.createControlPanel;
var createView = testUtils.createView;
var patchDate = testUtils.mock.patchDate;
var session = require('web.session');
var controlPanelViewParameters = require('web.controlPanelViewParameters');
var PERIOD_OPTIONS_IDS = controlPanelViewParameters.PERIOD_OPTIONS.map(function (option) {return option.optionId;});
@@ -1051,6 +1052,80 @@ QUnit.module('Search View', {
actionManager.destroy();
});
QUnit.test('favorites have unique descriptions (the submenus of the favorite menu are correctly updated)', async function (assert) {
assert.expect(7);
const UID = session.uid;
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);
},
create_filter: function (event) {
assert.step('create_filter');
assert.deepEqual(event.data.filter, {
"action_id": 1,
"context": {},
"domain": "[]",
"is_default": false,
"model_id": "partner",
"name": "My favorite 2",
"sort": "[]",
"user_id": UID,
});
return Promise.resolve(1).then(event.data.on_success);
}
},
});
testUtils.mock.intercept(actionManager, 'call_service', function (ev) {
if (ev.data.service === 'notification') {
// A notification alerting that another favorite with same name exists
// should be triggered
assert.step('notification');
assert.deepEqual(ev.data.args[0], {
"className": undefined,
"message": "Filter with same name already exists.",
"sticky": undefined,
"title": "Error",
"type": "warning"
});
}
}, true);
await actionManager.doAction(1);
await testUtils.dom.click($('button .fa-star'));
await testUtils.dom.click($('.o_favorites_menu .o_add_favorite'));
await testUtils.fields.editInput($('div.o_favorite_name input'), 'My favorite');
await testUtils.dom.click($('.o_favorites_menu div.o_save_favorite button'));
await testUtils.fields.editInput($('div.o_favorite_name input'), 'My favorite 2');
await testUtils.dom.click($('.o_favorites_menu div.o_save_favorite button'));
await testUtils.dom.click($('.o_favorites_menu .o_add_favorite'));
await testUtils.fields.editInput($('div.o_favorite_name input'), 'My favorite 2');
await testUtils.dom.click($('.o_favorites_menu div.o_save_favorite button'));
assert.verifySteps([
'notification',
'create_filter',
'notification'
])
actionManager.destroy();
});
QUnit.module('Search Arch');
QUnit.test('arch order of groups of filters preserved', async function (assert) {