[FIX] website: (re)start widgets on a cloned snippet

Commit [1] moved the website builder in the backend and in doing so
transferred event handling to the wysiwyg_adapter from the edit button
widget. Unfortunately, during that process, handling of event for
cloned snippets was forgotten.

This commit restores that and adds a test.

[1]: https://github.com/odoo/odoo/commit/31cc10b91dc7762e23b4bde9b945be0c4ce3fe3b

task-2687506

Part-of: odoo/odoo#94564
This commit is contained in:
Arthur Detroux (ard)
2022-08-10 20:28:48 +02:00
committed by qsm-odoo
parent 51c7734ef3
commit 24ca4ae3fb
3 changed files with 69 additions and 0 deletions
@@ -619,6 +619,37 @@ export class WysiwygAdapterComponent extends ComponentAdapter {
return this.props.quitCallback();
}
}
/**
* Called when a snippet is about to be cloned in the page. Notifies the
* WebsiteRoot that it should stop the public widgets inside that snippet.
*
* @private
* @param {OdooEvent} ev
*/
_onSnippetWillBeCloned(ev) {
this._websiteRootEvent('widgets_stop_request', {
$target: ev.data.$target,
});
}
/**
* Called when a snippet is cloned in the page. Notifies the WebsiteRoot
* that it should start the public widgets for this snippet and the snippet it
* was cloned from.
*
* @private
* @param {OdooEvent} ev
*/
_onSnippetCloned(ev) {
this._websiteRootEvent('widgets_start_request', {
editableMode: true,
$target: ev.data.$target,
});
this._websiteRootEvent('widgets_start_request', {
editableMode: true,
$target: ev.data.$origin,
});
}
/***
* Starts the widgets inside the dropped snippet.
*
@@ -732,6 +763,8 @@ WysiwygAdapterComponent.prototype.events = {
'context_get': '_onContextGet',
'action_demand': '_handleAction',
'request_cancel': '_onCancelRequest',
'snippet_will_be_cloned': '_onSnippetWillBeCloned',
'snippet_cloned': '_onSnippetCloned',
'snippet_dropped': '_onSnippetDropped',
'snippet_removed': '_onSnippetRemoved',
'reload_bundles': '_reloadBundles',
@@ -0,0 +1,33 @@
/** @odoo-module **/
import wTourUtils from 'website.tour_utils';
const countdownSnippet = {
name: 'Countdown',
id: 's_countdown',
};
const dragNDropOutOfFooter = wTourUtils.dragNDrop(countdownSnippet);
dragNDropOutOfFooter.run = 'drag_and_drop iframe #wrapwrap #wrap';
wTourUtils.registerEditionTour('website_start_cloned_snippet', {
edition: true,
test: true,
url: '/',
}, [
dragNDropOutOfFooter,
wTourUtils.clickOnSnippet(countdownSnippet),
{
content: 'Click on clone snippet',
trigger: '.oe_snippet_clone',
},
{
content: 'Check that the cloned snippet has a canvas and that something has been drawn inside of it',
trigger: 'iframe .s_countdown:eq(1) canvas',
run: function () {
// Check that at least one bit has been drawn in the canvas
if (!this.$anchor[0].getContext('2d').getImageData(0, 0, 1000, 1000).data.includes(1)) {
console.error('The cloned snippet should have been started');
}
},
},
]);
+3
View File
@@ -308,3 +308,6 @@ class TestUi(odoo.tests.HttpCase):
def test_20_snippet_editor_panel_options(self):
self.start_tour("/@/?enable_editor=1", "snippet_editor_panel_options", login="admin")
def test_21_website_start_cloned_snippet(self):
self.start_tour('/web', 'website_start_cloned_snippet', login='admin')