Files
odoo_source/addons/website/static/tests/tours/edit_menus.js
T
Arthur Detroux (ard) 982e3c2671 [FIX] website: fix edit menus tour
This commit aims at making the website dialog as well as the edit_menus
tour more stable.

Commit [1] introduced a new dialog API for website.
The component WebsiteDialog handles click asynchronously.

Prior to this commit, the tour could sometimes detect and click on modal
triggers before the actions that the previous trigger was triggering
could complete. This could lead to a modal closing too early either
because a click would done on the wrong modal or the input was completed
before the validation method was called (since the click handlers are
asynchronous).

Here are a few examples of possible failure in the tour :

- The tour clicks on "Add Menu Item", which should open a new modal
- The tour then clicks on OK to make sure the modal does not close.
- The click on OK is done before the New Menu Item modal is open and
  therefore is triggered on the previous modal
- The modal is closed too early

- The tour clicks on OK while the URL field is empty
- Before the validation method is processed the tour inserts a value in
  the input field.
- The validation method doesn't block the OK method which results in the
  dialog being closed
- The tour expects the dialog to be open and crashes

- The tour clicks on OK while the URL field is empty
- Before the validation method is processed the tour inserts a value in
  the input field
- The tour clicks on OK again
- 2 entries are created instead of one.

The last one doesn't crash the tour but is still incorrect.

This commit disables the buttons when they're clicked for the first time
until the handler is processed.

This commit also make the triggers in the tour more specific so that the
tour always clicks on the right modals.

[1]: https://github.com/odoo/odoo/commit/28a78fb4e4e4465aa99fb94f7cac3a21b2188502

runbot-4122

closes odoo/odoo#95839

Signed-off-by: Quentin Smetz (qsm) <qsm@odoo.com>
2022-07-18 18:41:09 +02:00

191 lines
6.6 KiB
JavaScript

