diff options
| author | Aurélien Warnon <awa@odoo.com> | 2020-02-20 16:10:45 +0000 |
|---|---|---|
| committer | Aurélien Warnon <awa@odoo.com> | 2020-03-31 10:39:05 +0000 |
| commit | 0132ab608af2502a6a2f59f3f35ef3ea76472a54 (patch) | |
| tree | fdb080529a2847f9c633944b7ff7f7c47483f38c /addons | |
| parent | 6d2bee710df2792c6000a5181efa023d6b814e64 (diff) | |
[IMP] website_event_questions: add test tour for event questions
This commit adds a test tour that will fill up two tickets with a few questions
answers and then assert that the answers are correctly saved for each attendee.
This will help ensuring that the new "free text question" feature works
correctly, along with existing "suggestion question".
LINKS
PR #45497
Task ID 2189529
Diffstat (limited to 'addons')
5 files changed, 156 insertions, 0 deletions
diff --git a/addons/website_event_questions/__manifest__.py b/addons/website_event_questions/__manifest__.py index d183e1b0244..a85f4398839 100644 --- a/addons/website_event_questions/__manifest__.py +++ b/addons/website_event_questions/__manifest__.py @@ -7,6 +7,7 @@ 'version': '1.1', 'depends': ['website_event'], 'data': [ + 'views/assets.xml', 'views/event_views.xml', 'views/event_templates.xml', 'security/ir.model.access.csv', diff --git a/addons/website_event_questions/static/tests/tours/tickets_questions.js b/addons/website_event_questions/static/tests/tours/tickets_questions.js new file mode 100644 index 00000000000..458ecc7eb90 --- /dev/null +++ b/addons/website_event_questions/static/tests/tours/tickets_questions.js @@ -0,0 +1,54 @@ +odoo.define('website_event_questions.tour_test_tickets_questions', function (require) { +'use strict'; + +var tour = require('web_tour.tour'); +tour.register('test_tickets_questions', { + test: true, + url: '/event' +}, [{ + content: "Click on the Design Fair event", + trigger: 'article:contains("Design Fair New York")', +}, { + content: "Click on Buy tickets button", + trigger: 'a:contains("Tickets")', +}, { + content: "Select 2 'Free' tickets to buy", + trigger: 'div.row:contains("Free") select.custom-select', + run: 'text 2' +}, { + content: "Click on Register tickets button", + trigger: 'button:contains("Register")', + run: 'click' +}, { + trigger: 'div:contains("Ticket #1").modal-body input[name*="name"]', + run: 'text Attendee A' +}, { + trigger: 'div:contains("Ticket #1").modal-body input[name*="email"]', + run: 'text attendee-a@gmail.com' +}, { + trigger: 'div:contains("Ticket #1").modal-body input[name*="phone"]', + run: 'text +32499123456' +}, { + trigger: 'div:contains("Ticket #1").modal-body select[name*="question_answer"]', + run: 'text Vegetarian' +}, { + trigger: 'div:contains("Ticket #1").modal-body textarea[name*="question_answer"]', + run: 'text Fish and Nuts' +}, { + trigger: 'div:contains("Ticket #2").modal-body input[name*="name"]', + run: 'text Attendee B' +}, { + trigger: 'div:contains("Ticket #2").modal-body input[name*="email"]', + run: 'text attendee-b@gmail.com' +}, { + trigger: 'div:contains("Ticket #2").modal-body select[name*="question_answer"]', + run: 'text Pastafarian' +}, { + trigger: 'div:contains("General questions").modal-body select[name*="question_answer"]', + run: 'text A friend' +}, { + trigger: 'button:contains("Continue")', + run: 'click' +}]); + +}); diff --git a/addons/website_event_questions/tests/__init__.py b/addons/website_event_questions/tests/__init__.py index d03842855ce..38db76983f5 100644 --- a/addons/website_event_questions/tests/__init__.py +++ b/addons/website_event_questions/tests/__init__.py @@ -3,3 +3,4 @@ from . import common from . import test_event_internals +from . import test_event_ui diff --git a/addons/website_event_questions/tests/test_event_ui.py b/addons/website_event_questions/tests/test_event_ui.py new file mode 100644 index 00000000000..fdebd0c40a7 --- /dev/null +++ b/addons/website_event_questions/tests/test_event_ui.py @@ -0,0 +1,90 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from dateutil.relativedelta import relativedelta + +from odoo import fields, tests + + +@tests.tagged('post_install', '-at_install') +class TestUi(tests.HttpCase): + + def test_01_tickets_questions(self): + """ Will execute the tour that fills up two tickets with a few questions answers + and then assert that the answers are correctly saved for each attendee. """ + + self.design_fair_event = self.env['event.event'].create({ + 'name': 'Design Fair New York', + 'date_begin': fields.Datetime.now() - relativedelta(days=15), + 'date_end': fields.Datetime.now() + relativedelta(days=15), + 'event_ticket_ids': [(0, 0, { + 'name': 'Free', + 'start_sale_date': fields.Datetime.now() - relativedelta(days=15) + }), (0, 0, { + 'name': 'Other', + 'start_sale_date': fields.Datetime.now() - relativedelta(days=15) + })], + 'website_published': True, + 'question_ids': [(0, 0, { + 'title': 'Meal Type', + 'question_type': 'simple_choice', + 'answer_ids': [ + (0, 0, {'name': 'Mixed'}), + (0, 0, {'name': 'Vegetarian'}), + (0, 0, {'name': 'Pastafarian'}) + ] + }), (0, 0, { + 'title': 'Allergies', + 'question_type': 'text_box' + }), (0, 0, { + 'title': 'How did you learn about this event?', + 'question_type': 'simple_choice', + 'once_per_order': True, + 'answer_ids': [ + (0, 0, {'name': 'Our website'}), + (0, 0, {'name': 'Commercials'}), + (0, 0, {'name': 'A friend'}) + ] + })] + }) + + self.start_tour("/", 'test_tickets_questions', login="portal") + + registrations = self.env['event.registration'].search([ + ('email', 'in', ['attendee-a@gmail.com', 'attendee-b@gmail.com']) + ]) + self.assertEqual(len(registrations), 2) + first_registration = registrations.filtered(lambda reg: reg.email == 'attendee-a@gmail.com') + second_registration = registrations.filtered(lambda reg: reg.email == 'attendee-b@gmail.com') + self.assertEqual(first_registration.name, 'Attendee A') + self.assertEqual(first_registration.phone, '+32499123456') + self.assertEqual(second_registration.name, 'Attendee B') + + event_questions = registrations.mapped('event_id.question_ids') + self.assertEqual(len(event_questions), 3) + + first_registration_answers = first_registration.registration_answer_ids + self.assertEqual(len(first_registration_answers), 3) + + self.assertEqual(first_registration_answers.filtered( + lambda answer: answer.question_id.title == 'Meal Type' + ).value_answer_id.name, 'Vegetarian') + + self.assertEqual(first_registration_answers.filtered( + lambda answer: answer.question_id.title == 'Allergies' + ).value_text_box, 'Fish and Nuts') + + self.assertEqual(first_registration_answers.filtered( + lambda answer: answer.question_id.title == 'How did you learn about this event?' + ).value_answer_id.name, 'A friend') + + second_registration_answers = second_registration.registration_answer_ids + self.assertEqual(len(second_registration_answers), 2) + + self.assertEqual(second_registration_answers.filtered( + lambda answer: answer.question_id.title == 'Meal Type' + ).value_answer_id.name, 'Pastafarian') + + self.assertEqual(first_registration_answers.filtered( + lambda answer: answer.question_id.title == 'How did you learn about this event?' + ).value_answer_id.name, 'A friend') diff --git a/addons/website_event_questions/views/assets.xml b/addons/website_event_questions/views/assets.xml new file mode 100644 index 00000000000..d85a4bda615 --- /dev/null +++ b/addons/website_event_questions/views/assets.xml @@ -0,0 +1,10 @@ +<?xml version="1.0" encoding="utf-8"?> +<odoo> +<data> + <template id="assets_tests" name="Website Event Questions Assets Tests" inherit_id="web.assets_tests"> + <xpath expr="." position="inside"> + <script type="text/javascript" src="/website_event_questions/static/tests/tours/tickets_questions.js"></script> + </xpath> + </template> +</data> +</odoo> |
