diff --git a/src/demo/tests/MultipleKeyboardsDestroyDemo.test.js b/src/demo/tests/MultipleKeyboardsDestroyDemo.test.js new file mode 100644 index 00000000..e376ccc1 --- /dev/null +++ b/src/demo/tests/MultipleKeyboardsDestroyDemo.test.js @@ -0,0 +1,67 @@ +import TestUtility from '../../utils/TestUtility'; +import MultipleKeyboardsDestroyDemo from '../MultipleKeyboardsDestroyDemo'; + +let testUtil = new TestUtility(); + +it('Demo will load', () => { + testUtil.setDOM(); + + let demo = new MultipleKeyboardsDestroyDemo(); +}); + +it('Demo onDOMLoaded will work', () => { + testUtil.setDOM(); + + let demo = new MultipleKeyboardsDestroyDemo(); + + expect(demo.keyboard).toBeTruthy(); +}); + +it('Demo onChange will work', () => { + testUtil.setDOM(); + + let demo = new MultipleKeyboardsDestroyDemo(); + + demo.onChange("test"); + demo.keyboard2.getButtonElement("q").click(); + + expect(document.body.querySelector('.input').value).toBe("test"); + expect(document.body.querySelector('.input2').value).toBe("q"); +}); + +it('Demo onChange will work', () => { + testUtil.setDOM(); + + let demo = new MultipleKeyboardsDestroyDemo(); + + demo.keyboard.getButtonElement("q").onclick(); + + expect(document.body.querySelector('.input').value).toBe("q"); +}); + +it('Demo input change will work', () => { + testUtil.setDOM(); + + let demo = new MultipleKeyboardsDestroyDemo(); + + document.body.querySelector('.input').value = "test"; + document.body.querySelector('.input').dispatchEvent(new Event('input')); + + document.body.querySelector('.input2').value = "test2"; + document.body.querySelector('.input2').dispatchEvent(new Event('input')); + + expect(demo.keyboard.getInput()).toBe("test"); + expect(demo.keyboard2.getInput()).toBe("test2"); +}); + +it('Demo handleShiftButton will work', () => { + testUtil.setDOM(); + + let demo = new MultipleKeyboardsDestroyDemo(); + + demo.keyboard.getButtonElement("{shift}")[0].onclick(); + expect(demo.keyboard.options.layoutName).toBe("shift"); + + demo.keyboard.getButtonElement("{shift}")[0].onclick(); + expect(demo.keyboard.options.layoutName).toBe("default"); +}); \ No newline at end of file diff --git a/src/lib/components/tests/Keyboard.test.js b/src/lib/components/tests/Keyboard.test.js index e8112d58..ca763774 100644 --- a/src/lib/components/tests/Keyboard.test.js +++ b/src/lib/components/tests/Keyboard.test.js @@ -1228,10 +1228,16 @@ it('Keyboard destroy will work', () => { testUtil.setDOM(); let keyboard = new Keyboard(); - keyboard.destroy(); + expect(keyboard.keyboardDOM).toBe(null); +}); - expect(keyboard.keyboardDOM.innerHTML).toBeFalsy(); +it('Keyboard destroy will work with debug option', () => { + testUtil.setDOM(); + + let keyboard = new Keyboard({ debug: true }); + keyboard.destroy(); + expect(keyboard.keyboardDOM).toBe(null); }); it('Keyboard disableButtonHold will work', () => { @@ -1325,4 +1331,10 @@ it('Keyboard buttonAttribute will warn about invalid entries', () => { } ] }); -}); \ No newline at end of file +}); + +it('Keyboard recurseButtons will not work without a valid param', () => { + testUtil.setDOM(); + let keyboard = new Keyboard(); + expect(keyboard.recurseButtons()).toBe(false); +});