odoo.define('mail/static/src/components/composer_suggestion/composer_suggestion_partner_tests.js', function (require) { 'use strict'; const components = { ComposerSuggestion: require('mail/static/src/components/composer_suggestion/composer_suggestion.js'), }; const { afterEach, beforeEach, createRootComponent, start, } = require('mail/static/src/utils/test_utils.js'); QUnit.module('mail', {}, function () { QUnit.module('components', {}, function () { QUnit.module('composer_suggestion', {}, function () { QUnit.module('composer_suggestion_partner_tests.js', { beforeEach() { beforeEach(this); this.createComposerSuggestion = async props => { await createRootComponent(this, components.ComposerSuggestion, { props, target: this.widget.el, }); }; this.start = async params => { const { env, widget } = await start(Object.assign({}, params, { data: this.data, })); this.env = env; this.widget = widget; }; }, afterEach() { afterEach(this); }, }); QUnit.test('partner mention suggestion displayed', async function (assert) { assert.expect(1); this.data['mail.channel'].records.push({ id: 20 }); await this.start(); const thread = this.env.models['mail.thread'].findFromIdentifyingData({ id: 20, model: 'mail.channel', }); const partner = this.env.models['mail.partner'].create({ id: 7, im_status: 'online', name: "Demo User", }); await this.createComposerSuggestion({ composerLocalId: thread.composer.localId, isActive: true, modelName: 'mail.partner', recordLocalId: partner.localId, }); assert.containsOnce( document.body, `.o_ComposerSuggestion`, "Partner mention suggestion should be present" ); }); QUnit.test('partner mention suggestion correct data', async function (assert) { assert.expect(6); this.data['mail.channel'].records.push({ id: 20 }); await this.start(); const thread = this.env.models['mail.thread'].findFromIdentifyingData({ id: 20, model: 'mail.channel', }); const partner = this.env.models['mail.partner'].create({ email: "demo_user@odoo.com", id: 7, im_status: 'online', name: "Demo User", }); await this.createComposerSuggestion({ composerLocalId: thread.composer.localId, isActive: true, modelName: 'mail.partner', recordLocalId: partner.localId, }); assert.containsOnce( document.body, '.o_ComposerSuggestion', "Partner mention suggestion should be present" ); assert.strictEqual( document.querySelectorAll(`.o_PartnerImStatusIcon`).length, 1, "Partner's im_status should be displayed" ); assert.containsOnce( document.body, '.o_ComposerSuggestion_part1', "Partner's name should be present" ); assert.strictEqual( document.querySelector(`.o_ComposerSuggestion_part1`).textContent, "Demo User", "Partner's name should be displayed" ); assert.containsOnce( document.body, '.o_ComposerSuggestion_part2', "Partner's email should be present" ); assert.strictEqual( document.querySelector(`.o_ComposerSuggestion_part2`).textContent, "(demo_user@odoo.com)", "Partner's email should be displayed" ); }); QUnit.test('partner mention suggestion active', async function (assert) { assert.expect(2); this.data['mail.channel'].records.push({ id: 20 }); await this.start(); const thread = this.env.models['mail.thread'].findFromIdentifyingData({ id: 20, model: 'mail.channel', }); const partner = this.env.models['mail.partner'].create({ id: 7, im_status: 'online', name: "Demo User", }); await this.createComposerSuggestion({ composerLocalId: thread.composer.localId, isActive: true, modelName: 'mail.partner', recordLocalId: partner.localId, }); assert.containsOnce( document.body, '.o_ComposerSuggestion', "Partner mention suggestion should be displayed" ); assert.hasClass( document.querySelector('.o_ComposerSuggestion'), 'active', "should be active initially" ); }); }); }); }); });