UNPKG

siesta-lite

Version:

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

180 lines (146 loc) 5.96 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-Action-Role-HasTarget'>/** </span>@class Siesta.Test.Action.Role.HasTarget This is a mixin, allowing the action to have &quot;target&quot; attribute, also aliased as &quot;el&quot;. Target will be also passed further on chain, as the argument after &quot;next&quot;: t.chain( { action : &#39;click&#39;, target : buttonComp }, function (next, buttonComp) { // target is available as 2nd argument next() }, { action : &#39;click&#39;, target : &#39;&gt;&gt;button&#39;, offset : [10, 20] }, function (next, buttonComp) { // various queries will be resolved down to Ext.Component instance or DOM element next() }, ... ) If needed, this behavior can be disabled with {@link #passTargetToNext} option. */ Role(&#39;Siesta.Test.Action.Role.HasTarget&#39;, { has : { <span id='Siesta-Test-Action-Role-HasTarget-cfg-target'> /** </span> * @cfg {Siesta.Test.ActionTarget/Function} [target=undefined] * * A target for action. See {@link Siesta.Test.ActionTarget} for various values that can be provided. * * **Important.** If the function is provided for this config, it will be called and returning value used as actual target. * This is useful, since sometimes target for the action depends from the previous step and * is not yet available during `t.chain` call. * * For example, you want to click on the button which opens a window and then click on something in the window. Compare: * t.chain( // clicking on button opens the window { action : &#39;click&#39;, target : buttonComp }, // FRAGILE: `windowComp` could not be rendered yet - `buttonComp` is not yet clicked! { action : &#39;click&#39;, target : windowComp.el.down(&#39;.clickArea&#39;) } // MORE ROBUST: taking the &quot;el&quot; right before this action starts { action : &#39;click&#39;, target : function () { return windowComp.el.down(&#39;.clickArea&#39;) } } ) * * Target will be available in the next step as the 2nd argument. See {@link Siesta.Test.Action.Role.HasTarget} * * This config option can also be provided as &quot;el&quot; */ target : { required : false }, normalizedTarget : null, cachedTarget : null, <span id='Siesta-Test-Action-Role-HasTarget-cfg-el'> /** </span> * @cfg {Object} el * * An alias for {@link #target} */ <span id='Siesta-Test-Action-Role-HasTarget-cfg-passTargetToNext'> /** </span> * @cfg {Boolean} passTargetToNext Whether to pass the target further on chain as the first argument */ passTargetToNext : true, <span id='Siesta-Test-Action-Role-HasTarget-cfg-options'> /** </span> * @cfg {Object} options * * Any options that will be used when simulating the event. For information about possible * config options, please see: &lt;https://developer.mozilla.org/en-US/docs/DOM/event.initMouseEvent&gt; */ options : null, <span id='Siesta-Test-Action-Role-HasTarget-cfg-offset'> /** </span> * @cfg {Array} offset * * An offset in X, Y coordinates from the targeted element. The offset can be expressed in 3 different ways. * * - Integers : `[10, 20]` - offset 10px from left, 20px from top * - Percent : `[&quot;10%&quot;, 20]` - offset 10% from left, 20px from top * - Percent + offset : `[&quot;100%-2&quot;, 20]` - offset -2px from right, 20px from top */ offset : null, waitForTarget : true }, after : { initialize : function () { if (!this.passTargetToNext) return var me = this var prevNext = this.next this.next = function () { prevNext.call(this, me.normalizedTarget); } } }, methods : { BUILD : function (config) { // allow &quot;el&quot; as synonym for &quot;target&quot; if (config.el &amp;&amp; !config.target) config.target = config.el return config }, getTarget : function () { if (this.cachedTarget) return this.cachedTarget var test = this.test; var target = this.target || test.getCursorPagePosition() if (test.typeOf(target) === &#39;Function&#39;) target = target.call(test, this); this.normalizedTarget = test.normalizeActionTarget(target, true) return this.cachedTarget = target } } }); </pre> </body> </html>