test_ui.py 4.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. # -*- coding: utf-8 -*-
  2. # Part of Odoo. See LICENSE file for full copyright and licensing details.
  3. from odoo import tests, _
  4. from odoo.addons.website_livechat.tests.common import TestLivechatCommon
  5. @tests.tagged('post_install', '-at_install')
  6. class TestLivechatUI(tests.HttpCase, TestLivechatCommon):
  7. def setUp(self):
  8. super(TestLivechatUI, self).setUp()
  9. self.visitor_tour = self.env['website.visitor'].create({
  10. 'access_token': 'f9d2e784d3d96a904fca2f5e2a559a19',
  11. 'website_id': self.env.ref('website.default_website').id,
  12. })
  13. self.target_visitor = self.visitor_tour
  14. def test_complete_rating_flow_ui(self):
  15. self.start_tour("/", 'website_livechat_complete_flow_tour')
  16. self._check_end_of_rating_tours()
  17. def test_happy_rating_flow_ui(self):
  18. self.start_tour("/", 'website_livechat_happy_rating_tour')
  19. self._check_end_of_rating_tours()
  20. def test_ok_rating_flow_ui(self):
  21. self.start_tour("/", 'website_livechat_ok_rating_tour')
  22. self._check_end_of_rating_tours()
  23. def test_bad_rating_flow_ui(self):
  24. self.start_tour("/", 'website_livechat_sad_rating_tour')
  25. self._check_end_of_rating_tours()
  26. def test_no_rating_flow_ui(self):
  27. self.start_tour("/", 'website_livechat_no_rating_tour')
  28. channel = self.env['mail.channel'].search([('livechat_visitor_id', '=', self.visitor_tour.id)])
  29. self.assertEqual(len(channel), 1, "There can only be one channel created for 'Visitor Tour'.")
  30. self.assertEqual(channel.livechat_active, False, 'Livechat must be inactive after closing the chat window.')
  31. def test_no_rating_no_close_flow_ui(self):
  32. self.start_tour("/", 'website_livechat_no_rating_no_close_tour')
  33. channel = self.env['mail.channel'].search([('livechat_visitor_id', '=', self.visitor_tour.id)])
  34. self.assertEqual(len(channel), 1, "There can only be one channel created for 'Visitor Tour'.")
  35. self.assertEqual(channel.livechat_active, True, 'Livechat must be active while the chat window is not closed.')
  36. def test_empty_chat_request_flow_no_rating_no_close_ui(self):
  37. # Open an empty chat request
  38. self.visitor_tour.with_user(self.operator).action_send_chat_request()
  39. chat_request = self.env['mail.channel'].search([('livechat_visitor_id', '=', self.visitor_tour.id), ('livechat_active', '=', True)])
  40. # Visitor ask a new livechat session before the operator start to send message in chat request session
  41. self.start_tour("/", 'website_livechat_no_rating_no_close_tour')
  42. # Visitor's session must be active (gets the priority)
  43. channel = self.env['mail.channel'].search([('livechat_visitor_id', '=', self.visitor_tour.id), ('livechat_active', '=', True)])
  44. self.assertEqual(len(channel), 1, "There can only be one channel created for 'Visitor Tour'.")
  45. self.assertEqual(channel.livechat_active, True, 'Livechat must be active while the chat window is not closed.')
  46. # Check that the chat request has been canceled.
  47. chat_request.invalidate_recordset()
  48. self.assertEqual(chat_request.livechat_active, False, "The livechat request must be inactive as the visitor started himself a livechat session.")
  49. def test_chat_request_flow_with_rating_ui(self):
  50. # Open a chat request
  51. self.visitor_tour.with_user(self.operator).action_send_chat_request()
  52. chat_request = self.env['mail.channel'].search([('livechat_visitor_id', '=', self.visitor_tour.id), ('livechat_active', '=', True)])
  53. # Operator send a message to the visitor
  54. self._send_message(chat_request, self.operator.email, "Hello my friend !", author_id=self.operator.partner_id.id)
  55. self.assertEqual(len(chat_request.message_ids), 1, "Number of messages incorrect.")
  56. # Visitor comes to the website and receives the chat request
  57. self.start_tour("/", 'website_livechat_chat_request_part_1_no_close_tour')
  58. # Check that the current session is the chat request
  59. channel = self.env['mail.channel'].search([('livechat_visitor_id', '=', self.visitor_tour.id), ('livechat_active', '=', True)])
  60. self.assertEqual(len(channel), 1, "There can only be one channel created for 'Visitor Tour'.")
  61. self.assertEqual(channel, chat_request, "The active livechat session must be the chat request one.")
  62. # Visitor reload the page and continues the chat with the operator normally
  63. self.start_tour("/", 'website_livechat_chat_request_part_2_end_session_tour')
  64. self._check_end_of_rating_tours()
  65. def _check_end_of_rating_tours(self):
  66. channel = self.env['mail.channel'].search([('livechat_visitor_id', '=', self.visitor_tour.id)])
  67. self.assertEqual(len(channel), 1, "There can only be one channel created for 'Visitor Tour'.")
  68. self.assertEqual(channel.livechat_active, False, 'Livechat must be inactive after rating.')