UNPKG

siesta-lite

Version:

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

133 lines (108 loc) 4.77 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-MoveCursor'>/** </span> @class Siesta.Test.Action.MoveCursor @extends Siesta.Test.Action @mixin Siesta.Test.Action.Role.HasTarget This action can be included in the `t.chain` call with &quot;moveCursor&quot; shortcut: t.chain( { action : &#39;moveCursor&#39;, to : &#39;div.someClass&#39; // A div with class=&#39;someClass&#39; }, { action : &#39;moveCursor&#39;, to : [400, 300] // Target pixel coordinates }, { action : &#39;moveCursor&#39;, by : [20, 10] // 20 px right, 10 px down } ) This action will perform a {@link Siesta.Test.Simulate.Mouse#moveCursorTo moveCursorTo} to the provided &#39;to&#39; destination or the relative &#39;by&#39; offset. */ Class(&#39;Siesta.Test.Action.MoveCursor&#39;, { isa : Siesta.Test.Action, has : { requiredTestMethod : &#39;moveMouseTo&#39;, <span id='Siesta-Test-Action-MoveCursor-cfg-to'> /** </span> * @cfg {Siesta.Test.ActionTarget/Function} to * * The target point the cursor should be moved to. Can be provided as a DOM element, an array with client coordinates: `[ x, y ]`, or a function * returning one of those. You can additionally pass an &#39;offset&#39; array to click at a point relative to the XY position of the target. * * Exactly one of the `to` and `by` configuration options should be provided for this action. */ to : null, <span id='Siesta-Test-Action-MoveCursor-cfg-by'> /** </span> * @cfg {Array/Function} by * * The delta for moving cursor. Should be provided as the array with delta value for each coordinate: `[ dX, dY ]` or the function returning such. * * Exactly one of the `to` and `by` configuration options should be provided for this action. */ by : null, <span id='Siesta-Test-Action-MoveCursor-cfg-offset'> /** </span> * @cfg {Array} offset * * An offset in X, Y coordinates from the targeted element (only applicable when using the &#39;to&#39; target option. */ offset : null }, methods : { getTo : function () { if (this.test.typeOf(this.to) == &#39;Function&#39;) return this.to.call(this.test, this) else return this.to }, getBy : function () { if (this.test.typeOf(this.by) == &#39;Function&#39;) return this.by.call(this.test, this) else return this.by }, process : function () { var test = this.test; var next = this.next; if (this.to) { var to = this.getTo() var normalizedTarget = test.normalizeActionTarget(to, false) test.moveMouseTo(to, function() { next(normalizedTarget); }, null, this.offset) } else { var by = this.getBy() var currentXY = test.getCursorPagePosition() var normalizedTarget = test.normalizeActionTarget([ currentXY[ 0 ] + by[ 0 ], currentXY[ 1 ] + by[ 1 ] ]); test.moveMouseBy(by, function() { next(normalizedTarget); }) } } } }); Siesta.Test.ActionRegistry().registerAction(&#39;moveCursor&#39;, Siesta.Test.Action.MoveCursor) Siesta.Test.ActionRegistry().registerAction(&#39;moveMouse&#39;, Siesta.Test.Action.MoveCursor) Siesta.Test.ActionRegistry().registerAction(&#39;moveFinger&#39;, Siesta.Test.Action.MoveCursor) </pre> </body> </html>