From cda1f774e7e1c3b75182e717eee5199fbfbeb9e9 Mon Sep 17 00:00:00 2001
From: Xavier Morel <xmo@odoo.com>
Date: Fri, 17 Jan 2020 07:02:01 +0000
Subject: [PATCH] [FIX] website, test_website: problematic tours

Fix various tours which either have transient failures due to logging
the entire browser lifecycle or don't deal well with the last step
being suppressed if no explicit `run` is provided.

* test_website: add a warning final step for the page reset as there's
  no way to actually run a tour step in the recovery page (because
  it's asset-less)
* website: remove final step's action in reset password tour, it's
  relatively low-value and adding a proper followup is probably not
  worth the effort
* website: add final check step in dashboard tour, as we want to check
  that the dashboard gets loaded, but we don't want that to be dangling
---
 .../static/tests/tours/reset_views.js           | 17 +++++++++++++----
 .../static/tests/tours/dashboard_tour.js        |  9 +++++----
 .../static/tests/tours/reset_password.js        | 17 +----------------
 3 files changed, 19 insertions(+), 24 deletions(-)

diff --git a/addons/test_website/static/tests/tours/reset_views.js b/addons/test_website/static/tests/tours/reset_views.js
index bc323eaec2f4..0c7aa9517ad7 100644
--- a/addons/test_website/static/tests/tours/reset_views.js
+++ b/addons/test_website/static/tests/tours/reset_views.js
@@ -3,6 +3,15 @@ odoo.define('test_website.reset_views', function (require) {
 
 var tour = require("web_tour.tour");
 
+var BROKEN_STEP = {
+    // because saving a broken template opens a recovery page with no assets
+    // there's no way for the tour to resume on the new page, and thus no way
+    // to properly wait for the page to be saved & reloaded in order to fix the
+    // race condition of a tour ending on a side-effect (with the possible
+    // exception of somehow telling the harness / browser to do it)
+    trigger: 'body',
+    run: function () {}
+};
 tour.register('test_reset_page_view_complete_flow_part1', {
     test: true,
     url: '/test_page_view',
@@ -45,9 +54,8 @@ tour.register('test_reset_page_view_complete_flow_part1', {
             content: "save the html editor",
             extra_trigger: '.ace_content:contains("not.exist")',
             trigger: ".o_ace_view_editor button[data-action=save]",
-        }
-
-        // 3. Reset the broken view
+        },
+        BROKEN_STEP
     ]
 );
 
@@ -93,7 +101,8 @@ tour.register('test_reset_page_view_complete_flow_part2', {
         {
             content: "save the html editor",
             trigger: ".o_ace_view_editor button[data-action=save]",
-        }
+        },
+        BROKEN_STEP
     ]
 );
 
diff --git a/addons/website/static/tests/tours/dashboard_tour.js b/addons/website/static/tests/tours/dashboard_tour.js
index a8566d63a971..b02747c6caaf 100644
--- a/addons/website/static/tests/tours/dashboard_tour.js
+++ b/addons/website/static/tests/tours/dashboard_tour.js
@@ -9,13 +9,14 @@ tour.register("backend_dashboard", {
 }, [tour.STEPS.SHOW_APPS_MENU_ITEM,
     {
     trigger: 'a[data-menu-xmlid="website.menu_website_configuration"]',
-    run: 'click',
 }, {
     trigger: '.dropdown-toggle[data-menu-xmlid="website.menu_dashboard"]',
-    run: 'click',
 }, {
     trigger: '.dropdown-item[data-menu-xmlid="website.menu_website_google_analytics"]',
-    content: 'Check if traceback',
-    run: 'click',
+}, {
+    // Visits section should always be present even when empty / not hooked to anything
+    trigger: 'h2:contains("Visits")',
+    content: "Check if dashboard loads",
+    run: function () {}
 }]);
 });
diff --git a/addons/website/static/tests/tours/reset_password.js b/addons/website/static/tests/tours/reset_password.js
index 9484a4c039fe..0ca5f6022889 100644
--- a/addons/website/static/tests/tours/reset_password.js
+++ b/addons/website/static/tests/tours/reset_password.js
@@ -151,22 +151,7 @@ tour.register('website_reset_password', {
     },
     {
         content: "check logged in, and reset admin website",
-        trigger: '.oe_topbar_name:contains("Admin")',
-        run: function () {
-            return rpc.query({
-                model: 'res.partner',
-                method: 'name_search',
-                kwargs: {'name': 'Admin'},
-            }).then(function (res) {
-                return rpc.query({
-                    'model': 'res.partner',
-                    'method': 'write',
-                    'args': [[res[0][0]], {
-                        'website_id': false,
-                    }],
-                });
-            });
-        },
+        trigger: '.oe_topbar_name:contains("Admin")'
     },
 ]);
 });
-- 
GitLab