From 90b408eff6c2c169bb88dc1334bbe5c8c9752087 Mon Sep 17 00:00:00 2001 From: Francisco Hodge Date: Thu, 24 Jan 2019 23:03:48 -0500 Subject: [PATCH] Tests update --- src/lib/components/tests/Keyboard.test.js | 42 +++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/src/lib/components/tests/Keyboard.test.js b/src/lib/components/tests/Keyboard.test.js index 33c2e933..62409ec7 100644 --- a/src/lib/components/tests/Keyboard.test.js +++ b/src/lib/components/tests/Keyboard.test.js @@ -947,4 +947,46 @@ it('Keyboard onModulesLoaded will work', () => { }); expect(foo).toBe("bar"); +}); + +it('Keyboard inputPattern will work globally', () => { + testUtil.setDOM(); + + let keyboard = new Keyboard({ + inputPattern: /^\d+$/ + }); + + keyboard.getButtonElement("q").onclick(); + + expect(keyboard.getInput()).toBeFalsy(); + + keyboard.getButtonElement("1").onclick(); + + expect(keyboard.getInput()).toBe("1"); +}); + +it('Keyboard inputPattern will work by input name', () => { + testUtil.setDOM(); + + let keyboard = new Keyboard({ + debug: true, + inputName: "test1", + inputPattern: { + test1: /^\d+$/ + } + }); + + keyboard.getButtonElement("q").onclick(); + keyboard.getButtonElement("1").onclick(); + + expect(keyboard.getInput()).toBe("1"); + + keyboard.setOptions({ + inputName: "default" + }); + + keyboard.getButtonElement("q").onclick(); + keyboard.getButtonElement("1").onclick(); + + expect(keyboard.getInput()).toBe("q1"); }); \ No newline at end of file