[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.
This commit is contained in:
Julien Mougenot
2020-03-18 14:51:35 +00:00
parent 3ad4abe171
commit c9ce8a07e1
3 changed files with 19 additions and 19 deletions
+3 -1
View File
@@ -344,7 +344,9 @@ var Discuss = AbstractAction.extend({
on_detach_callback: function () {
this._super();
this.call('mail_service', 'getMailBus').trigger('discuss_open', false);
this._threadsScrolltop[this._thread.getID()] = this._threadWidget.getScrolltop();
if (this._thread) {
this._threadsScrolltop[this._thread.getID()] = this._threadWidget.getScrolltop();
}
},
//--------------------------------------------------------------------------
-10
View File
@@ -307,10 +307,6 @@ QUnit.test('searchview filter messages', async function (assert) {
'</search>',
},
});
// needed to handle events triggered by the controlPanelModel
discuss.on_attach_callback();
await testUtils.nextTick();
assert.containsN(discuss, '.o_thread_message', 2,
"there should be two messages in the inbox mailbox");
assert.strictEqual($('.o_searchview_input').length, 1,
@@ -343,7 +339,6 @@ QUnit.test('searchview filter messages', async function (assert) {
"No matches found",
"should display that there are no matching messages");
discuss.on_detach_callback();
discuss.destroy();
});
@@ -1981,10 +1976,6 @@ QUnit.test('save filter discuss', async function (assert) {
}
}
});
// needed to handle events triggered by the controlPanelModel
discuss.on_attach_callback();
await testUtils.nextTick();
assert.containsOnce(discuss, '.o_searchview_input_container', 'search view input present');
await cpHelpers.editSearch(discuss, "she was born in a hurricane");
@@ -1999,7 +1990,6 @@ QUnit.test('save filter discuss', async function (assert) {
await cpHelpers.editFavoriteName(discuss, "War");
await cpHelpers.saveFavorite(discuss);
discuss.on_detach_callback();
discuss.destroy();
});
+16 -8
View File
@@ -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;
}