test_survey_ui_feedback.py 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. # Part of Odoo. See LICENSE file for full copyright and licensing details.
  2. import odoo.tests
  3. from odoo.addons.base.tests.common import HttpCaseWithUserDemo
  4. @odoo.tests.common.tagged('post_install', '-at_install')
  5. class TestUiFeedback(HttpCaseWithUserDemo):
  6. def setUp(self):
  7. super(TestUiFeedback, self).setUp()
  8. self.survey_feedback = self.env['survey.survey'].create({
  9. 'title': 'User Feedback Form',
  10. 'access_token': 'b137640d-14d4-4748-9ef6-344caaaaaae',
  11. 'access_mode': 'public',
  12. 'users_can_go_back': True,
  13. 'questions_layout': 'page_per_section',
  14. 'description': """<p>This survey allows you to give a feedback about your experience with our eCommerce solution.
  15. Filling it helps us improving your experience.</p></field>""",
  16. 'question_and_page_ids': [
  17. (0, 0, {
  18. 'title': 'General information',
  19. 'sequence': 1,
  20. 'question_type': False,
  21. 'is_page': True,
  22. 'description': """<p>This section is about general information about you. Answering them helps qualifying your answers.</p>""",
  23. }), (0, 0, {
  24. 'title': 'Where do you live ?',
  25. 'sequence': 2,
  26. 'question_type': 'char_box',
  27. 'constr_mandatory': False,
  28. }), (0, 0, {
  29. 'title': 'When is your date of birth ?',
  30. 'sequence': 3,
  31. 'question_type': 'date',
  32. 'description': False,
  33. }), (0, 0, {
  34. 'title': 'How frequently do you buy products online ?',
  35. 'sequence': 4,
  36. 'question_type': 'simple_choice',
  37. 'comments_allowed': True,
  38. 'comment_count_as_answer': True,
  39. 'constr_mandatory': True,
  40. 'suggested_answer_ids': [
  41. (0, 0, {
  42. 'value': 'Once a day',
  43. 'sequence': 1,
  44. }), (0, 0, {
  45. 'value': 'Once a week',
  46. 'sequence': 2,
  47. }), (0, 0, {
  48. 'value': 'Once a month',
  49. 'sequence': 3,
  50. }), (0, 0, {
  51. 'value': 'Once a year',
  52. 'sequence': 4,
  53. }), (0, 0, {
  54. 'value': 'Other (answer in comment)',
  55. 'sequence': 5,
  56. })],
  57. }), (0, 0, {
  58. 'title': 'How many times did you order products on our website ?',
  59. 'sequence': 5,
  60. 'question_type': 'numerical_box',
  61. 'constr_mandatory': True,
  62. }), (0, 0, {
  63. 'title': 'About our ecommerce',
  64. 'sequence': 6,
  65. 'is_page': True,
  66. 'question_type': False,
  67. 'description': """<p>This section is about our eCommerce experience itself.</p>""",
  68. }), (0, 0, {
  69. 'title': 'Which of the following words would you use to describe our products ?',
  70. 'sequence': 7,
  71. 'question_type': 'multiple_choice',
  72. 'constr_mandatory': True,
  73. 'comments_allowed': True,
  74. 'comment_count_as_answer': False,
  75. 'suggested_answer_ids': [
  76. (0, 0, {
  77. 'value': 'High quality',
  78. 'sequence': 1,
  79. }), (0, 0, {
  80. 'value': 'Useful',
  81. 'sequence': 2,
  82. }), (0, 0, {
  83. 'value': 'Unique',
  84. 'sequence': 3,
  85. }), (0, 0, {
  86. 'value': 'Good value for money',
  87. 'sequence': 4,
  88. }), (0, 0, {
  89. 'value': 'Overpriced',
  90. 'sequence': 5,
  91. }), (0, 0, {
  92. 'value': 'Impractical',
  93. 'sequence': 6,
  94. }), (0, 0, {
  95. 'value': 'Ineffective',
  96. 'sequence': 7,
  97. }), (0, 0, {
  98. 'value': 'Poor quality',
  99. 'sequence': 8,
  100. }), (0, 0, {
  101. 'value': 'Other',
  102. 'sequence': 9,
  103. })],
  104. }), (0, 0, {
  105. 'title': 'What do your think about our new eCommerce ?',
  106. 'sequence': 8,
  107. 'question_type': 'matrix',
  108. 'matrix_subtype': 'multiple',
  109. 'constr_mandatory': True,
  110. 'suggested_answer_ids': [(0, 0, {
  111. 'value': 'Totally disagree',
  112. 'sequence': 1
  113. }), (0, 0, {
  114. 'value': 'Disagree',
  115. 'sequence': 2,
  116. }), (0, 0, {
  117. 'value': 'Agree',
  118. 'sequence': 3,
  119. }), (0, 0, {
  120. 'value': 'Totally agree',
  121. 'sequence': 4,
  122. })],
  123. 'matrix_row_ids': [(0, 0, {
  124. 'value': 'The new layout and design is fresh and up-to-date',
  125. 'sequence': 1,
  126. }), (0, 0, {
  127. 'value': 'It is easy to find the product that I want',
  128. 'sequence': 2,
  129. }), (0, 0, {
  130. 'value': 'The tool to compare the products is useful to make a choice',
  131. 'sequence': 3,
  132. }), (0, 0, {
  133. 'value': 'The checkout process is clear and secure',
  134. 'sequence': 4,
  135. }), (0, 0, {
  136. 'value': 'I have added products to my wishlist',
  137. 'sequence': 5,
  138. })],
  139. }), (0, 0, {
  140. 'title': 'Do you have any other comments, questions, or concerns ?',
  141. 'sequence': 9,
  142. 'question_type': 'text_box',
  143. 'constr_mandatory': False,
  144. })
  145. ],
  146. })
  147. def test_01_admin_survey_tour(self):
  148. access_token = self.survey_feedback.access_token
  149. self.start_tour("/survey/start/%s" % access_token, 'test_survey', login="admin")
  150. def test_02_demo_survey_tour(self):
  151. access_token = self.survey_feedback.access_token
  152. self.start_tour("/survey/start/%s" % access_token, 'test_survey', login="demo")
  153. def test_03_public_survey_tour(self):
  154. access_token = self.survey_feedback.access_token
  155. self.start_tour("/survey/start/%s" % access_token, 'test_survey')
  156. def test_04_public_survey_with_triggers(self):
  157. """ Check that chained conditional questions are correctly
  158. hidden from survey when a previously selected triggering answer is
  159. unselected. E.g., if a specific answer for "Question 1" is selected,
  160. which triggers asking "Question 2", and a specific answer for
  161. "Question 2" is selected and triggers asking "Question 3",
  162. changing the selected answer for "Question 1" should:
  163. * hide questions 2 and 3
  164. * enable submitting the survey without answering questions 2 and 3,
  165. even if "constr_mandatory=True", as they are not visible.
  166. """
  167. survey_with_triggers = self.env['survey.survey'].create({
  168. 'title': 'Survey With Triggers',
  169. 'access_token': '3cfadce3-3f7e-41da-920d-10fa0eb19527',
  170. 'access_mode': 'public',
  171. 'users_can_go_back': True,
  172. 'questions_layout': 'one_page',
  173. 'description': "<p>Test survey with conditional questions</p>",
  174. 'question_and_page_ids': [
  175. (0, 0, {
  176. 'title': 'Q1',
  177. 'sequence': 1,
  178. 'question_type': 'simple_choice',
  179. 'suggested_answer_ids': [
  180. (0, 0, {
  181. 'value': 'Answer 1',
  182. 'sequence': 1,
  183. }), (0, 0, {
  184. 'value': 'Answer 2',
  185. 'sequence': 2,
  186. }),
  187. ],
  188. 'constr_mandatory': True,
  189. }), (0, 0, {
  190. 'title': 'Q2',
  191. 'sequence': 2,
  192. 'question_type': 'simple_choice',
  193. 'suggested_answer_ids': [
  194. (0, 0, {
  195. 'value': 'Answer 1',
  196. 'sequence': 1,
  197. }), (0, 0, {
  198. 'value': 'Answer 2',
  199. 'sequence': 2,
  200. })
  201. ],
  202. 'is_conditional': True,
  203. 'constr_mandatory': True,
  204. }), (0, 0, {
  205. 'title': 'Q3',
  206. 'sequence': 3,
  207. 'question_type': 'simple_choice',
  208. 'suggested_answer_ids': [
  209. (0, 0, {
  210. 'value': 'Answer 1',
  211. 'sequence': 1,
  212. }), (0, 0, {
  213. 'value': 'Answer 2',
  214. 'sequence': 2,
  215. })
  216. ],
  217. 'is_conditional': True,
  218. 'constr_mandatory': True,
  219. }),
  220. ]
  221. })
  222. q1 = survey_with_triggers.question_ids.filtered(lambda q: q.title == 'Q1')
  223. q1_a1 = q1.suggested_answer_ids.filtered(lambda a: a.value == 'Answer 1')
  224. q2 = survey_with_triggers.question_ids.filtered(lambda q: q.title == 'Q2')
  225. q2_a1 = q2.suggested_answer_ids.filtered(lambda a: a.value == 'Answer 1')
  226. q3 = survey_with_triggers.question_ids.filtered(lambda q: q.title == 'Q3')
  227. q2.triggering_question_id = q1
  228. q2.triggering_answer_id = q1_a1
  229. q3.triggering_question_id = q2
  230. q3.triggering_answer_id = q2_a1
  231. access_token = survey_with_triggers.access_token
  232. self.start_tour("/survey/start/%s" % access_token, 'test_survey_chained_conditional_questions')
  233. def test_06_survey_prefill(self):
  234. access_token = self.survey_feedback.access_token
  235. self.start_tour("/survey/start/%s" % access_token, 'test_survey_prefill')