From 564df4e68a47abf19d64e251987cf5e09d8f6dce Mon Sep 17 00:00:00 2001 From: jahorton Date: Fri, 1 May 2020 11:07:01 +0700 Subject: [PATCH] feat(web/engine): partial headless chirality check --- .../tests/cases/chirality.js | 57 +++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 common/core/web/keyboard-processor/tests/cases/chirality.js diff --git a/common/core/web/keyboard-processor/tests/cases/chirality.js b/common/core/web/keyboard-processor/tests/cases/chirality.js new file mode 100644 index 0000000000..251ef39d03 --- /dev/null +++ b/common/core/web/keyboard-processor/tests/cases/chirality.js @@ -0,0 +1,57 @@ +var assert = require('chai').assert; +let fs = require('fs'); +let vm = require('vm'); + +let KeyboardProcessor = require('../../dist'); +let KMWRecorder = require('../../../tools/recorder/dist/nodeProctor'); + +// Required initialization setup. +global.com = KeyboardProcessor.com; // exports all keyboard-processor namespacing. + +describe('Engine - Chirality', function() { + let testJSONtext = fs.readFileSync('../tests/resources/json/engine_tests/chirality.json'); + // Common test suite setup. + let testSuite = new KMWRecorder.KeyboardTest(JSON.parse(testJSONtext)); + + var keyboard; + let device = { + formFactor: 'desktop', + OS: 'windows', + browser: 'native' + } + + before(function() { + // -- START: Standard Recorder-based unit test loading boilerplate -- + // Load the keyboard. We'll need a KeyboardProcessor instance as an intermediary. + let kp = new KeyboardProcessor(); + + // These two lines will load a keyboard from its file; headless-mode `registerKeyboard` will + // automatically set the keyboard as active. + var script = new vm.Script(fs.readFileSync('../tests/' + testSuite.keyboard.filename)); + script.runInThisContext(); + + keyboard = kp.activeKeyboard; + assert.equal(keyboard.id, "Keyboard_" + testSuite.keyboard.id); + // -- END: Standard Recorder-based unit test loading boilerplate -- + + // This part provides extra assurance that the keyboard properly loaded. + assert.equal(keyboard.id, "Keyboard_test_chirality"); + }); + + // Converts each test set into its own Mocha-level test. + for(let set of testSuite.inputTestSets) { + let proctor = new KMWRecorder.NodeProctor(keyboard, device, assert.equal); + + if(!proctor.compatibleWithSuite(testSuite)) { + it.skip(set.toTestName() + " - Cannot run this test suite on Node."); + } else if(set.constraint.target == 'hardware') { + it(set.toTestName(), function() { + // Refresh the proctor instance at runtime. + let proctor = new KMWRecorder.NodeProctor(keyboard, device, assert.equal); + set.test(proctor); + }); + } else { + it.skip(set.toTestName() + " - modifier state simulation for OSK not yet supported in headless KeyboardProcessor"); + } + } +}); \ No newline at end of file