UNPKG

siesta-lite

Version:

Stress-free JavaScript unit testing and functional testing tool, works in NodeJS and browsers

116 lines (104 loc) 4.87 kB
<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>The source code</title> <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" /> <script type="text/javascript" src="../resources/prettify/prettify.js"></script> <style type="text/css"> .highlight { display: block; background-color: #ddd; } </style> <script type="text/javascript"> function highlight() { document.getElementById(location.hash.replace(/#/, "")).className = "highlight"; } </script> </head> <body onload="prettyPrint(); highlight();"> <pre class="prettyprint lang-js">/* Siesta 5.6.1 Copyright(c) 2009-2022 Bryntum AB https://bryntum.com/contact https://bryntum.com/products/siesta/license */ <span id='Siesta-Test-ExtJS-Ajax'>/** </span>@class Siesta.Test.ExtJS.Ajax This is a mixin, with helper methods for mocking Ajax functionality in Ext JS. This mixin is consumed by {@link Siesta.Test.ExtJS}. This is only supported when testing Ext JS 4. */ Role(&#39;Siesta.Test.ExtJS.Ajax&#39;, { has : { responses : Joose.I.Array, urlMatchers : Joose.I.Array }, methods: { <span id='Siesta-Test-ExtJS-Ajax-method-isAjaxLoading'> /** </span> * This assertion passes if there is at least one ongoing ajax call. * * @param {Object} object (optional) The options object passed to Ext.Ajax.request * @param {String} [description] The description for the assertion */ isAjaxLoading: function (obj, description) { var Ext = this.Ext(); this.ok(Ext.Ajax.isLoading(obj), description || Siesta.Resource(&#39;Siesta.Test.ExtJS.Ajax&#39;, &#39;ajaxIsLoading&#39;)); }, <span id='Siesta-Test-ExtJS-Ajax-method-ajaxRequestAndThen'> /** </span> * This method calls the supplied URL using Ext.Ajax.request and then calls the provided callback. The callback will be called with the * same parameters as the normal Ext.Ajax.request callback is called with (&quot;options&quot;, &quot;success&quot; and &quot;response&quot;). To get the response text, * use response.responseText. * * @param {String/Object} url The url or the options to pass to Ext.Ajax.request * @param {Function} callback The callback to call after the ajax request is completed * @param {Object} scope The scope for the callback */ ajaxRequestAndThen: function (url, callback, scope) { var Ext = this.Ext(); var options = url; if (typeof(url) === &#39;string&#39;) { options = { url : url, callback : callback, scope : scope }; } Ext.Ajax.request(options); }, <span id='Siesta-Test-ExtJS-Ajax-method-waitForAjaxRequest'> /** </span> * Waits until the passed Ext.Ajax request object has completed, or until the latest performed Ajax request is done if the first argument is omitted. * * @param {Object} object (optional) The options object passed to Ext.Ajax.request * @param {Function} callback The callback to call after the ajax request is completed * @param {Object} scope The scope for the callback * @param {Int} timeout The maximum amount of time to wait for the condition to be fulfilled. Defaults to the {@link Siesta.Test#waitForTimeout} value. */ waitForAjaxRequest: function (obj, callback, scope, timeout) { var Ext = this.Ext(); var msg; if (typeof obj === &#39;function&#39;) { msg = &#39; &#39; + Siesta.Resource(&#39;Siesta.Test.ExtJS.Ajax&#39;, &#39;allAjaxRequestsToComplete&#39;); timeout = scope; scope = callback; callback = obj; obj = undefined; } else { msg = &#39; &#39; + Siesta.Resource(&#39;Siesta.Test.ExtJS.Ajax&#39;, &#39;ajaxRequest&#39;) + &#39; &quot;&#39; + obj.options.url + &#39;&quot; &#39; + Siesta.Resource(&#39;Siesta.Test.ExtJS.Ajax&#39;, &#39;toComplete&#39;); } return this.waitFor({ method : function() { if (obj) { return !Ext.Ajax.isLoading(obj) &amp;&amp; obj; } return !Ext.Ajax.isLoading(); }, callback : callback, scope : scope, timeout : timeout, assertionName : &#39;waitForAjaxRequest&#39;, description : msg }); } } }); </pre> </body> </html>