website_livechat_common.js 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. odoo.define('website_livechat.tour_common', function (require) {
  2. 'use strict';
  3. // Due to some issue with assets bundles, the current file can be loaded while
  4. // LivechatButtonView isn't, causing the patch to fail as the original model was
  5. // not registered beforehand. The following import is intended to stop the
  6. // execution of this file if @im_livechat/public_models/livechat_button_view is
  7. // not part of the current assets bundles (as trying to import it will silently
  8. // crash).
  9. require('@im_livechat/public_models/livechat_button_view');
  10. const { registerPatch } = require('@mail/model/model_core');
  11. registerPatch({
  12. name: 'LivechatButtonView',
  13. recordMethods: {
  14. /**
  15. * Alter this method for test purposes.
  16. *
  17. * Force fetch notifications after sending the message: listen/notify
  18. * mechanism is not active during tests, but available messages
  19. * are directly sent when updating channel subscription.
  20. *
  21. * Add a class to the chatter window after sendFeedback is done
  22. * to force the test to wait until feedback is really done
  23. * (to check afterwards if the livechat session is set to inactive)
  24. *
  25. * Note : this asset is loaded for tests only (rpc call done only during
  26. * tests)
  27. *
  28. * @override
  29. */
  30. async sendMessage(message) {
  31. await this._super(message);
  32. if (message.isFeedback) {
  33. $('div.o_thread_window_header').addClass('feedback_sent');
  34. } else {
  35. this.messaging.rpc({ route: '/bus/test_mode_activated' }).then(in_test_mode => {
  36. if (!in_test_mode) {
  37. return;
  38. }
  39. this.env.services['bus_service'].forceUpdateChannels();
  40. });
  41. }
  42. },
  43. },
  44. });
  45. /*******************************
  46. * Common Steps
  47. *******************************/
  48. var startStep = [{
  49. content: "click on livechat widget",
  50. trigger: "div.o_livechat_button"
  51. }, {
  52. content: "Say hello!",
  53. trigger: "input.o_composer_text_field",
  54. run: "text Hello Sir!"
  55. }, {
  56. content: "Send the message",
  57. trigger: "input.o_composer_text_field",
  58. run: function() {
  59. $('input.o_composer_text_field').trigger($.Event('keydown', {which: $.ui.keyCode.ENTER}));
  60. }
  61. }, {
  62. content: "Verify your message has been typed",
  63. trigger: "div.o_thread_message_content>p:contains('Hello Sir!')"
  64. }, {
  65. content: "Verify there is no duplicates",
  66. trigger: "body",
  67. run: function () {
  68. if ($("div.o_thread_message_content p:contains('Hello Sir!')").length === 1) {
  69. $('body').addClass('no_duplicated_message');
  70. }
  71. }
  72. }, {
  73. content: "Is your message correctly sent ?",
  74. trigger: 'body.no_duplicated_message'
  75. }];
  76. var endDiscussionStep = [{
  77. content: "Close the chatter",
  78. trigger: "a.o_thread_window_close",
  79. run: function() {
  80. $('a.o_thread_window_close').click();
  81. }
  82. }];
  83. var feedbackStep = [{
  84. content: "Type a feedback",
  85. trigger: "div.o_livechat_rating_reason > textarea",
  86. run: "text ;-) This was really helpful. Thanks ;-)!"
  87. }, {
  88. content: "Send the feedback",
  89. trigger: "input[type='button'].o_rating_submit_button",
  90. }, {
  91. content: "Check if feedback has been sent",
  92. trigger: "div.o_thread_window_header.feedback_sent",
  93. }, {
  94. content: "Thanks for your feedback",
  95. trigger: "div.o_livechat_rating_box:has(div:contains('Thank you for your feedback'))",
  96. }];
  97. var transcriptStep = [{
  98. content: "Type your email",
  99. trigger: "input[id='o_email']",
  100. run: "text deboul@onner.com"
  101. }, {
  102. content: "Send the conversation to your email address",
  103. trigger: "button.o_email_chat_button",
  104. }, {
  105. content: "Type your email",
  106. trigger: "div.o_livechat_email:has(strong:contains('Conversation Sent'))",
  107. }];
  108. var closeStep = [{
  109. content: "Close the conversation with the x button",
  110. trigger: "a.o_thread_window_close",
  111. }, {
  112. content: "Check that the chat window is closed",
  113. trigger: 'body',
  114. run: function () {
  115. if ($('div.o_livechat_button').length === 1 && !$('div.o_livechat_button').is(':visible')) {
  116. $('body').addClass('tour_success');
  117. }
  118. }
  119. }, {
  120. content: "Is the Test succeded ?",
  121. trigger: 'body.tour_success'
  122. }];
  123. var goodRatingStep = [{
  124. content: "Send Good Rating",
  125. trigger: "div.o_livechat_rating_choices > img[data-value=5]",
  126. }, {
  127. content: "Check if feedback has been sent",
  128. trigger: "div.o_thread_window_header.feedback_sent",
  129. }, {
  130. content: "Thanks for your feedback",
  131. trigger: "div.o_livechat_rating_box:has(div:contains('Thank you for your feedback'))"
  132. }];
  133. var okRatingStep = [{
  134. content: "Send ok Rating",
  135. trigger: "div.o_livechat_rating_choices > img[data-value=3]",
  136. }];
  137. var sadRatingStep = [{
  138. content: "Send bad Rating",
  139. trigger: "div.o_livechat_rating_choices > img[data-value=1]",
  140. }];
  141. return {
  142. 'startStep': startStep,
  143. 'endDiscussionStep': endDiscussionStep,
  144. 'transcriptStep': transcriptStep,
  145. 'feedbackStep': feedbackStep,
  146. 'closeStep': closeStep,
  147. 'goodRatingStep': goodRatingStep,
  148. 'okRatingStep': okRatingStep,
  149. 'sadRatingStep': sadRatingStep,
  150. };
  151. });