diff options
| author | Aaron Bohy <aab@odoo.com> | 2020-06-05 09:18:14 +0000 |
|---|---|---|
| committer | Aaron Bohy <aab@odoo.com> | 2020-06-12 09:47:48 +0000 |
| commit | b4ba0fc34082deec8ca6c871ce7a203c0a3a61a4 (patch) | |
| tree | 27451423f32b218e699d3135c398d338b249c5cd /addons/mail/static/tests/document_thread_window_tests.js | |
| parent | dc260c324170a90fa737cd21dd528e39d658d9b6 (diff) | |
[FIX] *: adapt tests to env rework
This commit adapts tests following recent changes on the helpers.
The main change is that addMockEnvironment (and all functions using
it) are now async, as they need to wait for services to be started.
Diffstat (limited to 'addons/mail/static/tests/document_thread_window_tests.js')
| -rw-r--r-- | addons/mail/static/tests/document_thread_window_tests.js | 66 |
1 files changed, 38 insertions, 28 deletions
diff --git a/addons/mail/static/tests/document_thread_window_tests.js b/addons/mail/static/tests/document_thread_window_tests.js index f01ab0925f2..c4a84040433 100644 --- a/addons/mail/static/tests/document_thread_window_tests.js +++ b/addons/mail/static/tests/document_thread_window_tests.js @@ -1,6 +1,8 @@ odoo.define('mail.documentThreadWindowTests', function (require) { "use strict"; +const Bus = require('web.Bus'); +const LocalStorageService = require('web.LocalStorageService'); var mailTestUtils = require('mail.testUtils'); var MessagingMenu = require('mail.systray.MessagingMenu'); @@ -128,20 +130,23 @@ QUnit.test('open a document thread in a thread window', async function (assert) QUnit.test('expand a document thread window', async function (assert) { assert.expect(4); + const bus = new Bus(); + bus.on('do-action', null, function (payload) { + assert.deepEqual(payload.action, { + res_id: 1, + res_model: 'some.res.model', + type: 'ir.actions.act_window', + views: [[false, 'form']], + }, "should open the document in form view"); + }); + var messagingMenu = new MessagingMenu(); await testUtils.mock.addMockEnvironment(messagingMenu, { services: this.services, data: this.data, session: this.session, - intercepts: { - do_action: function (ev) { - assert.deepEqual(ev.data.action, { - res_id: 1, - res_model: 'some.res.model', - type: 'ir.actions.act_window', - views: [[false, 'form']], - }, "should open the document in form view"); - }, + env: { + bus }, }); await messagingMenu.appendTo($('#qunit-fixture')); @@ -177,8 +182,18 @@ QUnit.test('post messages in a document thread window', async function (assert) res_id: 1, }; var messagingMenu = new MessagingMenu(); + const MockedLocalStorageService = LocalStorageService.extend({ + setItem(key, value) { + if (key === 'mail.document_threads_last_message') { + assert.deepEqual(value.messageData, newMessage, + "should write sent message in local storage, to share info with other tabs"); + } + }, + }); await testUtils.mock.addMockEnvironment(messagingMenu, { - services: this.services, + services: Object.assign(this.services, { + local_storage: MockedLocalStorageService, + }), data: this.data, session: this.session, mockRPC: function (route, args) { @@ -198,13 +213,7 @@ QUnit.test('post messages in a document thread window', async function (assert) return this._super.apply(this, arguments); }, }); - testUtils.mock.intercept(messagingMenu, 'call_service', function (ev) { - if (ev.data.service === 'local_storage' && ev.data.method === 'setItem' && - ev.data.args[0] === 'mail.document_threads_last_message') { - assert.deepEqual(ev.data.args[1].messageData, newMessage, - "should write sent message in local storage, to share info with other tabs"); - } - }, true); + await messagingMenu.appendTo($('#qunit-fixture')); // toggle the messaging menu and open the documentThread @@ -229,24 +238,25 @@ QUnit.test('post messages in a document thread window', async function (assert) QUnit.test('open, fold, unfold and close a document thread window', async function (assert) { assert.expect(20); var messagingMenu = new MessagingMenu(); - await testUtils.mock.addMockEnvironment(messagingMenu, { - services: this.services, - data: this.data, - session: this.session, - }); - await testUtils.nextTick(); - testUtils.mock.intercept(messagingMenu, 'call_service', function (ev) { - if (ev.data.service === 'local_storage' && ev.data.method === 'setItem') { - const key = ev.data.args[0]; + const MockedLocalStorageService = LocalStorageService.extend({ + setItem(key, value) { if (key === 'mail.document_threads_state/some.res.model_1') { - const state = ev.data.args[1].state; + const state = value.state; assert.ok(state); assert.ok(state.name); assert.ok(state.windowState); assert.step(`${key}: { name: "${state.name}", windowState: '${state.windowState}' }`); } } - }, true); + }); + await testUtils.mock.addMockEnvironment(messagingMenu, { + services: Object.assign(this.services, { + local_storage: MockedLocalStorageService, + }), + data: this.data, + session: this.session, + }); + await testUtils.nextTick(); await messagingMenu.appendTo($('#qunit-fixture')); // toggle the messaging menu and open the documentThread |
