diff options
| author | Joseph Caburnay <jcb@odoo.com> | 2020-03-13 08:08:32 +0000 |
|---|---|---|
| committer | Joseph Caburnay <jcb@odoo.com> | 2020-03-13 08:41:15 +0000 |
| commit | 78beadb748a0bc7f533c8899dd872eaa75b893c5 (patch) | |
| tree | 7baccaeaa0ee932529a3664f49fe130fdd3e875e /addons/web/static/tests | |
| parent | c7f095396e88b67844bf0e4f1d35847f59a80400 (diff) | |
[REV] web: allow patching getters
This reverts commit d6b854306cae245343a7acb9edc4178d245a49fe.
The reverted commit introduced issues in patching class methods.
Introducing getters in the patch function is not actually compatible
with the original method patching.
Test for patch method is also introduced to guard patch from future
invalid modification that happened.
A more robust way of patching classes is now being developed.
closes odoo/odoo#47557
Signed-off-by: Aaron Bohy (aab) <aab@odoo.com>
Diffstat (limited to 'addons/web/static/tests')
| -rw-r--r-- | addons/web/static/tests/core/util_tests.js | 89 |
1 files changed, 22 insertions, 67 deletions
diff --git a/addons/web/static/tests/core/util_tests.js b/addons/web/static/tests/core/util_tests.js index f33a76d87c1..3403c9effaf 100644 --- a/addons/web/static/tests/core/util_tests.js +++ b/addons/web/static/tests/core/util_tests.js @@ -101,85 +101,40 @@ QUnit.module('core', {}, function () { assert.strictEqual(human_number(-1.012e+43, 2, 2), '-1.01e+43'); }); - QUnit.test('patch a class with getter', function (assert) { - assert.expect(13); + QUnit.test('patch a class', function(assert) { + assert.expect(4); - const { patch } = utils; - - class TestClass { - get val() { - return 'aaa'; + class Parent { + foo() { + return 'Parent foo'; } } - const testInstance = new TestClass(); - assert.strictEqual(testInstance.val, 'aaa'); - - // Extend `val` - - const removePatch1 = patch(TestClass, 'patch1', { - get val() { - return this._super + 'bbb'; - }, - }); - assert.strictEqual(testInstance.val, 'aaabbb'); - - const removePatch2 = patch(TestClass, 'patch2', { - get val() { - return this._super + 'ccc'; - }, - }); - assert.strictEqual(testInstance.val, 'aaabbbccc'); - - removePatch1(); - assert.strictEqual(testInstance.val, 'aaaccc'); - - removePatch2(); - assert.strictEqual(testInstance.val, 'aaa'); - - // Add getters + class Child extends Parent { + bar() { + return 'Child bar'; + } + } - const removeMorePatch1 = patch(TestClass, 'more-patch-1', { - get realVal() { - return `${this.wrapper.start}${this.val}${this.wrapper.end}` + const removePatch = utils.patch(Child, 'patch', { + foo() { + return this._super() + ' patch foo'; }, - get wrapper() { - return { - start: '(', - end: ')', - } - } - }) - assert.strictEqual(testInstance.realVal, '(aaa)'); - - const removeMorePatch2 = patch(TestClass, 'more-patch-2', { - get wrapper() { - return { - start: `[${this._super.start}`, - end: `${this._super.end}]`, - } + bar() { + return this._super() + ' patch bar'; } }) - assert.strictEqual(testInstance.realVal, '[(aaa)]'); - const removeMorePatch3 = patch(TestClass, 'more-patch-3', { - get realVal() { - return `${this._super} - augmented`; - } - }) - assert.strictEqual(testInstance.realVal, '[(aaa)] - augmented'); + const child = new Child(); - removeMorePatch2(); - assert.strictEqual(testInstance.realVal, '(aaa) - augmented'); + assert.strictEqual(child.foo(), 'Parent foo patch foo') + assert.strictEqual(child.bar(), 'Child bar patch bar') - removeMorePatch3(); - assert.strictEqual(testInstance.realVal, '(aaa)'); + removePatch(); - removeMorePatch1(); - assert.strictEqual(testInstance.realVal, undefined); - assert.strictEqual(testInstance.wrapper, undefined); - assert.strictEqual(testInstance.val, 'aaa'); - }); + assert.strictEqual(child.foo(), 'Parent foo'); + assert.strictEqual(child.bar(), 'Child bar'); + }) }); |