/** @odoo-module */
import wTourUtils from 'website.tour_utils';
wTourUtils.registerEditionTour('edit_menus', {
test: true,
url: '/',
}, [
// Add a megamenu item from the menu.
{
content: "open site menu",
extra_trigger: "iframe #wrapwrap",
trigger: 'button[data-menu-xmlid="website.menu_site"]',
},
{
content: "Click on Edit Menu",
trigger: 'a[data-menu-xmlid="website.menu_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 new menu",
trigger: '.modal-footer .btn-primary',
extra_trigger: '.oe_menu_editor [data-is-mega-menu="true"] .js_menu_label:contains("Megaaaaa!")',
},
wTourUtils.clickOnExtraMenuItem({extra_trigger: 'body:not(:has(.oe_menu_editor))'}, true),
{
content: "There should be a new megamenu item.",
trigger: 'iframe #top_menu .nav-item a.o_mega_menu_toggle:contains("Megaaaaa!")',
run: () => {}, // It's a check.
},
// Add a menu item in edit mode.
wTourUtils.clickOnEdit(),
{
content: "Click on a menu item",
trigger: 'iframe #top_menu .nav-item a',
extra_trigger: '#oe_snippets.o_loaded',
},
{
content: "Click on Edit Menu",
trigger: '.o_edit_menu_popover a.js_edit_menu',
},
{
content: "Trigger the link dialog (click 'Add Menu Item')",
extra_trigger: '.o_website_dialog:visible',
trigger: '.modal-body a:eq(0)',
},
{
content: "Confirm the new menu entry without a label",
extra_trigger: '.modal-dialog .o_website_dialog input:eq(0)',
trigger: '.modal-footer .btn-primary',
},
{
content: "It didn't save without a label. Fill label input.",
extra_trigger: '.o_website_dialog:eq(1):visible',
trigger: '.modal-dialog .o_website_dialog input:eq(0)',
run: 'text Random!',
},
{
content: "Confirm the new menu entry without a url",
trigger: '.modal-footer .btn-primary',
},
{
content: "It didn't save without a url. Fill url input.",
trigger: '.modal-dialog .o_website_dialog input:eq(1)',
extra_trigger: '.modal-dialog .o_website_dialog input.is-invalid',
run: 'text #',
},
{
content: "Confirm the new menu entry",
trigger: '.modal-footer .btn-primary',
},
{
content: "Save the website menu with the new entry",
trigger: '.modal-footer .btn-primary',
extra_trigger: '.oe_menu_editor .js_menu_label:contains("Random!")',
},
// Edit the new menu item from the "edit link" popover button
wTourUtils.clickOnExtraMenuItem({extra_trigger: '#oe_snippets.o_loaded'}, true),
{
content: "Menu should have a new link item",
trigger: 'iframe #top_menu .nav-item a:contains("Random!")',
},
{
content: "Click on Edit Link",
trigger: '.o_edit_menu_popover a.o_we_edit_link',
},
{
content: "Change the label",
trigger: '.modal-dialog .o_website_dialog input:eq(0)',
run: 'text Modnar',
},
{
content: "Confirm the new label",
trigger: '.modal-footer .btn-primary',
},
...wTourUtils.clickOnSave(),
wTourUtils.clickOnExtraMenuItem({extra_trigger: 'iframe body:not(.editor_enable)'}, true),
{
content: "Label should have changed",
extra_trigger: "iframe body:not(.editor_enable)",
trigger: 'iframe #top_menu .nav-item a:contains("Modnar")',
run: () => {}, // it's a check
},
// Edit the menu item from the "edit menu" popover button
wTourUtils.clickOnEdit(),
{
content: "Click on the 'Modnar' link",
extra_trigger: "#oe_snippets.o_loaded",
trigger: 'iframe #top_menu .nav-item a:contains("Modnar")',
},
{
content: "Click on the popover Edit Menu button",
trigger: '.o_edit_menu_popover a.js_edit_menu',
},
{
content: "Click on the dialog Edit Menu button",
trigger: '.oe_menu_editor .js_menu_label:contains("Modnar")',
run: function () {
const liEl = this.$anchor[0].closest('[data-menu-id]');
liEl.querySelector('button.js_edit_menu').click();
},
},
{
content: "Change the label",
trigger: '.modal-dialog .o_website_dialog input:eq(0)',
run: 'text Modnar !!',
},
{
content: "Confirm the new menu label",
trigger: '.modal-footer .btn-primary',
},
{
content: "Save the website menu with the new menu label",
trigger: '.modal-footer .btn-primary',
extra_trigger: '.oe_menu_editor .js_menu_label:contains("Modnar !!")',
},
...wTourUtils.clickOnSave(),
wTourUtils.clickOnExtraMenuItem({extra_trigger: 'iframe body:not(.editor_enable)'}, true),
{
content: "Label should have changed",
trigger: 'iframe #top_menu .nav-item a:contains("Modnar !!")',
run: () => {}, // It's a check.
},
// Nest menu item from the menu.
{
content: "open site menu",
trigger: 'button[data-menu-xmlid="website.menu_site"]',
},
{
content: "Click on Edit Menu",
trigger: 'a[data-menu-xmlid="website.menu_edit_menu"]',
},
{
content: "Drag item into parent",
trigger: '.oe_menu_editor li:contains("Contact us") > .ui-sortable-handle',
// Menu rows are 38px tall.
run: "drag_move_and_drop [50,38]@.oe_menu_editor li:contains('Home') > .ui-sortable-handle => .oe_menu_editor li:contains('Home') .ui-sortable-placeholder",
},
{
content: "Wait for drop",
trigger: '.oe_menu_editor li:contains("Home") ul li:contains("Contact us")',
run: () => {}, // It's a check.
},
{
content: "Save the website menu with new nested menus",
trigger: '.modal-footer .btn-primary',
},
{
content: "Menu item should have a child",
trigger: 'iframe #top_menu .nav-item a.dropdown-toggle:contains("Home")',
},
{
content: "When menu item is opened, child item must appear in the shown menu",
trigger: 'iframe #top_menu .nav-item:contains("Home") ul.show li a.dropdown-item:contains("Contact us")[href="/contactus"]',
run: () => {}, // It's a check.
},
]);