Files
odoo_source/addons/mail/static/tests/helpers/test_utils.js
T
b1ef0001f6 [REF] *: adapt all client actions
to ControlPanel/Search view refactoring.

The ControlPanel being now inside the DOM of client actions, those
existing widgets needed to be adapted (in the way they define if
and how they want a ControlPanel, and in the way the manipulate
their DOM as it slightly changed). Tests needed to be adapted as
well.

Part of task 1893568

Co-authored-by: Mathieu Duckerts-Antoine <dam@odoo.com>
Co-authored-by: Martin Geubelle <mge@odoo.com>
2018-12-07 13:16:07 +00:00

100 lines
2.8 KiB
JavaScript

odoo.define('mail.testUtils', function (require) {
"use strict";
var BusService = require('bus.BusService');
var Discuss = require('mail.Discuss');
var MailService = require('mail.Service');
var AbstractStorageService = require('web.AbstractStorageService');
var Class = require('web.Class');
var ControlPanelView = require('web.ControlPanelView');
var RamStorage = require('web.RamStorage');
var testUtils = require('web.test_utils');
var Widget = require('web.Widget');
/**
* Test Utils
*
* In this module, we define some utility functions to create mock objects
* in the mail module, such as the BusService or Discuss.
*/
/**
* Create asynchronously a discuss widget.
* This is async due to mail_manager/mail_service that needs to be ready.
*
* @param {Object} params
* @return {$.Promise} resolved with the discuss widget
*/
function createDiscuss(params) {
var Parent = Widget.extend({
do_push_state: function () {},
});
var parent = new Parent();
params.archs = params.archs || {
'mail.message,false,search': '<search/>',
};
testUtils.mock.addMockEnvironment(parent, params);
var discuss = new Discuss(parent, params);
var selector = params.debug ? 'body' : '#qunit-fixture';
// override 'destroy' of discuss so that it calls 'destroy' on the parent
// instead, which is the parent of discuss and the mockServer.
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;
parent.destroy();
};
return discuss.appendTo($(selector)).then(function () {
return discuss;
});
}
var MockMailService = Class.extend({
bus_service: function () {
return BusService.extend({
_poll: function () {}, // Do nothing
isOdooFocused: function () { return true; },
updateOption: function () {},
});
},
mail_service: function () {
return MailService;
},
local_storage: function () {
return AbstractStorageService.extend({
storage: new RamStorage(),
});
},
getServices: function () {
return {
mail_service: this.mail_service(),
bus_service: this.bus_service(),
local_storage: this.local_storage(),
};
},
});
/**
* Returns the list of mail services required by the mail components: a
* mail_service, and its two dependencies bus_service and local_storage.
*
* @return {AbstractService[]} an array of 3 services: mail_service, bus_service
* and local_storage, in that order
*/
function getMailServices() {
return new MockMailService().getServices();
}
return {
MockMailService: MockMailService,
createDiscuss: createDiscuss,
getMailServices: getMailServices,
};
});