From 6bd579bd6b501d316761bfc50ba8bf168f776d9f Mon Sep 17 00:00:00 2001 From: Romain Derie Date: Tue, 22 Jan 2019 13:59:43 +0000 Subject: [FIX] web_editor: send the html editor writes one after another With the following view hierarchy: A | B' (oe_structure_ID view) Before this fix, when saving multiple templates at once from the same hierarchy the COW views (website) would not be saved correctly as the first call to `write` would COW the parent view, then the second concurent call to `write` would create the child specific view under the generic parent view. Instead, the generic parent should have been cloned to a specific parent view and then the child view should be COW under the specific parent. A A' | | B' B*' (This one is the old B', without B' changes in the html editor) Instead of A A' | B' Calling the `write` one after another will do the trick. Indeed, when the second call is fired, the first call has already triggered the COW behavior. Thus, the second call correctly retrieves the COW view. Another issue might still appear, if the parent view write is sent first. Indeed, the parent view will be COW, thus the specific child view (second write waiting to be fired) will be deleted to be added on the new specific hierarchy. Thus, that write will then raise an error since the view does not exist anymore. task-1934279 Fix #30447 --- addons/website/static/src/js/html_editor.test.js | 75 ++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 addons/website/static/src/js/html_editor.test.js (limited to 'addons/website/static/src/js/html_editor.test.js') diff --git a/addons/website/static/src/js/html_editor.test.js b/addons/website/static/src/js/html_editor.test.js new file mode 100644 index 00000000000..cfbcd896bde --- /dev/null +++ b/addons/website/static/src/js/html_editor.test.js @@ -0,0 +1,75 @@ +odoo.define('website.test.html_editor', function (require) { +'use strict'; + +var tour = require('web_tour.tour'); +var base = require('web_editor.base'); + +tour.register('html_editor_multiple_templates', { + test: true, + url: '/aboutus', + wait_for: base.ready(), +}, + [ + // 1. Edit the page through Edit Mode, it will COW the view + { + content: "enter edit mode", + trigger: 'a[data-action=edit]', + }, + { + content: "drop a snippet", + trigger: '#oe_snippets .oe_snippet:has(.s_cover) .oe_snippet_thumbnail', + // id starting by 'oe_structure..' will actually create an inherited view + run: "drag_and_drop #oe_structure_test_ui", + }, + { + content: "save the page", + extra_trigger: '#wrapwrap .s_cover', + trigger: "#web_editor-top-edit button[data-action=save]", + }, + // 2. Edit generic aboutus view + { + content: "open customize menu", + extra_trigger: "body:not(.editor_enable)", + trigger: '#customize-menu > a', + }, + { + content: "open html editor", + trigger: '#html_editor', + }, + { + content: "add something in the aboutus view", + trigger: 'div.ace_line .ace_xml:contains("aboutus")', + run: function () { + ace.edit('ace-view-editor').getSession().insert({row: 3, column: 1}, '

somenewcontent

\n'); + }, + }, + // 3. Edit oe_structure specific view + { + content: "select oe_structure specific view", + trigger: 'div.ace_line .ace_xml:contains("somenewcontent")', + run: function () { + var viewId = $('#ace-view-list option:contains("oe_structure")').val(); + $('#ace-view-list').val(viewId).trigger('change'); + }, + }, + { + content: "add something in the oe_structure specific view", + trigger: 'div.ace_line .ace_xml:contains("s_cover")', + run: function () { + ace.edit('ace-view-editor').getSession().insert({row: 2, column: 1}, '

anothernewcontent

