UNPKG

gpii-universal

Version:

Cross platform, core components of the GPII personalization infrastructure.

239 lines (222 loc) 7.05 kB
/** * GPII Capture Tests * * Copyright 2019 Raising the Floor - International * * Licensed under the New BSD license. You may not use this file except in * compliance with this License. * * You may obtain a copy of the License at * https://github.com/GPII/universal/blob/master/LICENSE.txt */ "use strict"; var fluid = require("infusion"), gpii = fluid.registerNamespace("gpii"), kettle = require("kettle"); var jqUnit = require("node-jqunit"); fluid.require("%gpii-universal"); gpii.loadTestingSupport(); fluid.registerNamespace("gpii.tests.flowManager.capture"); kettle.config.createDefaults({ configName: "gpii.flowManager.tests.capture.fakeData.config", configPath: "%gpii-universal/gpii/node_modules/flowManager/test/configs" }); gpii.tests.flowManager.capture.checkForFakeMags = function (payload) { jqUnit.assertDeepEq("FakeMag1 with multiple settings handlers", { "magnification": 2, "invert": true }, payload.fakemag1); jqUnit.assertDeepEq("FakeMag2 with single settings handler", { "invert": 1, "magnification": 4.5, "location": "topRight" }, payload.fakemag2); }; gpii.tests.flowManager.capture.platformReporter = function () { return { id: "darwin" }; }; gpii.tests.flowManager.capture.checkForInstalledMags = function (payload) { jqUnit.assertEquals("There should be 2 solutions installed", 2, Object.keys(payload).length); jqUnit.assertEquals("Check for Fake Mag 1", "Fake Magnifier 1", payload.fakemag1.name); jqUnit.assertEquals("Check for Fake Mag 2", "Fake Magnifier 2 - fully featured", payload.fakemag2.name); }; /* * A simple resolver config for testing resolver substituion inside of solutions for * capture. This only needs to support a single varialbe in test `PWD` that will be * used to lookup json settings files for the fake magnifier configurations. */ fluid.defaults("gpii.tests.flowManager.capture.standardResolverConfig", { gradeNames: "fluid.component", resolvers: { test: "gpii.tests.flowManager.capture.testResolver" } }); gpii.tests.flowManager.capture.testResolver = function (name) { if (name === "PWD") { return __dirname; } else { return null; } }; fluid.defaults("gpii.tests.flowManager.capture.tests", { gradeNames: ["fluid.test.testEnvironment", "fluid.test.testCaseHolder"], modules: [ { name: "Simple system capture", tests: [{ name: "Check for existing FakeMag Settings", expect: 2, sequence: [{ task: "{config}.server.flowManager.capture.getSystemSettingsCapture", args: [], resolve: "gpii.tests.flowManager.capture.checkForFakeMags", resolveArgs: ["{arguments}.0"] }] }] }, { name: "Simple installed solutions fetch", tests: [{ name: "Testing get installed solutions", expect: 3, sequence: [{ task: "{config}.server.flowManager.capture.getInstalledSolutionsForCurrentDevice", args: [], resolve: "gpii.tests.flowManager.capture.checkForInstalledMags", resolveArgs: ["{arguments}.0"] }] }] } ], components: { "config": { type: "gpii.flowManager.tests.capture.fakeData.config" } } }); fluid.test.runTests([ "gpii.tests.flowManager.capture.tests" ]); /* * Tests for formatting raw captures. */ gpii.tests.flowManager.capture.formatRawCapturedSettingsTestCases = { emptyInput: { message: "Empy Input should produce an empty object", input: [], expected: {} }, allCorrectSettings: { message: "There should be 2 solutions each with 2 settings from the all correct payload", input: [ { "fakemag1": [ { "settings": { "magnification": 3 } } ] }, { "fakemag1": [ { "settings": { "invert": false } } ] }, { "fakemag2": [ { "settings": { "magnification": 2, "invert": true } } ] } ], expected: { "fakemag1": { "magnification": 3, "invert": false }, "fakemag2": { "magnification": 2, "invert": true } } }, someErrorsSettings: { message: "There should still be 2 solutions each with 2 settings from the all payload that contained an error in addition to correct entries.", input: [ { "fakemag1": [ { "settings": { "bouncedelay": 2 } } ] }, { "fakemag1": [ { "settings": { "invert": true } } ] }, { isError: true, msg: "This didn't work properly during capture" }, { "fakemag2": [ { "settings": { "magnification": 5, "invert": false } } ] } ], expected: { "fakemag1": { "bouncedelay": 2, "invert": true }, "fakemag2": { "magnification": 5, "invert": false } } }, allErrorsSettings: { message: "Settings with just errors should yield an empty object", input: [ { isError: true, msg: "This didn't work properly during capture" }, { isError: true, msg: "This is another error apparently" } ], expected: {} } }; jqUnit.test("Test Raw Settings Formatting", function () { fluid.each(gpii.tests.flowManager.capture.formatRawCapturedSettingsTestCases, function (nextTest) { var result = gpii.flowManager.capture.formatRawCapturedSettings(nextTest.input); jqUnit.assertDeepEq(nextTest.message, nextTest.expected, result); }); });