SyncInstanceInputs caret position and tests improvements. Fixes #65

This commit is contained in:
Francisco Hodge 2019-04-27 14:31:26 -04:00
parent 049900b49a
commit 1b55cbe774
2 changed files with 21 additions and 5 deletions

View File

@ -296,6 +296,7 @@ class SimpleKeyboard {
syncInstanceInputs() { syncInstanceInputs() {
this.dispatch(instance => { this.dispatch(instance => {
instance.replaceInput(this.input); instance.replaceInput(this.input);
instance.caretPosition = this.caretPosition;
}); });
} }
@ -354,11 +355,6 @@ class SimpleKeyboard {
*/ */
replaceInput(inputObj) { replaceInput(inputObj) {
this.input = inputObj; this.input = inputObj;
/**
* Reset caretPosition
*/
this.caretPosition = null;
} }
/** /**

View File

@ -168,6 +168,26 @@ it('Keyboard syncInstanceInputs will work', () => {
keyboard1.getButtonElement("q").onclick(); keyboard1.getButtonElement("q").onclick();
expect(keyboard2.getInput()).toBe("q"); expect(keyboard2.getInput()).toBe("q");
/**
* Test cursor syncing...
* Reinit keyboards
*/
keyboard1 = new Keyboard(".keyboard1", sharedOptions);
keyboard2 = new Keyboard(".keyboard2", sharedOptions);
keyboard1.getButtonElement("1").onclick();
keyboard1.getButtonElement("5").onclick();
keyboard1.getButtonElement("6").onclick();
keyboard1.caretPosition = 1;
keyboard1.getButtonElement("2").onclick();
keyboard1.getButtonElement("3").onclick();
keyboard1.getButtonElement("4").onclick();
expect(keyboard1.getInput()).toBe("123456");
expect(keyboard2.getInput()).toBe("123456");
}); });
it('Keyboard onChange will work', () => { it('Keyboard onChange will work', () => {