diff options
| author | Aaron Bohy <aab@odoo.com> | 2020-06-05 07:20:11 +0000 |
|---|---|---|
| committer | Aaron Bohy <aab@odoo.com> | 2020-06-12 09:47:48 +0000 |
| commit | dc260c324170a90fa737cd21dd528e39d658d9b6 (patch) | |
| tree | 9d839c10e56f7fa913e7f761bc8b2c5debc3d28b /addons/web/static/tests/owl_compatibility_tests.js | |
| parent | 26fe23201bb495176d14c15c8866e8fc72ca044c (diff) | |
[IMP] web: tests: rework mock helpers
This commit reworks the test helpers, following recent changes on
services deployed in the Owl env.
Diffstat (limited to 'addons/web/static/tests/owl_compatibility_tests.js')
| -rw-r--r-- | addons/web/static/tests/owl_compatibility_tests.js | 43 |
1 files changed, 22 insertions, 21 deletions
diff --git a/addons/web/static/tests/owl_compatibility_tests.js b/addons/web/static/tests/owl_compatibility_tests.js index f49fee5f78a..1cc463d0eeb 100644 --- a/addons/web/static/tests/owl_compatibility_tests.js +++ b/addons/web/static/tests/owl_compatibility_tests.js @@ -5,9 +5,9 @@ odoo.define('web.OwlCompatibilityTests', function (require) { const testUtils = require('web.test_utils'); const Widget = require('web.Widget'); - const getMockedOwlEnv = testUtils.mock.getMockedOwlEnv; const makeTestPromise = testUtils.makeTestPromise; const nextTick = testUtils.nextTick; + const addMockEnvironmentOwl = testUtils.mock.addMockEnvironmentOwl; const { Component, tags, useState } = owl; const { xml } = tags; @@ -448,17 +448,17 @@ odoo.define('web.OwlCompatibilityTests', function (require) { this.MyWidget = MyWidget; } } - Parent.env = getMockedOwlEnv({ - mockRPC: function (route, args) { - assert.step(`${route} ${args.val}`); - return Promise.resolve(); - }, - }); Parent.template = xml` <div> <ComponentAdapter Component="MyWidget"/> </div>`; Parent.components = { ComponentAdapter }; + const cleanUp = await addMockEnvironmentOwl(Parent, { + mockRPC: function (route, args) { + assert.step(`${route} ${args.val}`); + return Promise.resolve(); + }, + }); const target = testUtils.prepareTarget(); const parent = new Parent(); @@ -468,6 +468,7 @@ odoo.define('web.OwlCompatibilityTests', function (require) { assert.verifySteps(['some/route 2']); parent.destroy(); + cleanUp(); }); QUnit.test("sub widget that calls a service", async function (assert) { @@ -493,16 +494,14 @@ odoo.define('web.OwlCompatibilityTests', function (require) { this.MyWidget = MyWidget; } } - const env = getMockedOwlEnv(); - env.services.math = { - sqrt: v => Math.sqrt(v), - }; - Parent.env = env; Parent.template = xml` <div> <ComponentAdapter Component="MyWidget"/> </div>`; Parent.components = { ComponentAdapter }; + Parent.env.services.math = { + sqrt: v => Math.sqrt(v), + }; const target = testUtils.prepareTarget(); const parent = new Parent(); @@ -525,20 +524,21 @@ odoo.define('web.OwlCompatibilityTests', function (require) { this.MyWidget = MyWidget; } } - Parent.env = getMockedOwlEnv({ - session: { key: 'value' }, - }); Parent.template = xml` <div> <ComponentAdapter Component="MyWidget"/> </div>`; Parent.components = { ComponentAdapter }; + const cleanUp = await addMockEnvironmentOwl(Parent, { + session: { key: 'value' }, + }); const target = testUtils.prepareTarget(); const parent = new Parent(); await parent.mount(target); parent.destroy(); + cleanUp(); }); QUnit.test("sub widget that calls load_views", async function (assert) { @@ -555,7 +555,12 @@ odoo.define('web.OwlCompatibilityTests', function (require) { this.MyWidget = MyWidget; } } - Parent.env = getMockedOwlEnv({ + Parent.template = xml` + <div> + <ComponentAdapter Component="MyWidget"/> + </div>`; + Parent.components = { ComponentAdapter }; + const cleanUp = await addMockEnvironmentOwl(Parent, { mockRPC: function (route, args) { assert.strictEqual(route, '/web/dataset/call_kw/some_model'); assert.deepEqual(args.kwargs.context, { x: 2 }); @@ -563,11 +568,6 @@ odoo.define('web.OwlCompatibilityTests', function (require) { return Promise.resolve(); }, }); - Parent.template = xml` - <div> - <ComponentAdapter Component="MyWidget"/> - </div>`; - Parent.components = { ComponentAdapter }; const target = testUtils.prepareTarget(); const parent = new Parent(); @@ -576,6 +576,7 @@ odoo.define('web.OwlCompatibilityTests', function (require) { assert.strictEqual(parent.el.innerHTML, '<div></div>'); parent.destroy(); + cleanUp(); }); QUnit.test("sub widgets in a t-if/t-else", async function (assert) { |
