summaryrefslogtreecommitdiff
path: root/addons/mail/static/tests/helpers/test_utils.js
diff options
context:
space:
mode:
authorJulien Mougenot <jum@odoo.com>2020-03-17 15:51:13 +0000
committerJulien Mougenot <jum@odoo.com>2020-03-18 14:51:35 +0000
commitc9ce8a07e1d4f7253e4a889d659092d26477b8b6 (patch)
treea677f6c7c601668d1bc426271383c94ada443295 /addons/mail/static/tests/helpers/test_utils.js
parent3ad4abe171e8e7e86ed0e7b7f000e734d8a2ad92 (diff)
[REF] mail: update discuss helpers
Update the 'createDisuss' helper to be appended to the DOM using 'dom.prepend' to benefit of its 'on_(attach|detach)_callback' calls. This allows the mail test suite environment to be closer to the actual action behaviour (having those methods called each time it is created/destroyed). Some tests in which these methods were manually called have been adapted. Also, one of the tests was destroying the action too quickly and exposed an issue within the Discuss action, in the 'on_detach_callback' method. It has thus been fixed as well.
Diffstat (limited to 'addons/mail/static/tests/helpers/test_utils.js')
-rw-r--r--addons/mail/static/tests/helpers/test_utils.js24
1 files changed, 16 insertions, 8 deletions
diff --git a/addons/mail/static/tests/helpers/test_utils.js b/addons/mail/static/tests/helpers/test_utils.js
index f3328c9a1a9..529f2aa6d70 100644
--- a/addons/mail/static/tests/helpers/test_utils.js
+++ b/addons/mail/static/tests/helpers/test_utils.js
@@ -9,12 +9,13 @@ var mailUtils = require('mail.utils');
var AbstractStorageService = require('web.AbstractStorageService');
var Class = require('web.Class');
+const dom = require('web.dom');
var RamStorage = require('web.RamStorage');
const makeTestEnvironment = require('web.test_env');
var testUtils = require('web.test_utils');
var Widget = require('web.Widget');
-const { prepareTarget, nextTick } = testUtils;
+const { prepareTarget } = testUtils;
/**
* Test Utils
*
@@ -30,31 +31,38 @@ const { prepareTarget, nextTick } = testUtils;
* @returns {Promise<Discuss>}
*/
async function createDiscuss(params) {
- var Parent = Widget.extend({
+ const target = prepareTarget(params.debug);
+ const Parent = Widget.extend({
do_push_state: function () {},
});
- var parent = new Parent();
+ const parent = new Parent();
params.archs = params.archs || {
'mail.message,false,search': '<search/>',
};
- testUtils.mock.addMockEnvironment(parent, params);
+ await testUtils.mock.addMockEnvironment(parent, params);
const env = params.env || {};
owl.Component.env = makeTestEnvironment(env);
- var discuss = new Discuss(parent, params);
+ const discuss = new Discuss(parent, params);
// override 'destroy' of discuss so that it calls 'destroy' on the parent
// instead, which is the parent of discuss and the mockServer.
+ const _destroy = discuss.destroy;
discuss.destroy = function () {
// remove the override to properly destroy discuss and its children
// when it will be called the second time (by its parent)
- delete discuss.destroy;
+ discuss.destroy = _destroy;
+ discuss.on_detach_callback();
parent.destroy();
};
- await discuss.appendTo(prepareTarget(params.debug));
- await nextTick();
+ const fragment = document.createDocumentFragment();
+ await discuss.appendTo(fragment);
+ dom.prepend(target, fragment, {
+ callbacks: [{ widget: discuss }],
+ in_DOM: true,
+ });
return discuss;
}