Skip to content

Commit

Permalink
refactor: CORE-9977 - update input to allow for array of steps
Browse files Browse the repository at this point in the history
  • Loading branch information
Judy Lin authored and Zac Bowhay committed Nov 21, 2024
1 parent 3ec6a9c commit 3a782c3
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/corellium.js
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ class Corellium {
* @param {string} instanceId
* @returns {Promise<Instance>}
* @example
* await corellium.instance('aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa')
* await corellium.getInstance('aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa')
*/
async getInstance (instanceId) {
let lastError
Expand Down
7 changes: 5 additions & 2 deletions src/instance.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const { sleep } = require('./util/sleep')
const util = require('util')
const fs = require('fs')
const { compress, uploadFile } = require('./images')
const { Input } = require('./input')
const { v4: uuidv4 } = require('uuid')
const split = require('split')

Expand Down Expand Up @@ -594,13 +595,15 @@ class Instance extends EventEmitter {

/**
* Send an input to this instance.
* @param {Input} input - The input to send.
* @param {Input | Array<Record<string, unknown>>} input - The input(s) to send.
* @see Input
* @example
* await instance.sendInput(I.pressRelease('home'));
* @example
* await instance.sendInput([{ "text": "Hello, world" }]);
*/
async sendInput (input) {
await this._fetch('/input', { method: 'POST', json: input.points })
await this._fetch('/input', { method: 'POST', json: input instanceof Input ? input.points : input })
}

/**
Expand Down
10 changes: 9 additions & 1 deletion test/integration-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -489,12 +489,20 @@ describe('Corellium API', function () {
})
})

it('can send input', async function () {
it('can send input as an instance of Input', async function () {
const input = new Input()
const instance = instanceMap.get(instanceVersion)
instance.sendInput(input.pressRelease('home'))
})

it('can send input as an array of steps', async function () {
const instance = instanceMap.get(instanceVersion)
instance.sendInput([
{ buttons: ['finger'], position: [[300, 600]], wait: 0 },
{ buttons: [], wait: 100 }
])
})

if (CONFIGURATION.testFlavor === 'ranchu') {
// Peripherals/sensor are only supported for android currently
describe(`peripherals ${instanceVersion}`, function () {
Expand Down

0 comments on commit 3a782c3

Please sign in to comment.