diff --git a/addons/mail/static/src/js/discuss.js b/addons/mail/static/src/js/discuss.js index 79a13c307c8..7b56282565a 100644 --- a/addons/mail/static/src/js/discuss.js +++ b/addons/mail/static/src/js/discuss.js @@ -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(); + } }, //-------------------------------------------------------------------------- diff --git a/addons/mail/static/tests/discuss_tests.js b/addons/mail/static/tests/discuss_tests.js index 8cf73248754..7ef73123e4d 100644 --- a/addons/mail/static/tests/discuss_tests.js +++ b/addons/mail/static/tests/discuss_tests.js @@ -307,10 +307,6 @@ QUnit.test('searchview filter messages', async function (assert) { '', }, }); - // 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(); }); 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} */ 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': '', }; - 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; }