From a758f8f307fe74af93631b77f498db43a845c526 Mon Sep 17 00:00:00 2001 From: Mathieu Duckerts-Antoine Date: Wed, 10 Jun 2020 09:29:11 +0000 Subject: [PATCH] [FIX] web: don't forget initial registry entries MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The entries comming from the optional parameter 'mapping' passed at the instantiation of a registry were never considered when returning the registry keys or entries. This is no longer the case. closes odoo/odoo#52768 X-original-commit: e094ddd0ffaf3357e64ca5941ffc2e0454c24ab7 Signed-off-by: Géry Debongnie (ged) --- addons/web/static/src/js/core/registry.js | 13 ++++++++++-- .../web/static/tests/core/registry_tests.js | 21 +++++++++++++++++++ 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/addons/web/static/src/js/core/registry.js b/addons/web/static/src/js/core/registry.js index cf898c647ca..6089ccc827e 100644 --- a/addons/web/static/src/js/core/registry.js +++ b/addons/web/static/src/js/core/registry.js @@ -68,7 +68,12 @@ var Registry = Class.extend({ * @returns {Object} */ entries: function () { - return Object.create(this.map); + var entries = {}; + var keys = this.keys(); + for (var i = 0; i < keys.length; i++) { + entries[keys[i]] = this.map[keys[i]]; + } + return entries; }, /** * Returns the value associated to the given key. @@ -105,7 +110,11 @@ var Registry = Class.extend({ keys: function () { var self = this; if (!this._sortedKeys) { - this._sortedKeys = _.sortBy(Object.keys(this.map), function (key) { + var keys = []; + for (var key in this.map) { + keys.push(key); + } + this._sortedKeys = _.sortBy(keys, function (key) { return self._scoreMapping[key] || 0; }); } diff --git a/addons/web/static/tests/core/registry_tests.js b/addons/web/static/tests/core/registry_tests.js index f87238fafb8..fdc437c23ee 100644 --- a/addons/web/static/tests/core/registry_tests.js +++ b/addons/web/static/tests/core/registry_tests.js @@ -19,6 +19,27 @@ QUnit.module('core', {}, function () { assert.strictEqual(registry.get('foo'), foo); }); + QUnit.test('get initial keys', function (assert) { + assert.expect(1); + + var registry = new Registry({ a: 1, }); + assert.deepEqual( + registry.keys(), + ['a'], + "keys on prototype should be returned" + ); + }); + + QUnit.test('get initial entries', function (assert) { + assert.expect(1); + + var registry = new Registry({ a: 1, }); + assert.deepEqual( + registry.entries(), + { a: 1, }, + "entries on prototype should be returned" + ); + }); QUnit.test('multiget', function (assert) { assert.expect(1);