\n'); + }, + }, + { + content: "save the html editor", + extra_trigger: 'div.ace_line .ace_xml:contains("anothernewcontent")', + trigger: ".o_ace_view_editor button[data-action=save]", + }, + { + content: "check that the page has both modification", + extra_trigger: '#wrapwrap:contains("anothernewcontent")', + trigger: '#wrapwrap:contains("somenewcontent")', + run: function () {}, // it's a check + }, + ] +); +}); -- cgit v1.2.3 From 751ea9634a690bb1642be6d66d4124d6311766c7 Mon Sep 17 00:00:00 2001 From: Romain Derie Date: Fri, 25 Jan 2019 15:02:14 +0000 Subject: [IMP] website: add tests for scss edition on html editor As this behavior was recently broken (fixed in #30403), this commit adds a test tour for that flow. task-1934279 Fix #30447 --- addons/website/static/src/js/html_editor.test.js | 67 ++++++++++++++++++++++++ 1 file changed, 67 insertions(+) (limited to 'addons/website/static/src/js/html_editor.test.js') diff --git a/addons/website/static/src/js/html_editor.test.js b/addons/website/static/src/js/html_editor.test.js index cfbcd896bde..a57e7d4ea22 100644 --- a/addons/website/static/src/js/html_editor.test.js +++ b/addons/website/static/src/js/html_editor.test.js @@ -72,4 +72,71 @@ tour.register('html_editor_multiple_templates', { }, ] ); + +tour.register('test_html_editor_scss', { + test: true, + url: '/aboutus', + wait_for: base.ready(), +}, + [ + // 1. Open Html Editor and select a scss file + { + content: "open customize menu", + extra_trigger: '#wrap:visible', // ensure state for later + trigger: '#customize-menu > a', + }, + { + content: "open html editor", + trigger: '#html_editor', + }, + { + content: "open type switcher", + trigger: '.o_ace_type_switcher button', + }, + { + content: "select scss files", + trigger: '.o_ace_type_switcher_choice[data-type="scss"]', + }, + { + content: "select 'website.ui.scss'", + trigger: '#ace-scss-list', + run: function () { + var scssId = $('#ace-scss-list option:contains("website.ui")').val(); + $('#ace-scss-list').val(scssId).trigger('change'); + }, + }, + // 2. Edit that file and ensure it was saved then reset it + { + content: "add some scss content in the file", + trigger: 'div.ace_line .ace_variable:contains("body.o_connected_user")', + run: function () { + ace.edit('ace-view-editor').getSession().insert({row: 2, column: 0}, '#wrap {display: none;}\n'); + }, + }, + { + content: "save the html editor", + extra_trigger: 'div.ace_line:contains("#wrap {display: none;}")', + trigger: ".o_ace_view_editor button[data-action=save]", + }, + { + content: "check that the scss modification got applied", + trigger: 'body:has(#wrap:hidden)', + run: function () {}, // it's a check + }, + { + content: "reset view (after reload, html editor should have been reopened where it was)", + trigger: '#ace-view-id button[data-action="reset"]', + }, + { + content: "confirm reset warning", + trigger: '.modal-footer .btn-primary', + }, + { + content: "check that the scss file was reset correctly, wrap content should now be visible again", + trigger: '#wrap:visible', + run: function () {}, // it's a check + }, + ] +); + }); -- cgit v1.2.3 From 326a44c3f7f754160c78649f7c6c69dc0c030d92 Mon Sep 17 00:00:00 2001 From: Romain Derie Date: Fri, 25 Jan 2019 10:35:22 +0000 Subject: [FIX] web_editor, website: consider COW view when loading view Before this commit: 1. If we were editing a template with no xml_id, typically the case when editing a specific view (COW'd), the 'Template ID' label would be left empty as the view does not have an xml_id but only a key. 2. If we were editing a generic view, the template would be COW'd and replaced by the specific one created during the save. After the save, the page would be reload and will try to reopen the edited template (stored in url `res=123`). But as this template would be replaced by the COW'd view, the JS would crash trying to access an inexisting view. The HTML editor would then open in a very thin modal, barely editable. Now: 1. Display the template's key instead of its xml_id. The key is basically a duplicate of the xml_id, mainly used in website. 2. If we are saving a generic view, we search for its newly created specific view to upload the URL hash before reloading. task-1934279 Fix #30447 --- addons/website/static/src/js/html_editor.test.js | 1 + 1 file changed, 1 insertion(+) (limited to 'addons/website/static/src/js/html_editor.test.js') diff --git a/addons/website/static/src/js/html_editor.test.js b/addons/website/static/src/js/html_editor.test.js index a57e7d4ea22..6c7633cf7aa 100644 --- a/addons/website/static/src/js/html_editor.test.js +++ b/addons/website/static/src/js/html_editor.test.js @@ -54,6 +54,7 @@ tour.register('html_editor_multiple_templates', { }, { content: "add something in the oe_structure specific view", + extra_trigger: '#ace-view-id:contains("website.aboutus_oe_structure_test_ui")', // If no xml_id it should show key trigger: 'div.ace_line .ace_xml:contains("s_cover")', run: function () { ace.edit('ace-view-editor').getSession().insert({row: 2, column: 1}, '

anothernewcontent

\n'); -- cgit v1.2.3