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/survey/static/tests | |
| parent | 0a15094050bfde69a06d6eff798e9a8ddf2b8c21 (diff) | |
initial commit 2
Diffstat (limited to 'addons/survey/static/tests')
9 files changed, 976 insertions, 0 deletions
diff --git a/addons/survey/static/tests/tours/certification_failure.js b/addons/survey/static/tests/tours/certification_failure.js new file mode 100644 index 00000000..048915a3 --- /dev/null +++ b/addons/survey/static/tests/tours/certification_failure.js @@ -0,0 +1,109 @@ +odoo.define('survey.tour_test_certification_failure', function (require) { +'use strict'; + +var SurveyFormWidget = require('survey.form'); +/** + * Speed up fade-in fade-out to avoid useless delay in tests. + */ +SurveyFormWidget.include({ + _submitForm: function () { + this.fadeInOutDelay = 0; + return this._super.apply(this, arguments); + } +}); + +/** + * This tour will test that, for the demo certification allowing 2 attempts, a user can + * try and fail twice and will no longer be able to take the certification. + */ + +var tour = require('web_tour.tour'); + +var failSteps = [{ // Page-1 + content: "Clicking on Start Certification", + trigger: 'button.btn.btn-primary.btn-lg:contains("Start Certification")', +}, { // Question: Do we sell Acoustic Bloc Screens? + content: "Selecting answer 'No'", + trigger: 'div.js_question-wrapper:contains("Do we sell Acoustic Bloc Screens") label:contains("No")', +}, { // Question: Select all the existing products + content: "Ticking answer 'Fanta'", + trigger: 'div.js_question-wrapper:contains("Select all the existing products") label:contains("Fanta")' +}, { + content: "Ticking answer 'Drawer'", + trigger: 'div.js_question-wrapper:contains("Select all the existing products") label:contains("Drawer")' +}, { + content: "Ticking answer 'Conference chair'", + trigger: 'div.js_question-wrapper:contains("Select all the existing products") label:contains("Conference chair")' +}, { // Question: Select all the available customizations for our Customizable Desk + content: "Ticking answer 'Color'", + trigger: 'div.js_question-wrapper:contains("Select all the available customizations for our Customizable Desk") label:contains("Color")' +}, { + content: "Ticking answer 'Height'", + trigger: 'div.js_question-wrapper:contains("Select all the available customizations for our Customizable Desk") label:contains("Height")' +}, { // Question: How many versions of the Corner Desk do we have? + content: "Selecting answer '2'", + trigger: 'div.js_question-wrapper:contains("How many versions of the Corner Desk do we have") label:contains("2")', +}, { // Question: Do you think we have missing products in our catalog? (not rated) + content: "Missing products", + trigger: 'div.js_question-wrapper:contains("Do you think we have missing products in our catalog") textarea', + run: "text I don't know products enough to be able to answer that", +}, { // Page-2 Question: How much do we sell our Cable Management Box? + content: "Selecting answer '$80'", + trigger: 'div.js_question-wrapper:contains("How much do we sell our Cable Management Box") label:contains("$80")', +}, { // Question: Select all the products that sell for $100 or more + content: "Ticking answer 'Corner Desk Right Sit'", + trigger: 'div.js_question-wrapper:contains("Select all the products that sell for $100 or more") label:contains("Corner Desk Right Sit")' +}, { + content: "Ticking answer 'Desk Combination'", + trigger: 'div.js_question-wrapper:contains("Select all the products that sell for $100 or more") label:contains("Desk Combination")' +}, { + content: "Ticking answer 'Office Chair Black'", + trigger: 'div.js_question-wrapper:contains("Select all the products that sell for $100 or more") label:contains("Office Chair Black")' +}, { // Question: What do you think about our prices (not rated)? + trigger: 'div.js_question-wrapper:contains("What do you think about our prices") label:contains("Correctly priced")', +}, { // Page-3 Question: How many days is our money-back guarantee? + content: "Inputting answer '60'", + trigger: 'div.js_question-wrapper:contains("How many days is our money-back guarantee") input', + run: 'text 60' +}, { // Question: If a customer purchases a product on 6 January 2020, what is the latest day we expect to ship it? + content: "Inputting answer '01/06/2020'", + trigger: 'div.js_question-wrapper:contains("If a customer purchases a product on 6 January 2020, what is the latest day we expect to ship it") input', + run: 'text 01/06/2020' +}, { // Question: If a customer purchases a 1 year warranty on 6 January 2020, when do we expect the warranty to expire? + content: "Inputting answer '01/06/2021 00:00:01'", + trigger: 'div.js_question-wrapper:contains("If a customer purchases a 1 year warranty on 6 January 2020, when do we expect the warranty to expire") input', + run: 'text 01/06/2021 00:00:01' +}, { // Question: What day to you think is best for us to start having an annual sale (not rated)? + trigger: 'div.js_question-wrapper:contains("What day to you think is best for us to start having an annual sale (not rated)") input', +}, { // Question: What day and time do you think most customers are most likely to call customer service (not rated)? + trigger: 'div.js_question-wrapper:contains("What day and time do you think most customers are most likely to call customer service (not rated)") input', +}, { // Question: How many chairs do you think we should aim to sell in a year (not rated)? + content: "Inputting answer '0'", + trigger: 'div.js_question-wrapper:contains("How many chairs do you think we should aim to sell in a year (not rated)") input', + run: 'text 0' +}, { + content: "Finish Survey", + trigger: 'button[type="submit"]', +}]; + +var retrySteps = [{ + trigger: 'a:contains("Retry")' +}]; + +var lastSteps = [{ + trigger: 'h1:contains("Thank you!")', + run: function () { + if ($('a:contains("Retry")').length === 0) { + $('h1:contains("Thank you!")').addClass('tour_success'); + } + } +}, { + trigger: 'h1.tour_success', +}]; + +tour.register('test_certification_failure', { + test: true, + url: '/survey/start/4ead4bc8-b8f2-4760-a682-1fde8daaaaac' +}, [].concat(failSteps, retrySteps, failSteps, lastSteps)); + +}); diff --git a/addons/survey/static/tests/tours/certification_success.js b/addons/survey/static/tests/tours/certification_success.js new file mode 100644 index 00000000..1b793159 --- /dev/null +++ b/addons/survey/static/tests/tours/certification_success.js @@ -0,0 +1,100 @@ +odoo.define('survey.tour_test_certification_success', function (require) { +'use strict'; + +var SurveyFormWidget = require('survey.form'); +/** + * Speed up fade-in fade-out to avoid useless delay in tests. + */ +SurveyFormWidget.include({ + _submitForm: function () { + this.fadeInOutDelay = 0; + return this._super.apply(this, arguments); + } +}); + +var tour = require('web_tour.tour'); + +tour.register('test_certification_success', { + test: true, + url: '/survey/start/4ead4bc8-b8f2-4760-a682-1fde8daaaaac' +}, +[{ // Page-1 + content: "Clicking on Start Certification", + trigger: 'button.btn.btn-primary.btn-lg:contains("Start Certification")', + }, { // Question: Do we sell Acoustic Bloc Screens? + content: "Selecting answer 'Yes'", + trigger: 'div.js_question-wrapper:contains("Do we sell Acoustic Bloc Screens") label:contains("Yes")', + }, { // Question: Select all the existing products + content: "Ticking answer 'Chair floor protection'", + trigger: 'div.js_question-wrapper:contains("Select all the existing products") label:contains("Chair floor protection")' + }, { + content: "Ticking answer 'Drawer'", + trigger: 'div.js_question-wrapper:contains("Select all the existing products") label:contains("Drawer")' + }, { + content: "Ticking answer 'Conference chair'", + trigger: 'div.js_question-wrapper:contains("Select all the existing products") label:contains("Conference chair")' + }, { // Question: Select all the available customizations for our Customizable Desk + content: "Ticking answer 'Color'", + trigger: 'div.js_question-wrapper:contains("Select all the available customizations for our Customizable Desk") label:contains("Color")' + }, { + content: "Ticking answer 'Legs'", + trigger: 'div.js_question-wrapper:contains("Select all the available customizations for our Customizable Desk") label:contains("Legs")' + }, { // Question: How many versions of the Corner Desk do we have? + content: "Selecting answer '2'", + trigger: 'div.js_question-wrapper:contains("How many versions of the Corner Desk do we have") label:contains("2")', + }, { // Question: Do you think we have missing products in our catalog? (not rated) + content: "Missing products", + trigger: 'div.js_question-wrapper:contains("Do you think we have missing products in our catalog") textarea', + run: "text I think we should make more versions of the customizable desk, it's such an amazing product!", + }, { // Page-2 Question: How much do we sell our Cable Management Box? + content: "Selecting answer '$80' (wrong one)", + trigger: 'div.js_question-wrapper:contains("How much do we sell our Cable Management Box") label:contains("$80")', + }, { // Question: Select all the products that sell for $100 or more + content: "Ticking answer 'Corner Desk Right Sit'", + trigger: 'div.js_question-wrapper:contains("Select all the products that sell for $100 or more") label:contains("Corner Desk Right Sit")' + }, { + content: "Ticking answer 'Desk Combination'", + trigger: 'div.js_question-wrapper:contains("Select all the products that sell for $100 or more") label:contains("Desk Combination")' + }, { + content: "Ticking answer 'Large Desk'", + trigger: 'div.js_question-wrapper:contains("Select all the products that sell for $100 or more") label:contains("Large Desk")' + }, { // Question: What do you think about our prices (not rated)? + content: "Selecting answer 'Underpriced'", + trigger: 'div.js_question-wrapper:contains("What do you think about our prices") label:contains("Underpriced")', + }, { // Page-3 Question: How many days is our money-back guarantee? + content: "Inputting answer '30'", + trigger: 'div.js_question-wrapper:contains("How many days is our money-back guarantee") input', + run: 'text 30' + }, { // Question: If a customer purchases a product on 6 January 2020, what is the latest day we expect to ship it? + content: "Inputting answer '01/08/2020'", + trigger: 'div.js_question-wrapper:contains("If a customer purchases a product on 6 January 2020, what is the latest day we expect to ship it") input', + run: 'text 01/08/2020' + }, { // Question: If a customer purchases a 1 year warranty on 6 January 2020, when do we expect the warranty to expire? + content: "Inputting answer '01/07/2021 00:00:01'", + trigger: 'div.js_question-wrapper:contains("If a customer purchases a 1 year warranty on 6 January 2020, when do we expect the warranty to expire") input', + run: 'text 01/07/2021 00:00:01' + }, { // Question: What day to you think is best for us to start having an annual sale (not rated)? + content: "Inputting answer '01/01/2021'", + trigger: 'div.js_question-wrapper:contains("What day to you think is best for us to start having an annual sale (not rated)") input', + run: 'text 01/01/2021' + }, { // Question: What day and time do you think most customers are most likely to call customer service (not rated)? + content: "Inputting answer '01/01/2021 13:00:01'", + trigger: 'div.js_question-wrapper:contains("What day and time do you think most customers are most likely to call customer service (not rated)") input', + run: 'text 01/01/2021 13:00:01' + }, { // Question: How many chairs do you think we should aim to sell in a year (not rated)? + content: "Inputting answer '1000'", + trigger: 'div.js_question-wrapper:contains("How many chairs do you think we should aim to sell in a year (not rated)") input', + run: 'text 1000' + }, { + content: "Finish Survey", + trigger: 'button[type="submit"]', + }, { + content: "Thank you", + trigger: 'h1:contains("Thank you!")', + }, { + content: "test passed", + trigger: 'div:contains("Congratulations, you have passed the test!")', + } +]); + +}); diff --git a/addons/survey/static/tests/tours/survey.js b/addons/survey/static/tests/tours/survey.js new file mode 100644 index 00000000..22344bd2 --- /dev/null +++ b/addons/survey/static/tests/tours/survey.js @@ -0,0 +1,70 @@ +odoo.define('survey.tour_test_survey', function (require) { +'use strict'; + +var tour = require('web_tour.tour'); + +tour.register('test_survey', { + test: true, + url: '/survey/start/b137640d-14d4-4748-9ef6-344caaaaaae', +}, [ + // Page-1 + { + content: 'Click on Start', + trigger: 'button.btn:contains("Start")', + }, { + content: 'Answer Where do you live', + trigger: 'div.js_question-wrapper:contains("Where do you live") input', + run: 'text Mordor-les-bains', + }, { + content: 'Answer Where do you live', + trigger: 'div.js_question-wrapper:contains("When is your date of birth") input', + run: 'text 05/05/1980', + }, { + content: 'Answer How frequently do you buy products online', + trigger: 'div.js_question-wrapper:contains("How frequently do you buy products online") label:contains("Once a month")', + }, { + content: 'Answer How many times did you order products on our website', + trigger: 'div.js_question-wrapper:contains("How many times did you order products on our website") input', + run: 'text 12', + }, { + content: 'Submit and go to Next Page', + trigger: 'button[value="next"]', + }, + // Page-2 + { + content: 'Answer Which of the following words would you use to describe our products (High Quality)', + trigger: 'div.js_question-wrapper:contains("Which of the following words would you use to describe our products") label:contains("High quality")', + }, { + content: 'Answer Which of the following words would you use to describe our products (Good value for money)', + trigger: 'div.js_question-wrapper:contains("Which of the following words would you use to describe our products") label:contains("Good value for money")', + }, { + content: 'Answer What do your think about our new eCommerce (The new layout and design is fresh and up-to-date)', + trigger: 'div.js_question-wrapper:contains("What do your think about our new eCommerce") tr:contains("The new layout and design is fresh and up-to-date") td:first', + }, { + content: 'Answer What do your think about our new eCommerce (It is easy to find the product that I want)', + trigger: 'div.js_question-wrapper:contains("What do your think about our new eCommerce") tr:contains("It is easy to find the product that I want") td:eq(2)', + }, { + content: 'Answer What do your think about our new eCommerce (The tool to compare the products is useful to make a choice)', + trigger: 'div.js_question-wrapper:contains("What do your think about our new eCommerce") tr:contains("The tool to compare the products is useful to make a choice") td:eq(3)', + }, { + content: 'Answer What do your think about our new eCommerce (The checkout process is clear and secure)', + trigger: 'div.js_question-wrapper:contains("What do your think about our new eCommerce") tr:contains("The checkout process is clear and secure") td:eq(2)', + }, { + content: 'Answer What do your think about our new eCommerce (I have added products to my wishlist)', + trigger: 'div.js_question-wrapper:contains("What do your think about our new eCommerce") tr:contains("I have added products to my wishlist") td:last', + }, { + content: 'Answer Do you have any other comments, questions, or concerns', + trigger: 'div.js_question-wrapper:contains("Do you have any other comments, questions, or concerns") textarea', + run: 'text This is great. Really.', + }, { + content: 'Click Submit and finish the survey', + trigger: 'button[value="finish"]', + }, + // Final page + { + content: 'Thank you', + trigger: 'h1:contains("Thank you!")', + } +]); + +}); diff --git a/addons/survey/static/tests/tours/survey_prefill.js b/addons/survey/static/tests/tours/survey_prefill.js new file mode 100644 index 00000000..223b824c --- /dev/null +++ b/addons/survey/static/tests/tours/survey_prefill.js @@ -0,0 +1,155 @@ +odoo.define('survey.tour_test_survey_prefill', function (require) { +'use strict'; + +var tour = require('web_tour.tour'); + +tour.register('test_survey_prefill', { + test: true, + url: '/survey/start/b137640d-14d4-4748-9ef6-344caaaaaae' +}, +[{ // Page-1 + trigger: 'button.btn.btn-primary.btn-lg:contains("Start Survey")', + }, { // Question: Where do you live ? + trigger: 'div.js_question-wrapper:contains("Where do you live ?") input', + run: 'text Grand-Rosiere', + }, { // Question: When is your date of birth ? + trigger: 'div.js_question-wrapper:contains("When is your date of birth ?") input', + run: 'text 05/05/1980', + }, { // Question: How frequently do you buy products online ? + trigger: 'div.js_question-wrapper:contains("How frequently do you buy products online ?") label:contains("Once a week")', + }, { // Question: How many times did you order products on our website ? + trigger: 'div.js_question-wrapper:contains("How many times did you order products on our website ?") input', + run: 'text 42', + }, { + content: 'Click on Next Page', + trigger: 'button[value="next"]', + }, + // Page-2 + { // Question: Which of the following words would you use to describe our products ? + content: 'Answer Which of the following words would you use to describe our products (High Quality)', + trigger: 'div.js_question-wrapper:contains("Which of the following words would you use to describe our products") label:contains("High quality")', + }, { + content: 'Answer Which of the following words would you use to describe our products (Good value for money)', + trigger: 'div.js_question-wrapper:contains("Which of the following words would you use to describe our products") label:contains("Good value for money")', + }, { + content: 'Answer What do your think about our new eCommerce (The new layout and design is fresh and up-to-date)', + trigger: 'div.js_question-wrapper:contains("What do your think about our new eCommerce") tr:contains("The new layout and design is fresh and up-to-date") td:first', + }, { + content: 'Answer What do your think about our new eCommerce (It is easy to find the product that I want)', + trigger: 'div.js_question-wrapper:contains("What do your think about our new eCommerce") tr:contains("It is easy to find the product that I want") td:eq(2)', + }, { + content: 'Answer What do your think about our new eCommerce (The tool to compare the products is useful to make a choice)', + trigger: 'div.js_question-wrapper:contains("What do your think about our new eCommerce") tr:contains("The tool to compare the products is useful to make a choice") td:eq(3)', + }, { + content: 'Answer What do your think about our new eCommerce (The checkout process is clear and secure)', + trigger: 'div.js_question-wrapper:contains("What do your think about our new eCommerce") tr:contains("The checkout process is clear and secure") td:eq(2)', + }, { + content: 'Answer What do your think about our new eCommerce (I have added products to my wishlist)', + trigger: 'div.js_question-wrapper:contains("What do your think about our new eCommerce") tr:contains("I have added products to my wishlist") td:last', + }, { + content: 'Answer Do you have any other comments, questions, or concerns', + trigger: 'div.js_question-wrapper:contains("Do you have any other comments, questions, or concerns") textarea', + run: 'text Is the prefill working?', + }, { + // Go back to previous page + content: 'Click on the previous page name in the breadcrumb', + trigger: 'ol.breadcrumb a:first', + }, { + trigger: 'div.js_question-wrapper:contains("How many times did you order products on our website ?") input', + run: function () { + var $inputQ3 = $('div.js_question-wrapper:contains("How many times did you order products on our website ?") input'); + if ($inputQ3.val() === '42.0') { + $('.o_survey_title').addClass('prefilled'); + } + } + }, { + trigger: '.o_survey_title.prefilled', + run: function () { + // check that all the answers are prefilled in Page 1 + var $inputQ1 = $('div.js_question-wrapper:contains("Where do you live ?") input'); + if ($inputQ1.val() !== 'Grand-Rosiere') { + return; + } + + var $inputQ2 = $('div.js_question-wrapper:contains("When is your date of birth ?") input'); + if ($inputQ2.val() !== '05/05/1980') { + return; + } + + var $inputQ3 = $('div.js_question-wrapper:contains("How frequently do you buy products online ?") label:contains("Once a week") input'); + if (!$inputQ3.is(':checked')) { + return; + } + + var $inputQ4 = $('div.js_question-wrapper:contains("How many times did you order products on our website ?") input'); + if ($inputQ4.val() !== '42.0') { + return; + } + + $('.o_survey_title').addClass('tour_success'); + } + }, { + trigger: '.o_survey_title.tour_success' + }, { + content: 'Click on Next Page', + trigger: 'button[value="next"]', + }, { + trigger: 'div.js_question-wrapper:contains("Do you have any other comments, questions, or concerns") textarea', + run: function () { + var $inputQ3 = $('div.js_question-wrapper:contains("Do you have any other comments, questions, or concerns") textarea'); + if ($inputQ3.val() === "Is the prefill working?") { + $('.o_survey_title').addClass('prefilled2'); + } + } + }, { + trigger: '.o_survey_title.prefilled2', + run: function () { + // check that all the answers are prefilled in Page 2 + var $input1Q1 = $('div.js_question-wrapper:contains("Which of the following words would you use to describe our products") label:contains("High quality") input'); + if (!$input1Q1.is(':checked')) { + return; + } + + var $input2Q1 = $('div.js_question-wrapper:contains("Which of the following words would you use to describe our products") label:contains("Good value for money") input'); + if (!$input2Q1.is(':checked')) { + return; + } + + var $input1Q2 = $('div.js_question-wrapper:contains("What do your think about our new eCommerce") tr:contains("The new layout and design is fresh and up-to-date") input:first'); + if (!$input1Q2.is(':checked')) { + return; + } + + var $input2Q2 = $('div.js_question-wrapper:contains("What do your think about our new eCommerce") tr:contains("It is easy to find the product that I want") input:eq(2)'); + if (!$input2Q2.is(':checked')) { + return; + } + + var $input3Q2 = $('div.js_question-wrapper:contains("What do your think about our new eCommerce") tr:contains("The tool to compare the products is useful to make a choice") input:eq(3)'); + if (!$input3Q2.is(':checked')) { + return; + } + + var $input4Q2 = $('div.js_question-wrapper:contains("What do your think about our new eCommerce") tr:contains("The checkout process is clear and secure") input:eq(2)'); + if (!$input4Q2.is(':checked')) { + return; + } + + var $input5Q2 = $('div.js_question-wrapper:contains("What do your think about our new eCommerce") tr:contains("I have added products to my wishlist") input:last'); + if (!$input5Q2.is(':checked')) { + return; + } + + var $inputQ3 = $('div.js_question-wrapper:contains("Do you have any other comments, questions, or concerns") textarea'); + if ($inputQ3.val() !== "Is the prefill working?") { + return; + } + + $('.o_survey_title').addClass('tour_success_2'); + } + }, { + trigger: '.o_survey_title.tour_success_2' + } +]); + +}); diff --git a/addons/survey/static/tests/tours/survey_session_manage_test.js b/addons/survey/static/tests/tours/survey_session_manage_test.js new file mode 100644 index 00000000..dfd7f538 --- /dev/null +++ b/addons/survey/static/tests/tours/survey_session_manage_test.js @@ -0,0 +1,37 @@ +odoo.define('survey.session_manage_test', function (require) { +"use strict"; + +var SessionManager = require('survey.session_manage'); +/** + * Small override for test/tour purposes. + */ +SessionManager.include({ + /** + * - Trigger the fetch of answer results immediately at the start. + * (Instead of wasting 2 seconds waiting after the start). + * - Set the fade in/out time to 1 ms to avoid unnecessary delays. + * - Avoid refreshing the results every 2 seconds + */ + start: function () { + var self = this; + return this._super.apply(this, arguments) + .then(this._refreshResults.bind(this)) + .then(function () { + self.fadeInOutTime = 1; + clearInterval(self.resultsRefreshInterval); + }); + }, + + /** + * Force the timer to "now" to avoid introducing potential test breaking + * timely variables (rpc/small server delay/...) if the start_question_time flickers. + */ + _startTimer: function () { + this.$el.data('timer', moment.utc()); + return this._super.apply(this, arguments); + } +}); + +return SessionManager; + +}); diff --git a/addons/survey/static/tests/tours/survey_tour_session_create.js b/addons/survey/static/tests/tours/survey_tour_session_create.js new file mode 100644 index 00000000..ac0c2f27 --- /dev/null +++ b/addons/survey/static/tests/tours/survey_tour_session_create.js @@ -0,0 +1,20 @@ +odoo.define('survey.test_survey_session_create_tour', function (require) { +"use strict"; + +var tour = require('web_tour.tour'); +var surveySessionTools = require('survey.session_tour_tools'); + +/** + * Small tour that will simply start the session and wait for attendees. + */ +tour.register('test_survey_session_create_tour', { + url: "/web", + test: true, +}, [].concat(surveySessionTools.accessSurveySteps, [{ + trigger: 'button[name="action_start_session"]', +}, { + trigger: '.o_survey_session_attendees_count:contains("0")', + run: function () {} // check session is correctly started +}])); + +}); diff --git a/addons/survey/static/tests/tours/survey_tour_session_manage.js b/addons/survey/static/tests/tours/survey_tour_session_manage.js new file mode 100644 index 00000000..f92e6803 --- /dev/null +++ b/addons/survey/static/tests/tours/survey_tour_session_manage.js @@ -0,0 +1,432 @@ +odoo.define('survey.test_survey_session_manage_tour', function (require) { +"use strict"; + +var tour = require('web_tour.tour'); +var surveySessionTools = require('survey.session_tour_tools'); + +/** + * Since the chart is rendered using SVG, we can't use jQuery triggers to check if everything + * is correctly rendered. + * This helper method returns the chart data (Chartjs framework specific) in the following structure: + * [{ value, backgroundColor, labelColor }] + */ +var getChartData = function () { + var chartData = []; + var rootWidget = odoo.__DEBUG__.services['root.widget']; + var surveyManagePublicWidget = rootWidget.publicWidgets.find(function (widget) { + return widget.$el.hasClass('o_survey_session_manage'); + }); + + if (!surveyManagePublicWidget) { + return chartData; + } + + surveyManagePublicWidget.resultsChart.chart.data.datasets[0].data.forEach(function (value, index) { + chartData.push({ + value: value, + backgroundColor: surveyManagePublicWidget.resultsChart._getBackgroundColor({dataIndex: index}), + labelColor: surveyManagePublicWidget.resultsChart._getLabelColor({dataIndex: index}), + }); + }); + + return chartData; +}; + +var nextScreen = function () { + var e = $.Event('keydown'); + e.keyCode = 39; // arrow-right + $(document).trigger(e); +}; + +var previousScreen = function () { + var e = $.Event('keydown'); + e.keyCode = 37; // arrow-left + $(document).trigger(e); +}; + +var REGULAR_ANSWER_COLOR = '#212529'; +var CORRECT_ANSWER_COLOR = '#2CBB70'; +var WRONG_ANSWER_COLOR = '#D9534F'; + +/** + * A 'regular' answer is an answer that is nor correct, nor incorrect. + * The check is based on the specific opacity (0.8) and color of those answers. + */ +var isRegularAnswer = function (answer) { + return answer.backgroundColor.includes('0.8') && + answer.labelColor === REGULAR_ANSWER_COLOR; +}; + +/** + * The check is based on the specific opacity (0.8) and color of correct answers. + */ +var isCorrectAnswer = function (answer) { + return answer.backgroundColor.includes('0.8') && + answer.labelColor === CORRECT_ANSWER_COLOR; +}; + +/** + * The check is based on the specific opacity (0.2) and color of incorrect answers. + */ +var isIncorrectAnswer = function (answer) { + return answer.backgroundColor.includes('0.2') && + answer.labelColor === WRONG_ANSWER_COLOR; +}; + +/** + * Tour that will test the whole survey session from the host point of view. + * + * Break down of the main points: + * - Open the 'session manager' (the session was already created by a previous tour) + * - Display the nickname question, and move to the next one (as answers are not displayed) + * - Check answers are correctly displayed for the 3 'simple' question types (text, date, datetime) + * - Move to the choice question and check that answers are displayed + * (The check is rather complex, see 'getChartData' for details) + * - If everything is correctly displayed, move to the next question + * - On the scored choice question, check that the screens are correctly chained: + * no results displayed -> results displayed -> correct/incorrect answers -> leaderboard + * - On the scored + timed multiple choice question, check the same than previous question, + * except that the results are supposed to be displayed automatically when the question timer runs out + * - Test the 'back' behavior and check that screens are reversed correctly + * - Check that our final leaderboard is correct based on attendees answers + * - Close the survey session + */ +tour.register('test_survey_session_manage_tour', { + url: "/web", + test: true, +}, [].concat(surveySessionTools.accessSurveySteps, [{ + trigger: 'button[name="action_open_session_manager"]', +}, { + trigger: 'h1:contains("Nickname")', + run: function () {} // check nickname question is displayed +}, { + trigger: 'h1', + run: nextScreen +}, { + trigger: 'h1:contains("Text Question")', + run: function () {} // check text question is displayed +}, { + trigger: '.o_survey_session_progress_small:contains("3 / 3")', + run: function () {} // check we have 3 answers +}, { + trigger: '.o_survey_session_text_answer_container:contains("Attendee 1 is the best")', + run: function () {} // check attendee 1 answer is displayed +}, { + trigger: '.o_survey_session_text_answer_container:contains("Attendee 2 rulez")', + run: function () {} // check attendee 2 answer is displayed +}, { + trigger: '.o_survey_session_text_answer_container:contains("Attendee 3 will crush you")', + run: function () {} // check attendee 3 answer is displayed +}, { + trigger: 'h1', + run: nextScreen +}, { + trigger: '.o_survey_session_progress_small:contains("2 / 3")', + run: function () {} // check we have 2 answers +}, { + trigger: '.o_survey_session_text_answer_container:contains("10/10/2010")', + run: function () {} // check attendee 1 answer is displayed +}, { + trigger: '.o_survey_session_text_answer_container:contains("11/11/2011")', + run: function () {} // check attendee 2 answer is displayed +}, { + trigger: 'h1', + run: nextScreen +}, { + trigger: '.o_survey_session_progress_small:contains("2 / 3")', + run: function () {} // check we have 2 answers +}, { + trigger: '.o_survey_session_text_answer_container:contains("10/10/2010 10:00:00")', + run: function () {} // check attendee 2 answer is displayed +}, { + trigger: '.o_survey_session_text_answer_container:contains("11/11/2011 15:55:55")', + run: function () {} // check attendee 3 answer is displayed +}, { + trigger: 'h1', + run: nextScreen +}, { + trigger: 'h1:contains("Regular Simple Choice")', + run: function () { + var chartData = getChartData(); + if (chartData.length !== 3) { + console.error('Chart data should contain 3 records!'); + return; + } + + var firstAnswerData = chartData[0]; + if (firstAnswerData.value !== 2 || !isRegularAnswer(firstAnswerData)) { + console.error('First answer should be picked by 2 users!'); + return; + } + + var secondAnswerData = chartData[1]; + if (secondAnswerData.value !== 1 || !isRegularAnswer(secondAnswerData)) { + console.error('Second answer should be picked by 1 user!'); + return; + } + + var thirdAnswerData = chartData[2]; + if (thirdAnswerData.value !== 0 || !isRegularAnswer(thirdAnswerData)) { + console.error('Third answer should be picked by no users!'); + return; + } + + nextScreen(); + } +}, { + trigger: 'h1:contains("Scored Simple Choice")', + run: function () { + var chartData = getChartData(); + if (chartData.length !== 4) { + console.error('Chart data should contain 4 records!'); + return; + } + + for (var i = 0; i < chartData.length; i++) { + if (chartData[i].value !== 0) { + console.error( + 'Chart data should all be 0 because "next screen" that shows ' + + 'answers values is not triggered yet!'); + return; + } + } + + nextScreen(); + chartData = getChartData(); + + var firstAnswerData = chartData[0]; + if (firstAnswerData.value !== 1 || !isRegularAnswer(firstAnswerData)) { + console.error( + 'First answer should be picked by 1 user and its correctness should not be shown yet!' + ); + return; + } + + var secondAnswerData = chartData[1]; + if (secondAnswerData.value !== 1 || !isRegularAnswer(secondAnswerData)) { + console.error( + 'Second answer should be picked by 1 user and its correctness should not be shown yet!' + ); + return; + } + + var thirdAnswerData = chartData[2]; + if (thirdAnswerData.value !== 1 || !isRegularAnswer(thirdAnswerData)) { + console.error( + 'Third answer should be picked by 1 user and its correctness should not be shown yet!' + ); + return; + } + + var fourthAnswerData = chartData[3]; + if (fourthAnswerData.value !== 0 || !isRegularAnswer(fourthAnswerData)) { + console.error( + 'Fourth answer should be picked by no users and its correctness should not be shown yet!' + ); + return; + } + + nextScreen(); + chartData = getChartData(); + + firstAnswerData = chartData[0]; + if (firstAnswerData.value !== 1 || !isCorrectAnswer(firstAnswerData)) { + console.error( + 'First answer should be picked by 1 user and it should be correct!' + ); + return; + } + + secondAnswerData = chartData[1]; + if (secondAnswerData.value !== 1 || !isIncorrectAnswer(secondAnswerData)) { + console.error( + 'Second answer should be picked by 1 user and it should be incorrect!' + ); + return; + } + + thirdAnswerData = chartData[2]; + if (thirdAnswerData.value !== 1 || !isIncorrectAnswer(thirdAnswerData)) { + console.error( + 'Third answer should be picked by 1 user and it should be incorrect!' + ); + return; + } + + fourthAnswerData = chartData[3]; + if (fourthAnswerData.value !== 0 || !isIncorrectAnswer(fourthAnswerData)) { + console.error( + 'Fourth answer should be picked by no users and it should be incorrect!' + ); + return; + } + + nextScreen(); + nextScreen(); + } +}, { + trigger: 'h1:contains("Timed Scored Multiple Choice")', + run: function () { + var chartData = getChartData(); + if (chartData.length !== 3) { + console.error('Chart data should contain 4 records!'); + return; + } + + for (var i = 0; i < chartData.length; i++) { + if (chartData[i].value !== 0) { + console.error( + 'Chart data should all be 0 because "next screen" that shows ' + + 'answers values is not triggered yet!'); + return; + } + } + + // after 1 second, results are displayed automatically because question timer runs out + // we add 1 extra second because of the way the timer works: + // it only triggers the time_up event 1 second AFTER the delay is passed + setTimeout(function () { + chartData = getChartData(); + var firstAnswerData = chartData[0]; + if (firstAnswerData.value !== 2 || !isRegularAnswer(firstAnswerData)) { + console.error( + 'First answer should be picked by 2 users and its correctness should not be shown yet!' + ); + return; + } + + var secondAnswerData = chartData[1]; + if (secondAnswerData.value !== 2 || !isRegularAnswer(secondAnswerData)) { + console.error( + 'Second answer should be picked by 2 users and its correctness should not be shown yet!' + ); + return; + } + + var thirdAnswerData = chartData[2]; + if (thirdAnswerData.value !== 1 || !isRegularAnswer(thirdAnswerData)) { + console.error( + 'Third answer should be picked by 1 user and its correctness should not be shown yet!' + ); + return; + } + + nextScreen(); + chartData = getChartData(); + + firstAnswerData = chartData[0]; + if (firstAnswerData.value !== 2 || !isCorrectAnswer(firstAnswerData)) { + console.error( + 'First answer should be picked by 2 users and it should be correct!' + ); + return; + } + + secondAnswerData = chartData[1]; + if (secondAnswerData.value !== 2 || !isCorrectAnswer(secondAnswerData)) { + console.error( + 'Second answer should be picked by 2 users and it should be correct!' + ); + return; + } + + thirdAnswerData = chartData[2]; + if (thirdAnswerData.value !== 1 || !isIncorrectAnswer(thirdAnswerData)) { + console.error( + 'Third answer should be picked by 1 user and it should be incorrect!' + ); + return; + } + + nextScreen(); + }, 2100); + } +}, { + trigger: 'h1:contains("Final Leaderboard")', + run: function () {} // Final Leaderboard is displayed +}, { + trigger: 'h1', + run: function () { + // previous screen testing + previousScreen(); + var chartData = getChartData(); + + var firstAnswerData = chartData[0]; + if (firstAnswerData.value !== 2 || !isCorrectAnswer(firstAnswerData)) { + console.error( + 'First answer should be picked by 2 users and it should be correct!' + ); + return; + } + + var secondAnswerData = chartData[1]; + if (secondAnswerData.value !== 2 || !isCorrectAnswer(secondAnswerData)) { + console.error( + 'Second answer should be picked by 2 users and it should be correct!' + ); + return; + } + + var thirdAnswerData = chartData[2]; + if (thirdAnswerData.value !== 1 || !isIncorrectAnswer(thirdAnswerData)) { + console.error( + 'Third answer should be picked by 1 user and it should be incorrect!' + ); + return; + } + + previousScreen(); + chartData = getChartData(); + + firstAnswerData = chartData[0]; + if (firstAnswerData.value !== 2 || !isRegularAnswer(firstAnswerData)) { + console.error( + 'First answer should be picked by 2 users and its correctness should not be shown!' + ); + return; + } + + secondAnswerData = chartData[1]; + if (secondAnswerData.value !== 2 || !isRegularAnswer(secondAnswerData)) { + console.error( + 'Second answer should be picked by 2 users and its correctness should not be shown!' + ); + return; + } + + thirdAnswerData = chartData[2]; + if (thirdAnswerData.value !== 1 || !isRegularAnswer(thirdAnswerData)) { + console.error( + 'Third answer should be picked by 1 user and its correctness should not be shown!' + ); + return; + } + + previousScreen(); + chartData = getChartData(); + + for (var i = 0; i < chartData.length; i++) { + if (chartData[i].value !== 0) { + console.error( + 'Chart data should all be 0 because "next screen" that shows ' + + 'answers values is not triggered yet!'); + return; + } + } + + // Now we go forward to the "Final Leaderboard" again (3 times) + for (i = 0; i < 3; i++) { + nextScreen(); + } + } +}, { + trigger: 'h1:contains("Final Leaderboard")', + run: function () {} // Final Leaderboard is displayed +}, { + trigger: '.o_survey_session_close:has("i.fa-close")' +}, { + trigger: 'button[name="action_start_session"]', + run: function () {} // check that we can start another session +}])); + +}); diff --git a/addons/survey/static/tests/tours/survey_tour_session_start.js b/addons/survey/static/tests/tours/survey_tour_session_start.js new file mode 100644 index 00000000..309ce0af --- /dev/null +++ b/addons/survey/static/tests/tours/survey_tour_session_start.js @@ -0,0 +1,32 @@ +odoo.define('survey.test_survey_session_start_tour', function (require) { +"use strict"; + +var tour = require('web_tour.tour'); +var surveySessionTools = require('survey.session_tour_tools'); + +/** + * Small tour that will open the session manager and check + * that the attendees are accounted for, then start the session + * by going to the first question. + */ +tour.register('test_survey_session_start_tour', { + url: "/web", + test: true, +}, [].concat(surveySessionTools.accessSurveySteps, [{ + trigger: 'button[name="action_open_session_manager"]', +}, { + trigger: '.o_survey_session_attendees_count:contains("3")', + run: function () {} // check attendees count +}, { + trigger: 'h1', + run: function () { + var e = $.Event('keydown'); + e.keyCode = 39; // arrow-right + $(document).trigger(e); // start session + } +}, { + trigger: 'h1:contains("Nickname")', + run: function () {} // check first question is displayed +}])); + +}); diff --git a/addons/survey/static/tests/tours/survey_tour_session_tools.js b/addons/survey/static/tests/tours/survey_tour_session_tools.js new file mode 100644 index 00000000..a42d72e2 --- /dev/null +++ b/addons/survey/static/tests/tours/survey_tour_session_tools.js @@ -0,0 +1,21 @@ +odoo.define('survey.session_tour_tools', function (require) { +'use strict'; + +var tour = require('web_tour.tour'); + +/** + * Tool that gathers common steps to every 'survey session' tours. + */ +return { + accessSurveySteps: [tour.stepUtils.showAppsMenuItem(), { + trigger: '.o_app[data-menu-xmlid="survey.menu_surveys"]', + edition: 'community' + }, { + trigger: '.o_app[data-menu-xmlid="survey.menu_surveys"]', + edition: 'enterprise' + }, { + trigger: '.oe_kanban_card:contains("User Session Survey")', + }] +}; + +}); |
