MDL-59845 tool_lp: Add js tracking around UI refresh
authorAndrew Nicols <andrew@nicols.co.uk>
Wed, 2 May 2018 01:15:43 +0000 (09:15 +0800)
committerAndrew Nicols <andrew@nicols.co.uk>
Wed, 2 May 2018 01:15:43 +0000 (09:15 +0800)
admin/tool/lp/amd/build/planactions.min.js
admin/tool/lp/amd/src/planactions.js

index f63fbbc..8390ffa 100644 (file)
Binary files a/admin/tool/lp/amd/build/planactions.min.js and b/admin/tool/lp/amd/build/planactions.min.js differ
index 44a335d..d4320c3 100644 (file)
@@ -130,6 +130,11 @@ define(['jquery',
      * @return {Promise}
      */
     PlanActions.prototype._callAndRefresh = function(calls, planData) {
+        // Because this function causes a refresh, we must track the JS completion from start to finish to prevent
+        // stale reference issues in Behat.
+        var callKey = 'tool_lp/planactions:_callAndRefresh-' + Math.floor(Math.random() * Math.floor(1000));
+        M.util.js_pending(callKey);
+
         var self = this;
         calls.push({
             methodname: self._contextMethod,
@@ -141,7 +146,10 @@ define(['jquery',
             .then(function() {
                 return self._renderView(arguments[arguments.length - 1]);
             })
-            .fail(notification.exception);
+            .fail(notification.exception)
+            .always(function() {
+                return M.util.js_complete(callKey);
+            });
     };
 
     /**