From 6100d8014ed29fb06c5a7e0a4e6f273e3d68dcf4 Mon Sep 17 00:00:00 2001 From: Samuel Degueldre Date: Tue, 3 Aug 2021 07:23:47 +0000 Subject: [PATCH] [FIX] web: order items by sequence globally instead of by category Before this commit, all items from the same category were grouped together because we were sorting items within categories rather than sorting all items after getting them from the various categories. closes odoo/odoo#74598 Signed-off-by: Aaron Bohy (aab) --- .../static/src/core/debug/debug_context.js | 25 +++++----- .../tests/core/debug/debug_manager_tests.js | 48 ++++++++++++++++++- 2 files changed, 60 insertions(+), 13 deletions(-) diff --git a/addons/web/static/src/core/debug/debug_context.js b/addons/web/static/src/core/debug/debug_context.js index 70d94f29281..d1c102cc46c 100644 --- a/addons/web/static/src/core/debug/debug_context.js +++ b/addons/web/static/src/core/debug/debug_context.js @@ -44,18 +44,19 @@ class DebugContext { async getItems(env) { const accessRights = await getAccessRights(this.orm); - return [...this.categories.entries()].flatMap(([category, contexts]) => { - return debugRegistry - .category(category) - .getAll() - .map((factory) => factory(Object.assign({ env, accessRights }, ...contexts))) - .filter(Boolean) - .sort((x, y) => { - const xSeq = x.sequence || 1000; - const ySeq = y.sequence || 1000; - return xSeq - ySeq; - }); - }); + return [...this.categories.entries()] + .flatMap(([category, contexts]) => { + return debugRegistry + .category(category) + .getAll() + .map((factory) => factory(Object.assign({ env, accessRights }, ...contexts))); + }) + .filter(Boolean) + .sort((x, y) => { + const xSeq = x.sequence || 1000; + const ySeq = y.sequence || 1000; + return xSeq - ySeq; + }); } } diff --git a/addons/web/static/tests/core/debug/debug_manager_tests.js b/addons/web/static/tests/core/debug/debug_manager_tests.js index 4f852150336..8b90fac071f 100644 --- a/addons/web/static/tests/core/debug/debug_manager_tests.js +++ b/addons/web/static/tests/core/debug/debug_manager_tests.js @@ -22,7 +22,7 @@ const { xml } = tags; export class DebugMenuParent extends Component { setup() { - useOwnDebugContext({ categories: ["default"] }); + useOwnDebugContext({ categories: ["default", "custom"] }); } } DebugMenuParent.template = xml``; @@ -118,6 +118,52 @@ QUnit.module("DebugMenu", (hooks) => { assert.verifySteps(["callback item_2", "callback item_1", "callback item_3"]); }); + QUnit.test("items are sorted by sequence regardless of category", async (assert) => { + debugRegistry + .category("default") + .add("item_1", () => { + return { + type: "item", + description: "Item 4", + sequence: 4, + }; + }) + .add("item_2", () => { + return { + type: "item", + description: "Item 1", + sequence: 1, + }; + }); + debugRegistry + .category("custom") + .add("item_1", () => { + return { + type: "item", + description: "Item 3", + sequence: 3, + }; + }) + .add("item_2", () => { + return { + type: "item", + description: "Item 2", + sequence: 2, + }; + }); + const env = await makeTestEnv(testConfig); + const debugManager = await mount(DebugMenuParent, { env, target }); + registerCleanup(() => debugManager.destroy()); + await click(debugManager.el.querySelector("button.o_dropdown_toggler")); + const items = [ + ...debugManager.el.querySelectorAll("ul.o_dropdown_menu li.o_dropdown_item span"), + ]; + assert.deepEqual( + items.map((el) => el.textContent), + ["Item 1", "Item 2", "Item 3", "Item 4"] + ); + }); + QUnit.test("Don't display the DebugMenu if debug mode is disabled", async (assert) => { const env = await makeTestEnv(testConfig); const actionDialog = await mount(ActionDialog, {