From 2e44cb41eaa86b0044e36fdbc19d74e75c684581 Mon Sep 17 00:00:00 2001 From: "Arthur Detroux (ard)" Date: Wed, 5 Jan 2022 13:45:28 +0000 Subject: [PATCH] [FIX] website: fix editor not starting after creating a website Commit [1] introduced an automatic start of edit mode when selecting a theme but didn't take into account wether the frontend lang of the user was matching that of the website that is supposed to enter in edit mode. Steps to reproduce: - Create an empty database and install website. - Add an extra lang on website (e.g FR) and visit the website in that lang. - Go in settings an create a new website, skiper the configurator, select a theme. - Redirect is with enable_editor but nothing happens. The editor isn't started if not in the source's lang. This commit redirect the user to the default_lang of the website so that editor can always be started. It also introduces a tour to test out the flow. [1]: https://github.com/odoo/odoo/commit/f474eac4543712ae5b1c7d614f9eff9367445107 task-2687416 closes odoo/odoo#85058 X-original-commit: 02e08af7278cd66d768fe6a4f23aa17eb816be3c Signed-off-by: Romain Derie (rde) --- addons/website/models/website.py | 3 + .../static/tests/tours/automatic_editor.js | 95 +++++++++++++++++++ addons/website/tests/__init__.py | 1 + addons/website/tests/test_automatic_editor.py | 17 ++++ 4 files changed, 116 insertions(+) create mode 100644 addons/website/static/tests/tours/automatic_editor.js create mode 100644 addons/website/tests/test_automatic_editor.py diff --git a/addons/website/models/website.py b/addons/website/models/website.py index c4fc144f33e..22c39daae89 100644 --- a/addons/website/models/website.py +++ b/addons/website/models/website.py @@ -1281,6 +1281,9 @@ class Website(models.Model): def button_go_website(self, path='/', mode_edit=False): self._force() if mode_edit: + # If the user gets on a translated page (e.g /fr) the editor will + # never start. Forcing the default language fixes this issue. + path = url_for(path, self.default_lang_id.url_code) path += '?enable_editor=1' return { 'type': 'ir.actions.act_url', diff --git a/addons/website/static/tests/tours/automatic_editor.js b/addons/website/static/tests/tours/automatic_editor.js new file mode 100644 index 00000000000..5e8dc5b2efe --- /dev/null +++ b/addons/website/static/tests/tours/automatic_editor.js @@ -0,0 +1,95 @@ +odoo.define('website.tour.automatic_editor', function (require) { +'use strict'; + +const tour = require('web_tour.tour'); + +tour.register('automatic_editor_on_new_website', { + test: true, + url: '/', +}, +[ + { + content: "Select the language dropdown", + trigger: '.js_language_selector .dropdown-toggle' + }, + { + content: "click on Add a language", + trigger: 'a.o_add_language', + }, + { + content: "Select dropdown", + trigger: 'select[name=lang]', + run: () => { + $('select[name="lang"]').val('"pa_GB"').change(); + } + }, + { + content: "load parseltongue", + extra_trigger: '.modal select[name="lang"]:propValueContains(pa_GB)', + trigger: '.modal-footer button:first', + }, + { + content: "Select the language dropdown", + trigger: '.js_language_selector .dropdown-toggle', + }, + { + content: "Select parseltongue", + trigger: 'a.js_change_lang[data-url_code=pa_GB]', + }, + { + content: "Check that we're on parseltongue and then go to settings", + trigger: 'html[lang=pa-GB]', + run: () => { + // Now go through the settings for a new website. A frontend_lang + // cookie was set during previous steps. It should not be used when + // redirecting to the frontend in the following steps. + window.location.href = '/web#action=website.action_website_configuration'; + } + }, + { + content: "create a new website", + trigger: 'button[name="action_website_create_new"]', + }, + { + content: "insert website name", + trigger: 'input[name="name"]', + run: 'text Website EN' + }, + { + content: "validate the website creation modal", + trigger: 'button.btn-primary' + }, + { + content: "skip configurator", + // This trigger targets the skip button, it doesn't have a more + // explicit class or ID. + trigger: '.o_configurator_container .container-fluid .btn.btn-link' + }, + { + content: "make hover button appear", + trigger: '.o_theme_preview', + run: () => { + $('.o_theme_preview .o_button_area').attr('style', 'visibility: visible; opacity: 1;'); + }, + }, + { + content: "Install a theme", + trigger: 'button[data-name="button_choose_theme"]' + }, + { + content: "Check that the editor is loaded", + trigger: 'body.editor_enable', + timeout: 30000, + run: () => null, // it's a check + }, + { + content: "exit edit mode", + trigger: '.o_we_website_top_actions button.btn-primary:contains("Save")', + }, + { + content: "wait for editor to close", + trigger: 'body:not(.editor_enable)', + run: () => null, // It's a check + } +]); +}); diff --git a/addons/website/tests/__init__.py b/addons/website/tests/__init__.py index c01e33f3057..de00979d8f9 100644 --- a/addons/website/tests/__init__.py +++ b/addons/website/tests/__init__.py @@ -2,6 +2,7 @@ # Part of Odoo. See LICENSE file for full copyright and licensing details. from . import test_attachment from . import test_auth_signup_uninvited +from . import test_automatic_editor from . import test_base_url from . import test_configurator from . import test_controllers diff --git a/addons/website/tests/test_automatic_editor.py b/addons/website/tests/test_automatic_editor.py new file mode 100644 index 00000000000..13f3ddced14 --- /dev/null +++ b/addons/website/tests/test_automatic_editor.py @@ -0,0 +1,17 @@ +from odoo.tests import tagged +from odoo.addons.website.tests.test_configurator import TestConfiguratorCommon + +@tagged('post_install', '-at_install') +class TestAutomaticEditor(TestConfiguratorCommon): + + def test_01_automatic_editor_on_new_website(self): + # We create a lang because if the new website is displayed in this lang + # instead of the website's default one, the editor won't automatically + # start. + self.env['res.lang'].create({ + 'name': 'Parseltongue', + 'code': 'pa_GB', + 'iso_code': 'pa_GB', + 'url_code': 'pa_GB', + }) + self.start_tour('/', 'automatic_editor_on_new_website', login='admin')