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/tests | |
| parent | 0a15094050bfde69a06d6eff798e9a8ddf2b8c21 (diff) | |
initial commit 2
Diffstat (limited to 'addons/website_livechat/static/tests')
5 files changed, 372 insertions, 0 deletions
diff --git a/addons/website_livechat/static/tests/helpers/mock_models.js b/addons/website_livechat/static/tests/helpers/mock_models.js new file mode 100644 index 00000000..bc407959 --- /dev/null +++ b/addons/website_livechat/static/tests/helpers/mock_models.js @@ -0,0 +1,45 @@ +odoo.define('website_livechat/static/tests/helpers/mock_models.js', function (require) { +'use strict'; + +const MockModels = require('mail/static/tests/helpers/mock_models.js'); + +MockModels.patch('website_livechat/static/tests/helpers/mock_models.js', T => + class extends T { + + //---------------------------------------------------------------------- + // Public + //---------------------------------------------------------------------- + + /** + * @override + */ + static generateData() { + const data = super.generateData(...arguments); + Object.assign(data, { + 'website.visitor': { + fields: { + country_id: { string: "Country", type: 'many2one', relation: 'res.country' }, + display_name: { string: "Display name", type: 'string' }, + // Represent the browsing history of the visitor as a string. + // To ease testing this allows tests to set it directly instead + // of implementing the computation made on server. + // This should normally not be a field. + history: { string: "History", type: 'string'}, + is_connected: { string: "Is connected", type: 'boolean' }, + lang: { string: "Language", type: 'string'}, + partner_id: {string: "partner", type: "many2one", relation: 'res.partner'}, + website: { string: "Website", type: 'string' }, + }, + records: [], + }, + }); + Object.assign(data['mail.channel'].fields, { + livechat_visitor_id: { string: "Visitor", type: 'many2one', relation: 'website.visitor' }, + }); + return data; + } + + } +); + +}); diff --git a/addons/website_livechat/static/tests/helpers/mock_server.js b/addons/website_livechat/static/tests/helpers/mock_server.js new file mode 100644 index 00000000..1383e521 --- /dev/null +++ b/addons/website_livechat/static/tests/helpers/mock_server.js @@ -0,0 +1,78 @@ +odoo.define('website_livechat/static/tests/helpers/mock_server.js', function (require) { +'use strict'; + +require('im_livechat/static/tests/helpers/mock_server.js'); // ensure mail overrides are applied first + +const MockServer = require('web.MockServer'); + +MockServer.include({ + /** + * Simulate a 'call_button' operation from a view. + * + * @override + */ + _mockCallButton({ args, kwargs, method, model }) { + if (model === 'website.visitor' && method === 'action_send_chat_request') { + return this._mockWebsiteVisitorActionSendChatRequest(args[0]); + } + return this._super(...arguments); + }, + /** + * Overrides to add visitor information to livechat channels. + * + * @override + */ + _mockMailChannelChannelInfo(ids, extra_info) { + const channelInfos = this._super(...arguments); + for (const channelInfo of channelInfos) { + const channel = this._getRecords('mail.channel', [['id', '=', channelInfo.id]])[0]; + if (channel.channel_type === 'livechat' && channelInfo.livechat_visitor_id) { + const visitor = this._getRecords('website.visitor', [['id', '=', channelInfo.livechat_visitor_id]])[0]; + const country = this._getRecords('res.country', [['id', '=', visitor.country_id]])[0]; + channelInfo.visitor = { + name: visitor.display_name, + country_code: country && country.code, + country_id: country && country.id, + is_connected: visitor.is_connected, + history: visitor.history, // TODO should be computed + website: visitor.website, + lang: visitor.lang, + partner_id: visitor.partner_id, + } + } + } + return channelInfos; + }, + /** + * @private + * @param {integer[]} ids + */ + _mockWebsiteVisitorActionSendChatRequest(ids) { + const visitors = this._getRecords('website.visitor', [['id', 'in', ids]]); + for (const visitor of visitors) { + const country = visitor.country_id + ? this._getRecords('res.country', [['id', '=', visitor.country_id]]) + : undefined; + const visitor_name = `${visitor.display_name}${country ? `(${country.name})` : ''}`; + const members = [this.currentPartnerId]; + if (visitor.partner_id) { + members.push(visitor.partner_id); + } else { + members.push(this.publicPartnerId); + } + const livechatId = this._mockCreate('mail.channel', { + anonymous_name: visitor_name, + channel_type: 'livechat', + livechat_operator_id: this.currentPartnerId, + members, + public: 'private', + }); + // notify operator + const channelInfo = this._mockMailChannelChannelInfo([livechatId], 'send_chat_request')[0]; + const notification = [[false, 'res.partner', this.currentPartnerId], channelInfo]; + this._widget.call('bus_service', 'trigger', 'notification', [notification]); + } + }, +}); + +}); diff --git a/addons/website_livechat/static/tests/tours/website_livechat_common.js b/addons/website_livechat/static/tests/tours/website_livechat_common.js new file mode 100644 index 00000000..6568a82f --- /dev/null +++ b/addons/website_livechat/static/tests/tours/website_livechat_common.js @@ -0,0 +1,165 @@ +odoo.define('website_livechat.tour_common', function(require) { +'use strict'; + +var session = require('web.session'); +var LivechatButton = require('im_livechat.legacy.im_livechat.im_livechat').LivechatButton; + +/** + * Alter this method for test purposes. + * + * Fake the notification after sending message + * As bus is not available, it's necessary to add the message in the chatter + in livechat.messages + * + * Add a class to the chatter window after sendFeedback is done + * to force the test to wait until feedback is really done + * (to check afterwards if the livechat session is set to inactive) + * + * Note : this asset is loaded for tests only (rpc call done only during tests) + */ +LivechatButton.include({ + _sendMessage: function (message) { + var self = this; + return this._super.apply(this, arguments).then(function () { + if (message.isFeedback) { + $('div.o_thread_window_header').addClass('feedback_sent'); + } + else { + session.rpc('/bus/test_mode_activated', {}).then(function (in_test_mode) { + if (in_test_mode) { + var notification = [ + self._livechat.getUUID(), + { + 'id': -1, + 'author_id': [0, 'Website Visitor Test'], + 'email_from': 'Website Visitor Test', + 'body': '<p>' + message.content + '</p>', + 'is_discussion': true, + 'subtype_id': [1, "Discussions"], + 'date': moment().format('YYYY-MM-DD HH:mm:ss'), + } + ] + self._handleNotification(notification); + } + }); + } + }); + }, +}); + +/******************************* +* Common Steps +*******************************/ + +var startStep = [{ + content: "click on livechat widget", + trigger: "div.o_livechat_button" +}, { + content: "Say hello!", + trigger: "input.o_composer_text_field", + run: "text Hello Sir!" +}, { + content: "Send the message", + trigger: "input.o_composer_text_field", + run: function() { + $('input.o_composer_text_field').trigger($.Event('keydown', {which: $.ui.keyCode.ENTER})); + } +}, { + content: "Verify your message has been typed", + trigger: "div.o_thread_message_content>p:contains('Hello Sir!')" +}, { + content: "Verify there is no duplicates", + trigger: "body", + run: function () { + if ($("div.o_thread_message_content p:contains('Hello Sir!')").length === 1) { + $('body').addClass('no_duplicated_message'); + } + } +}, { + content: "Is your message correctly sent ?", + trigger: 'body.no_duplicated_message' +}]; + +var endDiscussionStep = [{ + content: "Close the chatter", + trigger: "a.o_thread_window_close", + run: function() { + $('a.o_thread_window_close').click(); + } +}]; + +var feedbackStep = [{ + content: "Type a feedback", + trigger: "div.o_livechat_rating_reason > textarea", + run: "text ;-) This was really helpful. Thanks ;-)!" +}, { + content: "Send the feedback", + trigger: "input[type='button'].o_rating_submit_button", +}, { + content: "Check if feedback has been sent", + trigger: "div.o_thread_window_header.feedback_sent", +}, { + content: "Thanks for your feedback", + trigger: "div.o_livechat_rating_box:has(div:contains('Thank you for your feedback'))", +}]; + +var transcriptStep = [{ + content: "Type your email", + trigger: "input[id='o_email']", + run: "text deboul@onner.com" +}, { + content: "Send the conversation to your email address", + trigger: "button.o_email_chat_button", +}, { + content: "Type your email", + trigger: "div.o_livechat_email:has(strong:contains('Conversation Sent'))", +}]; + +var closeStep = [{ + content: "Close the conversation with the x button", + trigger: "a.o_thread_window_close", +}, { + content: "Check that the chat window is closed", + trigger: 'body', + run: function () { + if ($('div.o_livechat_button').length === 1 && !$('div.o_livechat_button').is(':visible')) { + $('body').addClass('tour_success'); + } + } +}, { + content: "Is the Test succeded ?", + trigger: 'body.tour_success' +}]; + +var goodRatingStep = [{ + content: "Send Good Rating", + trigger: "div.o_livechat_rating_choices > img[data-value=5]", +}, { + content: "Check if feedback has been sent", + trigger: "div.o_thread_window_header.feedback_sent", +}, { + content: "Thanks for your feedback", + trigger: "div.o_livechat_rating_box:has(div:contains('Thank you for your feedback'))" +}]; + +var okRatingStep = [{ + content: "Send ok Rating", + trigger: "div.o_livechat_rating_choices > img[data-value=3]", +}]; + +var sadRatingStep = [{ + content: "Send bad Rating", + trigger: "div.o_livechat_rating_choices > img[data-value=1]", +}]; + +return { + 'startStep': startStep, + 'endDiscussionStep': endDiscussionStep, + 'transcriptStep': transcriptStep, + 'feedbackStep': feedbackStep, + 'closeStep': closeStep, + 'goodRatingStep': goodRatingStep, + 'okRatingStep': okRatingStep, + 'sadRatingStep': sadRatingStep, +}; + +}); diff --git a/addons/website_livechat/static/tests/tours/website_livechat_rating.js b/addons/website_livechat/static/tests/tours/website_livechat_rating.js new file mode 100644 index 00000000..d3339f2b --- /dev/null +++ b/addons/website_livechat/static/tests/tours/website_livechat_rating.js @@ -0,0 +1,38 @@ +odoo.define('website_livechat.tour', function(require) { +'use strict'; + +var commonSteps = require("website_livechat.tour_common"); +var tour = require("web_tour.tour"); + +tour.register('website_livechat_complete_flow_tour', { + test: true, + url: '/', +}, [].concat(commonSteps.startStep, commonSteps.endDiscussionStep, commonSteps.okRatingStep, commonSteps.feedbackStep, commonSteps.transcriptStep, commonSteps.closeStep)); + +tour.register('website_livechat_happy_rating_tour', { + test: true, + url: '/', +}, [].concat(commonSteps.startStep, commonSteps.endDiscussionStep, commonSteps.goodRatingStep)); + +tour.register('website_livechat_ok_rating_tour', { + test: true, + url: '/', +}, [].concat(commonSteps.startStep, commonSteps.endDiscussionStep, commonSteps.okRatingStep, commonSteps.feedbackStep)); + +tour.register('website_livechat_sad_rating_tour', { + test: true, + url: '/', +}, [].concat(commonSteps.startStep, commonSteps.endDiscussionStep, commonSteps.sadRatingStep, commonSteps.feedbackStep)); + +tour.register('website_livechat_no_rating_tour', { + test: true, + url: '/', +}, [].concat(commonSteps.startStep, commonSteps.endDiscussionStep, commonSteps.transcriptStep, commonSteps.closeStep)); + +tour.register('website_livechat_no_rating_no_close_tour', { + test: true, + url: '/', +}, [].concat(commonSteps.startStep)); + +return {}; +}); diff --git a/addons/website_livechat/static/tests/tours/website_livechat_request.js b/addons/website_livechat/static/tests/tours/website_livechat_request.js new file mode 100644 index 00000000..8c4042e3 --- /dev/null +++ b/addons/website_livechat/static/tests/tours/website_livechat_request.js @@ -0,0 +1,46 @@ +odoo.define('website_livechat.chat_request_tour', function(require) { +'use strict'; + +var commonSteps = require("website_livechat.tour_common"); +var tour = require("web_tour.tour"); + + +var stepWithChatRequestStep = [{ + content: "Answer the chat request!", + trigger: "input.o_composer_text_field", + run: "text Hi ! What a coincidence! I need your help indeed." +}, { + content: "Send the message", + trigger: "input.o_composer_text_field", + run: function() { + $('input.o_composer_text_field').trigger($.Event('keydown', {which: $.ui.keyCode.ENTER})); + } +}, { + content: "Verify your message has been typed", + trigger: "div.o_thread_message_content>p:contains('Hi ! What a coincidence! I need your help indeed.')" +}, { + content: "Verify there is no duplicates", + trigger: "body", + run: function () { + if ($("div.o_thread_message_content p:contains('Hi ! What a coincidence! I need your help indeed.')").length === 1) { + $('body').addClass('no_duplicated_message'); + } + } +}, { + content: "Is your message correctly sent ?", + trigger: 'body.no_duplicated_message' +}]; + + +tour.register('website_livechat_chat_request_part_1_no_close_tour', { + test: true, + url: '/', +}, [].concat(stepWithChatRequestStep)); + +tour.register('website_livechat_chat_request_part_2_end_session_tour', { + test: true, + url: '/', +}, [].concat(commonSteps.endDiscussionStep, commonSteps.okRatingStep, commonSteps.feedbackStep, commonSteps.transcriptStep, commonSteps.closeStep)); + +return {}; +}); |
