Files
odoo_source/addons/website/static/tests/tours/edit_megamenu.js
T
Younn Olivier 7b36c29417 [FIX] web_editor, *: fix link popover position in mobile edition
*: website, test_website

Before this commit, the LinkPopoverWidget element was not positioned
correctly in mobile edition.

With [1] that introduced the website edition using an iframe, the
element was appended on the global document, outside of the iframe, so
that it was not overlapped by the snippets manipulators (that were also
in the global document).

But Bootstrap popovers are not meant to be used "on top" of iframes.
Bootstrap uses the container's ownerDocument to compute placements, and
does not take into account whether or not the target is located inside
an iframe (therefore, skipping the iframe's offset and dimensions in the
placements computations).

This was leading to a visual bug in mobile edition: the iframe top, left
values were not computed by the popover, and it was not positioned
correctly.

Since [2] moved the manipulators inside the iframe, the popover can be
initialised using its target ownerDocument body, without being
overlapped by the manipulators.

Styles are adapted so that the popover stays consistent in the frontend
and the backend, and a container option is added to the widget so that
the element can be placed with other snippets manipulators from the
website builder.

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

task-2687506

closes odoo/odoo#103562

X-original-commit: 931d488af0d4dce529e4ea4ab3c8b827bda0d699
Signed-off-by: Quentin Smetz (qsm) <qsm@odoo.com>
Signed-off-by: Younn Olivier (yol) <yol@odoo.com>
2022-10-20 12:19:25 +02:00

81 lines
2.7 KiB
JavaScript

odoo.define("website.tour.edit_megamenu", function (require) {
"use strict";
const wTourUtils = require('website.tour_utils');
const toggleMegaMenu = (stepOptions) => Object.assign({}, {
content: "Toggles the mega menu.",
trigger: 'iframe #top_menu .nav-item a.o_mega_menu_toggle',
run: function () {
// If the mega menu is displayed inside the extra menu items, it should
// already be displayed.
if (!this.$anchor[0].closest('.o_extra_menu_items')) {
this.$anchor[0].dispatchEvent(new Event('click'))
}
},
}, stepOptions);
wTourUtils.registerWebsitePreviewTour('edit_megamenu', {
test: true,
url: '/',
edition: true,
}, [
// Add a megamenu item to the top menu.
{
content: "Click on a menu item",
extra_trigger: '#oe_snippets.o_loaded',
trigger: 'iframe #top_menu .nav-item a',
},
{
content: "Click on 'Link' to open Link Dialog",
trigger: 'iframe .o_edit_menu_popover a.js_edit_menu',
},
{
content: "Trigger the link dialog (click 'Add Mega Menu Item')",
extra_trigger: '.o_website_dialog:visible',
trigger: '.modal-body a:eq(1)',
},
{
content: "Write a label for the new menu item",
trigger: '.modal-dialog .o_website_dialog input',
run: 'text Megaaaaa!'
},
{
content: "Confirm the mega menu label",
trigger: '.modal-footer .btn-primary',
},
{
content: "Save the website menu with a new mega menu",
trigger: '.modal-footer .btn-primary',
extra_trigger: '.oe_menu_editor [data-is-mega-menu="true"] .js_menu_label:contains("Megaaaaa!")',
},
// Edit a menu item
wTourUtils.clickOnExtraMenuItem({extra_trigger: '#oe_snippets.o_loaded'}, true),
toggleMegaMenu({extra_trigger: 'iframe #top_menu .nav-item a.o_mega_menu_toggle:contains("Megaaaaa!")'}),
{
content: "Clicks on the first title item.",
trigger: 'iframe .o_mega_menu h4',
},
{
content: "Press enter.",
trigger: 'iframe .o_mega_menu h4',
run: function (actions) {
this.$anchor[0].dispatchEvent(new window.InputEvent('input', {bubbles: true, inputType: 'insertParagraph'}));
},
},
{
content: "The menu should still be visible. Edit a menu item.",
trigger: 'iframe .o_mega_menu h4',
run: 'text New Menu Item',
},
...wTourUtils.clickOnSave(),
wTourUtils.clickOnExtraMenuItem({extra_trigger: 'iframe body:not(.editor_enable)'}, true),
toggleMegaMenu(),
{
content: "The menu item should have been renamed.",
trigger: 'iframe .o_mega_menu h4:contains("New Menu Item")',
run: function () {}, // it's a check
},
]);
});