From a79b4dfa5e3be085bea43129d956035e3ca2bebb Mon Sep 17 00:00:00 2001 From: jahorton Date: Tue, 24 Mar 2020 12:37:00 +0700 Subject: [PATCH] test(web/engine): Adds keystroke-sequence unit test --- web/source/recorder_KeyboardScripts.js | 1 + web/unit_tests/cases/engine.js | 24 ++++++++- .../engine_tests/options_with_save_1.json | 54 +++++++++++++++++++ .../engine_tests/options_with_save_2.json | 38 +++++++++++++ 4 files changed, 116 insertions(+), 1 deletion(-) create mode 100644 web/unit_tests/json/engine_tests/options_with_save_1.json create mode 100644 web/unit_tests/json/engine_tests/options_with_save_2.json diff --git a/web/source/recorder_KeyboardScripts.js b/web/source/recorder_KeyboardScripts.js index 14100c755d..439cc67f50 100644 --- a/web/source/recorder_KeyboardScripts.js +++ b/web/source/recorder_KeyboardScripts.js @@ -5,6 +5,7 @@ function loadKeyboards() { var preloadFiles = [ filePrefix + "khmer_angkor.json", filePrefix + "lao_2008_basic.json", + filePrefix + "options_with_save.json", filePrefix + "test_deadkeys.json", filePrefix + "test_chirality.json" ]; diff --git a/web/unit_tests/cases/engine.js b/web/unit_tests/cases/engine.js index af38b0e83d..563c10a959 100644 --- a/web/unit_tests/cases/engine.js +++ b/web/unit_tests/cases/engine.js @@ -901,7 +901,29 @@ describe('Engine', function() { }, kmwconfig.timeouts.scriptLoad); }); }); - }) + + it("Multiple-sequence check", function(done) { + this.timeout(kmwconfig.timeouts.standard + kmwconfig.timeouts.scriptLoad * 3); + var keyboardID = "options_with_save"; + var storeName = "foo"; + + keyman.setActiveKeyboard(keyboardID, 'en').then(function() { + KeymanWeb.saveStore(storeName, 1); + keyman.removeKeyboards(keyboardID); + + var finalCheck = function() { + // Reset the keyboard... again. + keyman.removeKeyboards(keyboardID); + + // Second test: expects option to still be "off" b/c cookies. + runKeyboardTestFromJSON('/engine_tests/options_with_save_2.json', {usingOSK: false}, done, assert.equal, kmwconfig.timeouts.scriptLoad); + }; + + // First test: expects option to be "on" from cookie-init setting, emitting "foo.", then turning option "off". + runKeyboardTestFromJSON('/engine_tests/options_with_save_1.json', {usingOSK: false}, finalCheck, assert.equal, kmwconfig.timeouts.scriptLoad); + }); + }); + }); // Performs basic processing system checks/tests to ensure the sequence testing // is based on correct assumptions about the code. diff --git a/web/unit_tests/json/engine_tests/options_with_save_1.json b/web/unit_tests/json/engine_tests/options_with_save_1.json new file mode 100644 index 0000000000..c929fc9cfd --- /dev/null +++ b/web/unit_tests/json/engine_tests/options_with_save_1.json @@ -0,0 +1,54 @@ +{ + "keyboard": { + "id": "options_with_save", + "name": "Variable-store test kbd: options_with_save", + "filename": "resources/keyboards/options_with_save.js", + "languages": [ + { + "id": "en", + "name": "English", + "region": "World" + } + ] + }, + "inputTestSets": [ + { + "constraint": { + "target": "hardware", + "validOSList": null, + "validBrowsers": null + }, + "testSet": [ + { + "inputs": [ + { + "type": "key", + "key": "a", + "code": "KeyA", + "keyCode": 65, + "modifierSet": 0, + "location": 0 + }, + { + "type": "key", + "key": "0", + "code": "Digit0", + "keyCode": 48, + "modifierSet": 0, + "location": 0 + }, + { + "type": "key", + "key": "2", + "code": "Digit2", + "keyCode": 50, + "modifierSet": 0, + "location": 0 + } + ], + "output": "foo." + } + ] + } + ] +} \ No newline at end of file diff --git a/web/unit_tests/json/engine_tests/options_with_save_2.json b/web/unit_tests/json/engine_tests/options_with_save_2.json new file mode 100644 index 0000000000..9485aca166 --- /dev/null +++ b/web/unit_tests/json/engine_tests/options_with_save_2.json @@ -0,0 +1,38 @@ +{ + "keyboard": { + "id": "options_with_save", + "name": "Variable-store test kbd: options_with_save", + "filename": "resources/keyboards/options_with_save.js", + "languages": [ + { + "id": "en", + "name": "English", + "region": "World" + } + ] + }, + "inputTestSets": [ + { + "constraint": { + "target": "hardware", + "validOSList": null, + "validBrowsers": null + }, + "testSet": [ + { + "inputs": [ + { + "type": "key", + "key": "a", + "code": "KeyA", + "keyCode": 65, + "modifierSet": 0, + "location": 0 + } + ], + "output": "no foo." + } + ] + } + ] +} \ No newline at end of file