diff --git a/addons/web_editor/static/src/js/editor/snippets.editor.js b/addons/web_editor/static/src/js/editor/snippets.editor.js index 645b797fd84..79b86a0301b 100644 --- a/addons/web_editor/static/src/js/editor/snippets.editor.js +++ b/addons/web_editor/static/src/js/editor/snippets.editor.js @@ -470,8 +470,11 @@ var SnippetEditor = Widget.extend({ // body. If the editable has options, we do not want to show them. parent = $(parent).closest('body'); } - this.trigger_up('activate_snippet', { - $snippet: $(previousSibling || nextSibling || parent) + const activateSnippetProm = new Promise(resolve => { + this.trigger_up('activate_snippet', { + $snippet: $(previousSibling || nextSibling || parent), + onSuccess: resolve, + }); }); // Actually remove the snippet and its option UI. @@ -523,7 +526,11 @@ var SnippetEditor = Widget.extend({ this.$body.find('.o_table_handler').remove(); this.trigger_up('snippet_removed'); - this.destroy(); + // FIXME that whole Promise should be awaited before the DOM removal etc + // as explained above where it is defined. However, it is critical to at + // least await it before destroying the snippet editor instance + // otherwise the logic of activateSnippet gets messed up. + activateSnippetProm.then(() => this.destroy()); $parent.trigger('content_changed'); // TODO Page content changed, some elements may need to be adapted diff --git a/addons/website/static/tests/tours/snippet_popup_add_remove.js b/addons/website/static/tests/tours/snippet_popup_add_remove.js new file mode 100644 index 00000000000..fc457e8635f --- /dev/null +++ b/addons/website/static/tests/tours/snippet_popup_add_remove.js @@ -0,0 +1,30 @@ +/** @odoo-module */ + +import tour from 'web_tour.tour'; + +tour.register('snippet_popup_add_remove', { + test: true, + url: '/?enable_editor=1', +}, [{ + content: 'Drop s_popup snippet', + trigger: '#oe_snippets .oe_snippet:has( > [data-snippet="s_popup"]) .oe_snippet_thumbnail', + run: "drag_and_drop #wrap", +}, { + content: 'Edit s_popup snippet', + in_modal: false, + trigger: '#wrap.o_editable [data-snippet="s_popup"] .row > div', // Click deep in the snippet structure +}, { + content: 'Check s_popup setting are loaded, wait panel is visible', + in_modal: false, + trigger: '.o_we_customize_panel', + run: () => null, +}, { + content: `Remove the s_popup snippet`, + in_modal: false, + trigger: '.o_we_customize_panel we-button.oe_snippet_remove:first', +}, { + content: 'Check the s_popup was removed', + in_modal: false, + trigger: '#wrap.o_editable:not(:has([data-snippet="s_popup"]))', + run: () => null, +}]); diff --git a/addons/website/tests/test_snippets.py b/addons/website/tests/test_snippets.py index e651d04a32c..557a7df6d3e 100644 --- a/addons/website/tests/test_snippets.py +++ b/addons/website/tests/test_snippets.py @@ -38,3 +38,6 @@ class TestSnippets(HttpCase): 'https://instagram.com/odoo.official/', 'Social media should have been updated' ) + + def test_06_snippet_popup_add_remove(self): + self.start_tour('/?enable_editor=1', 'snippet_popup_add_remove', login='admin')