summaryrefslogtreecommitdiff
path: root/addons/mail/static/tests/chatter_tests.js
diff options
context:
space:
mode:
Diffstat (limited to 'addons/mail/static/tests/chatter_tests.js')
-rw-r--r--addons/mail/static/tests/chatter_tests.js147
1 files changed, 147 insertions, 0 deletions
diff --git a/addons/mail/static/tests/chatter_tests.js b/addons/mail/static/tests/chatter_tests.js
index 2bb5742e378..f268851463d 100644
--- a/addons/mail/static/tests/chatter_tests.js
+++ b/addons/mail/static/tests/chatter_tests.js
@@ -11,7 +11,9 @@ var testUtils = require('web.test_utils');
var BasicComposer = Composers.BasicComposer;
+var createAsyncView = testUtils.createAsyncView;
var createView = testUtils.createView;
+var createAsyncView = testUtils.createAsyncView;
QUnit.module('mail', {}, function () {
@@ -862,5 +864,150 @@ QUnit.test('followers widget: do not display follower duplications', function (a
form.destroy();
});
+QUnit.test('does not render and crash when destroyed before chat system is ready', function (assert) {
+ assert.expect(0);
+
+ var def = $.Deferred();
+
+ var form = createView({
+ View: FormView,
+ model: 'partner',
+ data: this.data,
+ arch: '<form string="Partners">' +
+ '<sheet>' +
+ '<field name="foo"/>' +
+ '</sheet>' +
+ '<div class="oe_chatter">' +
+ '<field name="message_follower_ids" widget="mail_followers"/>' +
+ '<field name="message_ids" widget="mail_thread"/>' +
+ '<field name="activity_ids" widget="mail_activity"/>' +
+ '</div>' +
+ '</form>',
+ res_id: 2,
+ mockRPC: function (route, args) {
+ if (route === '/mail/read_followers') {
+ return $.when({
+ followers: [],
+ subtypes: [],
+ });
+ }
+ return this._super(route, args);
+ },
+ intercepts: {
+ chat_manager_ready: function (event) {
+ // we delay the return of the chat_manager ready event
+ event.data.callback(def);
+ },
+ get_messages: function (event) {
+ event.stopPropagation();
+ event.data.callback($.when([{
+ attachment_ids: [],
+ body: "",
+ date: moment("2016-12-20 09:35:40"),
+ id: 34,
+ res_id: 3,
+ author_id: ["3", "Fu Ck Mil Grom"],
+ }]));
+ },
+ get_bus: function (event) {
+ event.stopPropagation();
+ event.data.callback(new Bus());
+ },
+ get_session: function (event) {
+ event.stopPropagation();
+ event.data.callback({uid: 1});
+ },
+ },
+ });
+
+ form.destroy();
+ // here, the chat_manager system is ready, and the chatter can try to render
+ // itself. We simply make sure here that no crashes occur (since the form
+ // view is destroyed, all rpcs will be dropped, and many other mechanisms
+ // relying on events will not work, such as _getBus)
+ def.resolve();
+});
+
+QUnit.module('FieldMany2ManyTagsEmail', {
+ beforeEach: function () {
+ this.data = {
+ partner: {
+ fields: {
+ display_name: { string: "Displayed name", type: "char" },
+ timmy: { string: "pokemon", type: "many2many", relation: 'partner_type'},
+ },
+ records: [{
+ id: 1,
+ display_name: "first record",
+ timmy: [],
+ }],
+ },
+ partner_type: {
+ fields: {
+ name: {string: "Partner Type", type: "char"},
+ email: {string: "Email", type: "char"},
+ },
+ records: [
+ {id: 12, display_name: "gold", email: 'coucou@petite.perruche'},
+ {id: 14, display_name: "silver", email: ''},
+ ]
+ },
+ };
+ },
+});
+
+QUnit.test('fieldmany2many tags email', function (assert) {
+ assert.expect(11);
+ var done = assert.async();
+
+ this.data.partner.records[0].timmy = [12, 14];
+
+ // the modals need to be closed before the form view rendering
+ createAsyncView({
+ View: FormView,
+ model: 'partner',
+ data: this.data,
+ res_id: 1,
+ arch:'<form string="Partners">' +
+ '<sheet>' +
+ '<field name="display_name"/>' +
+ '<field name="timmy" widget="many2many_tags_email"/>' +
+ '</sheet>' +
+ '</form>',
+ viewOptions: {
+ mode: 'edit',
+ },
+ mockRPC: function (route, args) {
+ if (args.method ==='read' && args.model === 'partner_type') {
+ assert.step(args.args[0]);
+ assert.deepEqual(args.args[1] , ['display_name', 'email'], "should read the email");
+ }
+ return this._super.apply(this, arguments);
+ },
+ archs: {
+ 'partner_type,false,form': '<form string="Types"><field name="display_name"/><field name="email"/></form>',
+ },
+ }).then(function (form) {
+ // should read it 3 times (1 with the form view, one with the form dialog and one after save)
+ assert.verifySteps([[12, 14], [14], [14]]);
+ assert.strictEqual(form.$('.o_field_many2manytags[name="timmy"] span.o_tag_color_10').length, 2,
+ "the second tag should be present");
+
+ form.destroy();
+ done();
+ });
+
+ assert.strictEqual($('.modal-body.o_act_window').length, 1,
+ "there should be one modal opened to edit the empty email");
+ assert.strictEqual($('.modal-body.o_act_window input[name="display_name"]').val(), "silver",
+ "the opened modal should be a form view dialog with the partner_type 14");
+ assert.strictEqual($('.modal-body.o_act_window input[name="email"]').length, 1,
+ "there should be an email field in the modal");
+
+ // set the email and save the modal (will render the form view)
+ $('.modal-body.o_act_window input[name="email"]').val('coucou@petite.perruche').trigger('input');
+ $('.modal-footer .btn-primary').click();
+});
+
});
});