Skip to content

Instantly share code, notes, and snippets.

@y2468101216
Created December 29, 2015 03:21
Show Gist options
  • Save y2468101216/0f301d4533c4f8ba0325 to your computer and use it in GitHub Desktop.
Save y2468101216/0f301d4533c4f8ba0325 to your computer and use it in GitHub Desktop.
var readline = require('readline');
var rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
var readlineClass = function () {
this.monkKeyboard = function (robot,importString) {
rl.on('pause', function () {
Console.log('Readline pause');
robot.typeString(importString);
robot.keyTap("enter");
});
}
this.enterPackagePackageNumber = function (callback) {
rl.question("請輸入補充包或者預組編號:", function (answer) {
// TODO: Log the answer in a database
callback(answer);
rl.close();
});
}
}
module.exports = readlineClass;
var assert = require('assert');
var robot = require('robotjs');
var readline = require(__dirname + '/../../../bin/parse/readlineClass.js');
var readlineTest = new readline();
describe('readlineSyncTest', function () {
it('enterPackagePackageNumber', function (done) {
readlineTest.monkKeyboard(robot, 'S05');
readlineTest.enterPackagePackageNumber(function(actual){
assert.equal(actual, 'S05');
done()
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment