UNPKG

siesta-lite

Version:

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

156 lines (132 loc) 6.11 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-Store'>/** </span>@class Siesta.Test.ExtJS.Store This is a mixin, with helper methods for testing functionality relating to Ext.data.Store class. This mixin is being consumed by {@link Siesta.Test.ExtJS} */ Role(&#39;Siesta.Test.ExtJS.Store&#39;, { methods : { <span id='Siesta-Test-ExtJS-Store-method-waitForStoresToLoad'> /** </span> * Waits until all the passed stores have been loaded (fires the &quot;load&quot; event) and calls the provided callback. * * This method accepts either variable number of arguments: * * t.waitForStoresToLoad(store1, store2, function () { ... }) * or array of stores: * * t.waitForStoresToLoad([ store1, store2 ], function () { ... }) * * @param {Ext.data.AbstractStore} store1 The store to load. * @param {Ext.data.AbstractStore} store2 The store to load. * @param {Ext.data.AbstractStore} storeN The store to load. * @param {Function} callback A function to call when the condition has been met. */ waitForStoresToLoad: function () { var Ext = this.getExt(); var args = Array.prototype.concat.apply([], arguments) var me = this; var R = Siesta.Resource(&#39;Siesta.Test.ExtJS.Store&#39;); // Ext 3 var baseStoreCls = Ext.data.AbstractStore || Ext.data.Store; var callback var storesNum; // First locate the callback Joose.A.each(args, function (arg, index) { if (me.typeOf(arg) == &#39;Function&#39;) { callback = arg; storesNum = index; return false; } }); var loaded = 0; var result = me.waitFor({ method : function() { return loaded == storesNum; }, callback : callback, name : &#39;waitForStoresToLoad&#39;, description : storesNum + &#39; &#39; + R.get(&#39;storesToLoad&#39;) }); Joose.A.each(args, function (store) { // Ext 3 // Ext 4 &amp;&amp; ST var proxy = (store.proxy || store.getProxy &amp;&amp; store.getProxy()); if (!(store instanceof baseStoreCls)) { return false; } if (!proxy) { storesNum--; return; } store.on(&#39;load&#39;, function () { loaded++; proxy.un(&#39;exception&#39;, exceptionFailure); }, null, { single : true }); var exceptionFailure = function (proxy, response, operation) { var url = proxy.api &amp;&amp; proxy.api.read || proxy.url me.fail(R.get(&#39;failedToLoadStore&#39;), R.get(&#39;URL&#39;) + &quot;: &quot; + url); }; proxy.on(&#39;exception&#39;, exceptionFailure); }); return result }, <span id='Siesta-Test-ExtJS-Store-method-loadStoresAndThen'> /** </span> * This method is a wrapper around {@link #waitForStoresToLoad} method - it waits for the provided stores to fire the &quot;load&quot; event. * In addition to {@link #waitForStoresToLoad} this method also calls the `load` method of each passed store. * * This method accepts either variable number of arguments: * * t.loadStoresAndThen(store1, store2, function () { ... }) * or array of stores: * * t.loadStoresAndThen([ store1, store2 ], function () { ... }) * * @param {Ext.data.AbstractStore} store1 The store to load. * @param {Ext.data.AbstractStore} store2 The store to load. * @param {Ext.data.AbstractStore} storeN The store to load. * @param {Function} callback A function to call when the condition has been met. */ loadStoresAndThen: function () { var Ext = this.getExt(); this.waitForStoresToLoad.apply(this, arguments); var args = Array.prototype.concat.apply([], arguments) if (this.typeOf(args[ args.length - 1 ]) == &#39;Function&#39;) args.pop() Joose.A.each(args, function (store) { var proxy = (store.proxy || store.getProxy &amp;&amp; store.getProxy()); if (proxy &amp;&amp; store.load) { store.load(); } }); }, <span id='Siesta-Test-ExtJS-Store-method-isStoreEmpty'> /** </span> * Passes if the passed store has no data. * * @param {Ext.data.AbstractStore} store * @param {String} [description] The description of the assertion */ isStoreEmpty : function(store, description) { this.is(store.getCount(), 0, description); } } }); </pre> </body> </html>