MDL-86527 behat: Fix random failures when toggling edit mode

This commit is contained in:
Muhammad Arnaldo
2026-01-21 15:05:19 +07:00
committed by Huong Nguyen
parent 23ad73ee56
commit f6c8f4a098
3 changed files with 17 additions and 7 deletions
+2 -3
View File
@@ -1,11 +1,10 @@
define("core/edit_switch",["exports","core/ajax","core/event_dispatcher","core/notification"],(function(_exports,_ajax,_event_dispatcher,_notification){Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.init=_exports.eventTypes=void 0;
define("core/edit_switch",["exports","core/ajax","core/event_dispatcher","core/notification","core/pending"],(function(_exports,_ajax,_event_dispatcher,_notification,_pending){var obj;
/**
* Controls the edit switch.
*
* @module core/edit_switch
* @copyright 2021 Bas Brands <bas@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
const eventTypes={editModeSet:"core/edit_switch/editModeSet"};_exports.eventTypes=eventTypes;const notifyEditModeSet=(container,editMode)=>(0,_event_dispatcher.dispatchEvent)(eventTypes.editModeSet,{editMode:editMode},container,{cancelable:!0});_exports.init=editingSwitchId=>{const editSwitch=document.getElementById(editingSwitchId);editSwitch.addEventListener("change",(()=>{var context,setmode;(context=editSwitch.dataset.context,setmode=editSwitch.checked,(0,_ajax.call)([{methodname:"core_change_editmode",args:{context:context,setmode:setmode}}])[0]).then((result=>{result.success?(editSwitch=>{editSwitch.checked?editSwitch.setAttribute("aria-checked",!0):editSwitch.setAttribute("aria-checked",!1),notifyEditModeSet(editSwitch,editSwitch.checked).defaultPrevented||(editSwitch.setAttribute("disabled",!0),window.location=editSwitch.dataset.pageurl)})(editSwitch):editSwitch.checked=!1})).catch(_notification.exception)}))}}));
*/Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.init=_exports.eventTypes=void 0,_pending=(obj=_pending)&&obj.__esModule?obj:{default:obj};const eventTypes={editModeSet:"core/edit_switch/editModeSet"};_exports.eventTypes=eventTypes;const notifyEditModeSet=(container,editMode)=>(0,_event_dispatcher.dispatchEvent)(eventTypes.editModeSet,{editMode:editMode},container,{cancelable:!0});_exports.init=editingSwitchId=>{const editSwitch=document.getElementById(editingSwitchId);editSwitch.addEventListener("change",(()=>{const pendingPromise=new _pending.default("core/edit_switch:toggle");var context,setmode;(context=editSwitch.dataset.context,setmode=editSwitch.checked,(0,_ajax.call)([{methodname:"core_change_editmode",args:{context:context,setmode:setmode}}])[0]).then((result=>{if(result.success){const redirected=(editSwitch=>(editSwitch.checked?editSwitch.setAttribute("aria-checked",!0):editSwitch.setAttribute("aria-checked",!1),!notifyEditModeSet(editSwitch,editSwitch.checked).defaultPrevented&&(editSwitch.setAttribute("disabled",!0),window.location=editSwitch.dataset.pageurl,!0)))(editSwitch);redirected||pendingPromise.resolve()}else editSwitch.checked=!1,pendingPromise.resolve()})).catch((error=>{pendingPromise.resolve(),(0,_notification.exception)(error)}))}))}}));
//# sourceMappingURL=edit_switch.min.js.map
File diff suppressed because one or more lines are too long
+14 -3
View File
@@ -24,6 +24,7 @@
import {call as fetchMany} from 'core/ajax';
import {dispatchEvent} from 'core/event_dispatcher';
import {exception as displayException} from 'core/notification';
import Pending from "core/pending";
/**
* Change the Edit mode.
@@ -58,7 +59,9 @@ const toggleEditSwitch = editSwitch => {
if (!event.defaultPrevented) {
editSwitch.setAttribute('disabled', true);
window.location = editSwitch.dataset.pageurl;
return true;
}
return false;
};
/**
@@ -108,15 +111,23 @@ const notifyEditModeSet = (container, editMode) => dispatchEvent(
export const init = editingSwitchId => {
const editSwitch = document.getElementById(editingSwitchId);
editSwitch.addEventListener('change', () => {
const pendingPromise = new Pending("core/edit_switch:toggle");
setEditMode(editSwitch.dataset.context, editSwitch.checked)
.then(result => {
.then((result) => {
if (result.success) {
toggleEditSwitch(editSwitch);
const redirected = toggleEditSwitch(editSwitch);
if (!redirected) {
pendingPromise.resolve();
}
} else {
editSwitch.checked = false;
pendingPromise.resolve();
}
return;
})
.catch(displayException);
.catch((error) => {
pendingPromise.resolve();
displayException(error);
});
});
};