diff --git a/addons/web/static/src/legacy/js/control_panel/custom_favorite_item.js b/addons/web/static/src/legacy/js/control_panel/custom_favorite_item.js index 6fbfe827b6c..27db3b680b9 100644 --- a/addons/web/static/src/legacy/js/control_panel/custom_favorite_item.js +++ b/addons/web/static/src/legacy/js/control_panel/custom_favorite_item.js @@ -53,7 +53,7 @@ odoo.define('web.CustomFavoriteItem', function (require) { * @private */ saveFavorite() { - if (!this.state.description.length) { + if (!this.state.description) { this.env.services.notification.notify({ message: this.env._t("A name for your favorite filter is required."), type: 'danger', diff --git a/addons/web/static/src/search/favorite_menu/custom_favorite_item.js b/addons/web/static/src/search/favorite_menu/custom_favorite_item.js index 3369b521bfb..f8c0441e29a 100644 --- a/addons/web/static/src/search/favorite_menu/custom_favorite_item.js +++ b/addons/web/static/src/search/favorite_menu/custom_favorite_item.js @@ -24,7 +24,7 @@ export class CustomFavoriteItem extends Component { * @param {Event} ev */ saveFavorite(ev) { - if (!this.state.description.length) { + if (!this.state.description) { this.notificationService.add( this.env._t("A name for your favorite filter is required."), { type: "danger" } diff --git a/addons/web/static/tests/search/custom_favorite_item_tests.js b/addons/web/static/tests/search/custom_favorite_item_tests.js index 1fbe3c9ef7e..090318b319e 100644 --- a/addons/web/static/tests/search/custom_favorite_item_tests.js +++ b/addons/web/static/tests/search/custom_favorite_item_tests.js @@ -345,6 +345,45 @@ QUnit.module("Search", (hooks) => { } ); + QUnit.test("undefined name for filter shows notification and not error", async function (assert) { + assert.expect(2); + + serviceRegistry.add( + "notification", + { + start() { + return { + add(message, options) { + assert.strictEqual( + message, + "A name for your favorite filter is required.", + "The notification should match: A name for your favorite filter is required." + ); + assert.deepEqual(options, { type: "danger" }); + }, + }; + }, + }, + { force: true } + ); + + await makeWithSearch({ + serverData, + mockRPC: (_, args) => { + if (args.model === "ir.filters" && args.method === "create_or_replace") { + return 7; // fake serverSideId + } + }, + resModel: "foo", + Component: FavoriteMenu, + searchViewId: false, + }); + + await toggleFavoriteMenu(target); + await toggleSaveFavorite(target); + await saveFavorite(target); + }); + QUnit.skip("save search filter in modal", async function (assert) { /** @todo I don't know yet how to convert this test */ // assert.expect(5);