From 2926b554a247f4802666ab1c11da6e0bdc94a9f4 Mon Sep 17 00:00:00 2001 From: Francisco Hodge Date: Thu, 18 Apr 2019 10:13:09 -0400 Subject: [PATCH] Tests update --- src/lib/components/tests/Keyboard.test.js | 35 ++++++++++++++++++++--- 1 file changed, 31 insertions(+), 4 deletions(-) diff --git a/src/lib/components/tests/Keyboard.test.js b/src/lib/components/tests/Keyboard.test.js index 4718902e..e7a367fc 100644 --- a/src/lib/components/tests/Keyboard.test.js +++ b/src/lib/components/tests/Keyboard.test.js @@ -178,7 +178,8 @@ it('Keyboard onChange will work', () => { let keyboard = new Keyboard({ onChange: (input) => { output = input; - } + }, + useMouseEvents: true }); keyboard.getButtonElement("q").onclick(); @@ -194,7 +195,8 @@ it('Keyboard onChangeAll will work', () => { let keyboard = new Keyboard({ onChangeAll: (input) => { output = input ? input.default : null; - } + }, + useMouseEvents: true }); keyboard.getButtonElement("q").onclick(); @@ -959,7 +961,8 @@ it('Keyboard inputPattern will work globally', () => { testUtil.setDOM(); let keyboard = new Keyboard({ - inputPattern: /^\d+$/ + inputPattern: /^\d+$/, + useMouseEvents: true }); keyboard.getButtonElement("q").onclick(); @@ -979,7 +982,8 @@ it('Keyboard inputPattern will work by input name', () => { inputName: "test1", inputPattern: { test1: /^\d+$/ - } + }, + useMouseEvents: true }); keyboard.getButtonElement("q").onclick(); @@ -1175,4 +1179,27 @@ it('Keyboard disableRowButtonContainers will bypass parseRowDOMContainers', () = let containers = Array.from(document.querySelectorAll(".hg-button-container")); expect(containers.length).toBe(0); +}); + +it('Keyboard inputName change will trigget caretPosition reset', () => { + testUtil.setDOM(); + + let keyboard = new Keyboard(); + + keyboard.caretPosition = 0; + + keyboard.getButtonElement("q").onpointerdown(); + keyboard.getButtonElement("1").onpointerdown(); + + expect(keyboard.caretPosition).toBe(2); + + keyboard.setOptions({ + inputName: "myInput" + }); + + keyboard.getButtonElement("q").onpointerdown(); + keyboard.getButtonElement("1").onpointerdown(); + keyboard.getButtonElement("b").onpointerdown(); + + expect(keyboard.caretPosition).toBe(null); }); \ No newline at end of file