UNPKG

cabbie-async

Version:
513 lines (386 loc) 17.3 kB
'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); var _regenerator = require('babel-runtime/regenerator'); var _regenerator2 = _interopRequireDefault(_regenerator); var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck'); var _classCallCheck3 = _interopRequireDefault(_classCallCheck2); var _createClass2 = require('babel-runtime/helpers/createClass'); var _createClass3 = _interopRequireDefault(_createClass2); var _mouseButtons = require('./enums/mouse-buttons'); var _mouseButtons2 = _interopRequireDefault(_mouseButtons); var _httpMethod = require('./flow-types/http-method'); var _debug = require('./debug'); var _debug2 = _interopRequireDefault(_debug); var _driver = require('./driver'); var _driver2 = _interopRequireDefault(_driver); var _element = require('./element'); var _element2 = _interopRequireDefault(_element); var _util = require('util'); var _addDebugging = require('./add-debugging'); var _addDebugging2 = _interopRequireDefault(_addDebugging); var _flowRuntime = require('flow-runtime'); var _flowRuntime2 = _interopRequireDefault(_flowRuntime); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } var Element = _flowRuntime2.default.tdz(function () { return _element2.default; }); /* * Mouse commands relative to a DOM-element */ /** * * This file is generated automatically, run npm run build to re-generate. **/ var Driver = _flowRuntime2.default.tdz(function () { return _driver2.default; }); var Debug = _flowRuntime2.default.tdz(function () { return _debug2.default; }); var HttpMethod = _flowRuntime2.default.tdz(function () { return _httpMethod.HttpMethod; }); var MouseButton = _flowRuntime2.default.tdz(function () { return _mouseButtons.MouseButton; }); var Mouse = function () { /* * @private */ function Mouse(driver /*: Driver*/, parent /*: Element*/) { (0, _classCallCheck3.default)(this, Mouse); var _driverType = _flowRuntime2.default.ref(Driver); var _parentType = _flowRuntime2.default.ref(Element); _flowRuntime2.default.param('driver', _driverType).assert(driver); _flowRuntime2.default.param('parent', _parentType).assert(parent); this.driver = driver; this.debug = driver.debug; this._parent = parent; } /* * @private */ /* * @private */ (0, _createClass3.default)(Mouse, [{ key: 'requestJSON', value: function requestJSON(method /*: HttpMethod*/, path /*: string*/, body /*:: ?: Object*/) /*: Promise<any>*/ { var _methodType, _pathType, _bodyType, _returnType; return _regenerator2.default.async(function requestJSON$(_context) { while (1) { switch (_context.prev = _context.next) { case 0: _methodType = _flowRuntime2.default.ref(HttpMethod); _pathType = _flowRuntime2.default.string(); _bodyType = _flowRuntime2.default.object(); _returnType = _flowRuntime2.default.return(_flowRuntime2.default.union(_flowRuntime2.default.any(), _flowRuntime2.default.ref('Promise', _flowRuntime2.default.any()))); _flowRuntime2.default.param('method', _methodType).assert(method); _flowRuntime2.default.param('path', _pathType).assert(path); _flowRuntime2.default.param('body', _bodyType, true).assert(body); _context.t0 = _returnType; _context.next = 10; return _regenerator2.default.awrap(this._parent.requestJSON(method, path, body)); case 10: _context.t1 = _context.sent; return _context.abrupt('return', _context.t0.assert.call(_context.t0, _context.t1)); case 12: case 'end': return _context.stop(); } } }, null, this); } /* * Click any mouse button at the center of the element */ }, { key: 'click', value: function click() /*: Promise<void>*/ { var button /*: MouseButton*/ = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : _mouseButtons2.default.LEFT; var _buttonType, _returnType2; return _regenerator2.default.async(function click$(_context2) { while (1) { switch (_context2.prev = _context2.next) { case 0: _buttonType = _flowRuntime2.default.ref(MouseButton); _returnType2 = _flowRuntime2.default.return(_flowRuntime2.default.union(_flowRuntime2.default.void(), _flowRuntime2.default.ref('Promise', _flowRuntime2.default.void()))); _flowRuntime2.default.param('button', _buttonType).assert(button); if (!(button !== _mouseButtons2.default.LEFT)) { _context2.next = 10; break; } _context2.next = 6; return _regenerator2.default.awrap(this.moveToCenter()); case 6: _context2.next = 8; return _regenerator2.default.awrap(this.driver.activeWindow.mouse.click(button)); case 8: _context2.next = 12; break; case 10: _context2.next = 12; return _regenerator2.default.awrap(this.requestJSON('POST', '/click')); case 12: case 'end': return _context2.stop(); } } }, null, this); } /* * Click any mouse button at a specified offset of the element */ }, { key: 'clickAt', value: function clickAt(xOffset /*: number*/, yOffset /*: number*/) /*: Promise<void>*/ { var button /*: MouseButton*/ = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : _mouseButtons2.default.LEFT; var _xOffsetType, _yOffsetType, _buttonType2, _returnType3; return _regenerator2.default.async(function clickAt$(_context3) { while (1) { switch (_context3.prev = _context3.next) { case 0: _xOffsetType = _flowRuntime2.default.number(); _yOffsetType = _flowRuntime2.default.number(); _buttonType2 = _flowRuntime2.default.ref(MouseButton); _returnType3 = _flowRuntime2.default.return(_flowRuntime2.default.union(_flowRuntime2.default.void(), _flowRuntime2.default.ref('Promise', _flowRuntime2.default.void()))); _flowRuntime2.default.param('xOffset', _xOffsetType).assert(xOffset); _flowRuntime2.default.param('yOffset', _yOffsetType).assert(yOffset); _flowRuntime2.default.param('button', _buttonType2).assert(button); _context3.next = 9; return _regenerator2.default.awrap(this.moveTo(xOffset, yOffset)); case 9: _context3.next = 11; return _regenerator2.default.awrap(this.driver.activeWindow.mouse.click(button)); case 11: case 'end': return _context3.stop(); } } }, null, this); } /* * Move the mouse by an offset of the element */ }, { key: 'moveTo', value: function moveTo(xOffset /*: number*/, yOffset /*: number*/) /*: Promise<void>*/ { var _xOffsetType2, _yOffsetType2, _returnType4; return _regenerator2.default.async(function moveTo$(_context4) { while (1) { switch (_context4.prev = _context4.next) { case 0: _xOffsetType2 = _flowRuntime2.default.number(); _yOffsetType2 = _flowRuntime2.default.number(); _returnType4 = _flowRuntime2.default.return(_flowRuntime2.default.union(_flowRuntime2.default.void(), _flowRuntime2.default.ref('Promise', _flowRuntime2.default.void()))); _flowRuntime2.default.param('xOffset', _xOffsetType2).assert(xOffset); _flowRuntime2.default.param('yOffset', _yOffsetType2).assert(yOffset); _context4.next = 7; return _regenerator2.default.awrap(this.driver.activeWindow.mouse._moveTo(this._parent.elementID, xOffset, yOffset)); case 7: case 'end': return _context4.stop(); } } }, null, this); } /* * Move the mouse to the center of the element */ }, { key: 'moveToCenter', value: function moveToCenter() /*: Promise<void>*/ { var _returnType5; return _regenerator2.default.async(function moveToCenter$(_context5) { while (1) { switch (_context5.prev = _context5.next) { case 0: _returnType5 = _flowRuntime2.default.return(_flowRuntime2.default.union(_flowRuntime2.default.void(), _flowRuntime2.default.ref('Promise', _flowRuntime2.default.void()))); _context5.next = 3; return _regenerator2.default.awrap(this.driver.activeWindow.mouse._moveTo(this._parent.elementID, undefined, undefined)); case 3: case 'end': return _context5.stop(); } } }, null, this); } /* * Double-clicks the element at the center of the element */ }, { key: 'doubleClick', value: function doubleClick() /*: Promise<void>*/ { var _returnType6; return _regenerator2.default.async(function doubleClick$(_context6) { while (1) { switch (_context6.prev = _context6.next) { case 0: _returnType6 = _flowRuntime2.default.return(_flowRuntime2.default.union(_flowRuntime2.default.void(), _flowRuntime2.default.ref('Promise', _flowRuntime2.default.void()))); _context6.next = 3; return _regenerator2.default.awrap(this.moveToCenter()); case 3: _context6.next = 5; return _regenerator2.default.awrap(this.driver.activeWindow.mouse.doubleClick()); case 5: case 'end': return _context6.stop(); } } }, null, this); } /* * Double-clicks the element at a specified offset of the element */ }, { key: 'doubleClickAt', value: function doubleClickAt(xOffset /*: number*/, yOffset /*: number*/) /*: Promise<void>*/ { var _xOffsetType3, _yOffsetType3, _returnType7; return _regenerator2.default.async(function doubleClickAt$(_context7) { while (1) { switch (_context7.prev = _context7.next) { case 0: _xOffsetType3 = _flowRuntime2.default.number(); _yOffsetType3 = _flowRuntime2.default.number(); _returnType7 = _flowRuntime2.default.return(_flowRuntime2.default.union(_flowRuntime2.default.void(), _flowRuntime2.default.ref('Promise', _flowRuntime2.default.void()))); _flowRuntime2.default.param('xOffset', _xOffsetType3).assert(xOffset); _flowRuntime2.default.param('yOffset', _yOffsetType3).assert(yOffset); _context7.next = 7; return _regenerator2.default.awrap(this.moveTo(xOffset, yOffset)); case 7: _context7.next = 9; return _regenerator2.default.awrap(this.driver.activeWindow.mouse.doubleClick()); case 9: case 'end': return _context7.stop(); } } }, null, this); } /* * Click and hold any mouse button at the center of the element */ }, { key: 'buttonDown', value: function buttonDown() /*: Promise<void>*/ { var button /*: MouseButton*/ = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : _mouseButtons2.default.LEFT; var _buttonType3, _returnType8; return _regenerator2.default.async(function buttonDown$(_context8) { while (1) { switch (_context8.prev = _context8.next) { case 0: _buttonType3 = _flowRuntime2.default.ref(MouseButton); _returnType8 = _flowRuntime2.default.return(_flowRuntime2.default.union(_flowRuntime2.default.void(), _flowRuntime2.default.ref('Promise', _flowRuntime2.default.void()))); _flowRuntime2.default.param('button', _buttonType3).assert(button); _context8.next = 5; return _regenerator2.default.awrap(this.moveToCenter()); case 5: _context8.next = 7; return _regenerator2.default.awrap(this.driver.activeWindow.mouse.buttonDown(button)); case 7: case 'end': return _context8.stop(); } } }, null, this); } /* * Click and hold any mouse button at a specified offset of the element */ }, { key: 'buttonDownAt', value: function buttonDownAt(xOffset /*: number*/, yOffset /*: number*/) /*: Promise<void>*/ { var button /*: MouseButton*/ = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : _mouseButtons2.default.LEFT; var _xOffsetType4, _yOffsetType4, _buttonType4, _returnType9; return _regenerator2.default.async(function buttonDownAt$(_context9) { while (1) { switch (_context9.prev = _context9.next) { case 0: _xOffsetType4 = _flowRuntime2.default.number(); _yOffsetType4 = _flowRuntime2.default.number(); _buttonType4 = _flowRuntime2.default.ref(MouseButton); _returnType9 = _flowRuntime2.default.return(_flowRuntime2.default.union(_flowRuntime2.default.void(), _flowRuntime2.default.ref('Promise', _flowRuntime2.default.void()))); _flowRuntime2.default.param('xOffset', _xOffsetType4).assert(xOffset); _flowRuntime2.default.param('yOffset', _yOffsetType4).assert(yOffset); _flowRuntime2.default.param('button', _buttonType4).assert(button); _context9.next = 9; return _regenerator2.default.awrap(this.moveTo(xOffset, yOffset)); case 9: _context9.next = 11; return _regenerator2.default.awrap(this.driver.activeWindow.mouse.buttonDown(button)); case 11: case 'end': return _context9.stop(); } } }, null, this); } /* * Releases a mouse button at the center of the element */ }, { key: 'buttonUp', value: function buttonUp() /*: Promise<void>*/ { var button /*: MouseButton*/ = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : _mouseButtons2.default.LEFT; var _buttonType5, _returnType10; return _regenerator2.default.async(function buttonUp$(_context10) { while (1) { switch (_context10.prev = _context10.next) { case 0: _buttonType5 = _flowRuntime2.default.ref(MouseButton); _returnType10 = _flowRuntime2.default.return(_flowRuntime2.default.union(_flowRuntime2.default.void(), _flowRuntime2.default.ref('Promise', _flowRuntime2.default.void()))); _flowRuntime2.default.param('button', _buttonType5).assert(button); _context10.next = 5; return _regenerator2.default.awrap(this.moveToCenter()); case 5: _context10.next = 7; return _regenerator2.default.awrap(this.driver.activeWindow.mouse.buttonUp(button)); case 7: case 'end': return _context10.stop(); } } }, null, this); } /* * Releases a mouse button at a specified offset of the element */ }, { key: 'buttonUpAt', value: function buttonUpAt(xOffset /*: number*/, yOffset /*: number*/) /*: Promise<void>*/ { var button /*: MouseButton*/ = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : _mouseButtons2.default.LEFT; var _xOffsetType5, _yOffsetType5, _buttonType6, _returnType11; return _regenerator2.default.async(function buttonUpAt$(_context11) { while (1) { switch (_context11.prev = _context11.next) { case 0: _xOffsetType5 = _flowRuntime2.default.number(); _yOffsetType5 = _flowRuntime2.default.number(); _buttonType6 = _flowRuntime2.default.ref(MouseButton); _returnType11 = _flowRuntime2.default.return(_flowRuntime2.default.union(_flowRuntime2.default.void(), _flowRuntime2.default.ref('Promise', _flowRuntime2.default.void()))); _flowRuntime2.default.param('xOffset', _xOffsetType5).assert(xOffset); _flowRuntime2.default.param('yOffset', _yOffsetType5).assert(yOffset); _flowRuntime2.default.param('button', _buttonType6).assert(button); _context11.next = 9; return _regenerator2.default.awrap(this.moveTo(xOffset, yOffset)); case 9: _context11.next = 11; return _regenerator2.default.awrap(this.driver.activeWindow.mouse.buttonUp(button)); case 11: case 'end': return _context11.stop(); } } }, null, this); } }]); return Mouse; }(); (0, _addDebugging2.default)(Mouse, { inspect: function inspect(obj, depth, options) { return obj._parent[_util.inspect.custom || 'inspect'](depth, options) + '.mouse'; } }); exports.default = Mouse;