diff options
| author | stephanchrst <stephanchrst@gmail.com> | 2022-05-10 21:51:50 +0700 |
|---|---|---|
| committer | stephanchrst <stephanchrst@gmail.com> | 2022-05-10 21:51:50 +0700 |
| commit | 3751379f1e9a4c215fb6eb898b4ccc67659b9ace (patch) | |
| tree | a44932296ef4a9b71d5f010906253d8c53727726 /addons/website_livechat/static/src/components/discuss | |
| parent | 0a15094050bfde69a06d6eff798e9a8ddf2b8c21 (diff) | |
initial commit 2
Diffstat (limited to 'addons/website_livechat/static/src/components/discuss')
3 files changed, 312 insertions, 0 deletions
diff --git a/addons/website_livechat/static/src/components/discuss/discuss.js b/addons/website_livechat/static/src/components/discuss/discuss.js new file mode 100644 index 00000000..778b1513 --- /dev/null +++ b/addons/website_livechat/static/src/components/discuss/discuss.js @@ -0,0 +1,31 @@ +odoo.define('website_livechat/static/src/components/discuss/discuss.js', function (require) { +'use strict'; + +const components = { + Discuss: require('mail/static/src/components/discuss/discuss.js'), + VisitorBanner: require('website_livechat/static/src/components/visitor_banner/visitor_banner.js'), +}; + +components.Discuss.patch('website_livechat/static/src/components/discuss/discuss.js', T => + class extends T { + + /** + * @override + */ + _useStoreSelector(props) { + const res = super._useStoreSelector(...arguments); + const thread = res.thread; + const visitor = thread && thread.visitor; + return Object.assign({}, res, { + visitor, + }); + } + + } +); + +Object.assign(components.Discuss.components, { + VisitorBanner: components.VisitorBanner, +}); + +}); diff --git a/addons/website_livechat/static/src/components/discuss/discuss.xml b/addons/website_livechat/static/src/components/discuss/discuss.xml new file mode 100644 index 00000000..af5a1469 --- /dev/null +++ b/addons/website_livechat/static/src/components/discuss/discuss.xml @@ -0,0 +1,12 @@ +<?xml version="1.0" encoding="UTF-8"?> +<templates xml:space="preserve"> + <t t-inherit="mail.Discuss.content" t-inherit-mode="extension"> + <xpath expr="//*[hasclass('o_Discuss_thread')]" position="before"> + <t t-if="discuss.thread.visitor"> + <VisitorBanner + visitorLocalId="discuss.thread.visitor.localId" + /> + </t> + </xpath> + </t> +</templates> diff --git a/addons/website_livechat/static/src/components/discuss/discuss_tests.js b/addons/website_livechat/static/src/components/discuss/discuss_tests.js new file mode 100644 index 00000000..153e55e4 --- /dev/null +++ b/addons/website_livechat/static/src/components/discuss/discuss_tests.js @@ -0,0 +1,269 @@ +odoo.define('website_livechat/static/src/components/discuss/discuss_tests.js', function (require) { +'use strict'; + +const { + afterEach, + beforeEach, + start, +} = require('mail/static/src/utils/test_utils.js'); + +QUnit.module('website_livechat', {}, function () { +QUnit.module('components', {}, function () { +QUnit.module('discuss', {}, function () { +QUnit.module('discuss_tests.js', { + beforeEach() { + beforeEach(this); + + this.start = async params => { + const { env, widget } = await start(Object.assign({}, params, { + autoOpenDiscuss: true, + data: this.data, + hasDiscuss: true, + })); + this.env = env; + this.widget = widget; + }; + }, + afterEach() { + afterEach(this); + }, +}); + +QUnit.test('rendering of visitor banner', async function (assert) { + assert.expect(13); + + this.data['res.country'].records.push({ + id: 11, + code: 'FAKE', + }); + this.data['website.visitor'].records.push({ + id: 11, + country_id: 11, + display_name: 'Visitor #11', + history: 'Home → Contact', + is_connected: true, + lang: "English", + website: "General website", + }); + this.data['mail.channel'].records.push({ + channel_type: 'livechat', + id: 11, + livechat_operator_id: this.data.currentPartnerId, + livechat_visitor_id: 11, + members: [this.data.currentPartnerId, this.data.publicPartnerId], + }); + await this.start({ + discuss: { + context: { + active_id: 'mail.channel_11', + }, + }, + }); + assert.containsOnce( + document.body, + '.o_VisitorBanner', + "should have a visitor banner", + ); + assert.containsOnce( + document.body, + '.o_VisitorBanner_avatar', + "should show the visitor avatar in the banner", + ); + assert.strictEqual( + document.querySelector('.o_VisitorBanner_avatar').dataset.src, + "/mail/static/src/img/smiley/avatar.jpg", + "should show the default avatar", + ); + assert.containsOnce( + document.body, + '.o_VisitorBanner_onlineStatusIcon', + "should show the visitor online status icon on the avatar", + ); + assert.strictEqual( + document.querySelector('.o_VisitorBanner_country').dataset.src, + "/base/static/img/country_flags/FAKE.png", + "should show the flag of the country of the visitor", + ); + assert.containsOnce( + document.body, + '.o_VisitorBanner_visitor', + "should show the visitor name in the banner", + ); + assert.strictEqual( + document.querySelector('.o_VisitorBanner_visitor').textContent, + "Visitor #11", + "should have 'Visitor #11' as visitor name", + ); + assert.containsOnce( + document.body, + '.o_VisitorBanner_language', + "should show the visitor language in the banner", + ); + assert.strictEqual( + document.querySelector('.o_VisitorBanner_language').textContent, + "English", + "should have 'English' as language of the visitor", + ); + assert.containsOnce( + document.body, + '.o_VisitorBanner_website', + "should show the visitor website in the banner", + ); + assert.strictEqual( + document.querySelector('.o_VisitorBanner_website').textContent, + "General website", + "should have 'General website' as website of the visitor", + ); + assert.containsOnce( + document.body, + '.o_VisitorBanner_history', + "should show the visitor history in the banner", + ); + assert.strictEqual( + document.querySelector('.o_VisitorBanner_history').textContent, + "Home → Contact", + "should have 'Home → Contact' as history of the visitor", + ); +}); + +QUnit.test('livechat with non-logged visitor should show visitor banner', async function (assert) { + assert.expect(1); + + this.data['res.country'].records.push({ + id: 11, + code: 'FAKE', + }); + this.data['website.visitor'].records.push({ + id: 11, + country_id: 11, + display_name: 'Visitor #11', + history: 'Home → Contact', + is_connected: true, + lang: "English", + website: "General website", + }); + this.data['mail.channel'].records.push({ + channel_type: 'livechat', + id: 11, + livechat_operator_id: this.data.currentPartnerId, + livechat_visitor_id: 11, + members: [this.data.currentPartnerId, this.data.publicPartnerId], + }); + await this.start({ + discuss: { + context: { + active_id: 'mail.channel_11', + }, + }, + }); + assert.containsOnce( + document.body, + '.o_VisitorBanner', + "should have a visitor banner", + ); +}); + +QUnit.test('livechat with logged visitor should show visitor banner', async function (assert) { + assert.expect(2); + + this.data['res.country'].records.push({ + id: 11, + code: 'FAKE', + }); + this.data['res.partner'].records.push({ + id: 12, + name: 'Partner Visitor', + }); + this.data['website.visitor'].records.push({ + id: 11, + country_id: 11, + display_name: 'Visitor #11', + history: 'Home → Contact', + is_connected: true, + lang: "English", + partner_id: 12, + website: "General website", + }); + this.data['mail.channel'].records.push({ + channel_type: 'livechat', + id: 11, + livechat_operator_id: this.data.currentPartnerId, + livechat_visitor_id: 11, + members: [this.data.currentPartnerId, 12], + }); + await this.start({ + discuss: { + context: { + active_id: 'mail.channel_11', + }, + }, + }); + assert.containsOnce( + document.body, + '.o_VisitorBanner', + "should have a visitor banner", + ); + assert.strictEqual( + document.querySelector('.o_VisitorBanner_visitor').textContent, + "Partner Visitor", + "should have partner name as display name of logged visitor on the visitor banner" + ); +}); + +QUnit.test('livechat without visitor should not show visitor banner', async function (assert) { + assert.expect(2); + + this.data['res.partner'].records.push({ id: 11 }); + this.data['mail.channel'].records.push({ + channel_type: 'livechat', + id: 11, + livechat_operator_id: this.data.currentPartnerId, + members: [this.data.currentPartnerId, 11], + }); + await this.start({ + discuss: { + context: { + active_id: 'mail.channel_11', + }, + }, + }); + assert.containsOnce( + document.body, + '.o_MessageList', + "should have a message list", + ); + assert.containsNone( + document.body, + '.o_VisitorBanner', + "should not have any visitor banner", + ); +}); + +QUnit.test('non-livechat channel should not show visitor banner', async function (assert) { + assert.expect(2); + + this.data['mail.channel'].records.push({ id: 11, name: "General" }); + await this.start({ + discuss: { + context: { + active_id: 'mail.channel_11', + }, + }, + }); + assert.containsOnce( + document.body, + '.o_MessageList', + "should have a message list", + ); + assert.containsNone( + document.body, + '.o_VisitorBanner', + "should not have any visitor banner", + ); +}); + +}); +}); +}); + +}); |
