UNPKG

gpii-universal

Version:

Cross platform, core components of the GPII personalization infrastructure.

567 lines (538 loc) 25.8 kB
/*! GPII Lifecycle Manager Tests Copyright 2019 OCAD University Licensed under the New BSD license. You may not use this file except in compliance with this License. The research leading to these results has received funding from the European Union's Seventh Framework Programme (FP7/2007-2013) under grant agreement no. 289016. You may obtain a copy of the License at https://github.com/GPII/universal/blob/master/LICENSE.txt */ "use strict"; var fluid = fluid || require("infusion"), gpii = fluid.registerNamespace("gpii"), jqUnit = jqUnit || fluid.require("node-jqunit", require, "jqUnit"); fluid.registerNamespace("gpii.tests.lifecycleManager"); gpii.tests.lifecycleManager.solutionRegistryEntries = { magnifier: { "settingsHandlers": { "configuration": { "type": "gpii.gsettings", "liveness": "live", "options": { "schema": "org.gnome.desktop.a11y.magnifier" }, "capabilitiesTransformations": { "mag-factor": "http://registry\\.gpii\\.net/common/magnification", "show-cross-hairs": "http://registry\\.gpii\\.net/common/showCrosshairs", "transform": { "type": "fluid.transforms.arrayToSetMembership", "inputPath": "http://registry\\.gpii\\.net/common/tracking", "outputPath": "", "presentValue": "proportional", "missingValue": "none", "options": { "focus": "focus-tracking", "caret": "caret-tracking", "mouse": "mouse-tracking" } }, "screen-position": { "transform": { "type": "fluid.transforms.valueMapper", "defaultInputPath": "http://registry\\.gpii\\.net/common/magnifierPosition", "match": { "FullScreen": "full-screen", "Lens": "full-screen", "LeftHalf": "left-half", "RightHalf": "right-half", "TopHalf": "top-half", "BottomHalf": "bottom-half" }, "noMatch": { "outputValue": "full-screen" } } } }, "inverseCapabilitiesTransformations": { "http://registry\\.gpii\\.net/common/magnification": "mag-factor", "http://registry\\.gpii\\.net/common/showCrosshairs": "show-cross-hairs", "transform": [ { "type": "fluid.transforms.valueMapper", "defaultInputPath": "screen-position", "defaultOutputPath": "http://registry\\.gpii\\.net/common/magnifierPosition", "match": { "full-screen": "FullScreen", "left-half": "LeftHalf", "right-half": "RightHalf", "top-half": "TopHalf", "bottom-half": "BottomHalf" } }, { "type": "fluid.transforms.valueMapper", "defaultOutputPath": "http://registry\\.gpii\\.net/common/tracking", "defaultInputPath": "mouse-tracking", "match": { "centered": "mouse" } } ] } } } }, alsa: { "name": "ALSA System Volume", "settingsHandlers": { "configuration": { "type": "gpii.alsa", "liveness": "live", "supportedSettings": { "masterVolume": { } }, "capabilitiesTransformations": { "masterVolume": { "transform": { "type": "fluid.transforms.linearScale", "inputPath": "http://registry\\.gpii\\.net/common/volume", "factor": 100 } } }, "settings": { "masterVolume": 10 } } }, "isInstalled": [ { "type": "gpii.packageKit.find", "name": "alsa" }, { "type": "gpii.packageKit.find", "name": "alsa-lib" } ], "active": true }, office: { "settingsHandlers": { "configure.ribbons": { "type": "gpii.settingsHandlers.remoteFileSettingsHandler", "liveness": "live", "options": { "settings": { "word-ribbon": { "path": "${{environment}.LOCALAPPDATA}\\Microsoft\\Office\\Word.officeUI", "url": "https://raw.githubusercontent.com/GPII/gpii-assets/master/dataBlocks/officeRibbon/Word%20%value.xml", "cache": true }, "excel-ribbon": { "path": "${{environment}.LOCALAPPDATA}\\Microsoft\\Office\\Excel.officeUI", "url": "https://raw.githubusercontent.com/GPII/gpii-assets/master/dataBlocks/officeRibbon/Excel%20%value.xml", "cache": true } } }, "capabilitiesTransformations": { "word-ribbon": "http://registry\\.gpii\\.net/applications/com\\.microsoft\\.office.word-ribbon", "excel-ribbon": "http://registry\\.gpii\\.net/applications/com\\.microsoft\\.office.excel-ribbon" } } } } }; jqUnit.test("Test gpii.lifecycleManager.transformSettingsToPrefs() to transform settings to preferences", function () { jqUnit.expect(3); var testCases = { flat: { message: "Transform a setting to a flat preference", settings: { "org.gnome.desktop.a11y.magnifier": { "mag-factor": 2 } }, solutionRegistryEntries: { "org.gnome.desktop.a11y.magnifier": gpii.tests.lifecycleManager.solutionRegistryEntries.magnifier }, expected: { "http://registry.gpii.net/common/magnification": 2 } }, nested: { message: "Transform a setting to a nested preferences", settings: { "com.microsoft.office": { "word-ribbon": "StandardSet" } }, solutionRegistryEntries: { "com.microsoft.office": gpii.tests.lifecycleManager.solutionRegistryEntries.office }, expected: { "http://registry.gpii.net/applications/com.microsoft.office": { "word-ribbon": "StandardSet" } } }, multiple: { message: "Transform settings for multiple solutions to a multiple preferences", settings: { "org.gnome.desktop.a11y.magnifier": { "mag-factor": 1.5, "screen-position": undefined }, "org.alsa-project": { "masterVolume": 50 } }, solutionRegistryEntries: { "org.gnome.desktop.a11y.magnifier": gpii.tests.lifecycleManager.solutionRegistryEntries.magnifier, "org.alsa-project": gpii.tests.lifecycleManager.solutionRegistryEntries.alsa }, expected: { "http://registry.gpii.net/common/magnification": 1.5, "http://registry.gpii.net/common/volume": 0.5 } } }; fluid.each(testCases, function (testCase) { var result = gpii.lifecycleManager.transformSettingsToPrefs(testCase.settings, testCase.solutionRegistryEntries); jqUnit.assertDeepEq(testCase.message, testCase.expected, result); }); jqUnit.test("Test gpii.lifecycleManager.getMatchMakerSettings() to find the settings that generated from a matchmaking process ", function () { jqUnit.expect(2); var testCases = { common: { message: "Match for one solution", settingValues: [{ "org.gnome.desktop.a11y.magnifier": [ { "settings": { "mag-factor": 2, "show-cross-hairs": false, "focus-tracking": false, "caret-tracking": false, "mouse-tracking": false, "screen-position": "full-screen" } } ] }], matchMakerSolutionRegistryEntries: { "org.gnome.desktop.a11y.magnifier": { "name": "GNOME Shell Magnifier", "capabilities": [ "http://registry\\.gpii\\.net/common/magnification/enabled" ], "settingsHandlers": { "configuration": { "type": "gpii.gsettings", "liveness": "live", "options": { "schema": "org.gnome.desktop.a11y.magnifier" }, "supportedSettings": { "mag-factor": { }, "show-cross-hairs": { }, "focus-tracking": { }, "caret-tracking": { }, "mouse-tracking": { }, "screen-position": { } }, "inverseCapabilitiesTransformations": { "http://registry\\.gpii\\.net/common/magnification": "mag-factor", "http://registry\\.gpii\\.net/common/showCrosshairs": "show-cross-hairs", "transform": [ { "type": "fluid.transforms.valueMapper", "defaultInputPath": "screen-position", "defaultOutputPath": "http://registry\\.gpii\\.net/common/magnifierPosition", "match": { "full-screen": "FullScreen", "left-half": "LeftHalf", "right-half": "RightHalf", "top-half": "TopHalf", "bottom-half": "BottomHalf" } }, { "type": "fluid.transforms.valueMapper", "defaultOutputPath": "http://registry\\.gpii\\.net/common/tracking", "defaultInputPath": "mouse-tracking", "match": { "centered": "mouse" } } ] }, "settings": { "mag-factor": 1, "screen-position": "full-screen" } } }, "launchHandlers": { "launcher": { "type": "gpii.gsettings.launch", "options": { "schema": "org.gnome.desktop.a11y.applications", "key": "screen-magnifier-enabled" }, "settings": { "running": true } } }, "update": [ "settings.configuration" ], "isInstalled": [ { "type": "gpii.packageKit.find", "name": "gnome-shell" } ], "active": true } }, expected: { "org.gnome.desktop.a11y.magnifier": { "mag-factor": 2, "screen-position": "full-screen" } } }, multiple: { message: "Get settings for multiple solutions", settingValues: [{ "org.gnome.desktop.a11y.magnifier": [{ "settings": { "mag-factor": 1.5, "show-cross-hairs": undefined, "focus-tracking": undefined, "caret-tracking": undefined, "mouse-tracking": undefined, "screen-position": undefined } }] }, { "org.alsa-project": [{ "settings": { "masterVolume": 50 } }] }], matchMakerSolutionRegistryEntries: { "org.gnome.desktop.a11y.magnifier": { "name": "GNOME Shell Magnifier", "capabilities": [ "http://registry\\.gpii\\.net/common/magnification/enabled" ], "settingsHandlers": { "configuration": { "type": "gpii.gsettings", "liveness": "live", "options": { "schema": "org.gnome.desktop.a11y.magnifier" }, "supportedSettings": { "mag-factor": { }, "show-cross-hairs": { }, "focus-tracking": { }, "caret-tracking": { }, "mouse-tracking": { }, "screen-position": { } }, "capabilitiesTransformations": { "mag-factor": "http://registry\\.gpii\\.net/common/magnification", "show-cross-hairs": "http://registry\\.gpii\\.net/common/showCrosshairs", "transform": { "type": "fluid.transforms.arrayToSetMembership", "inputPath": "http://registry\\.gpii\\.net/common/tracking", "outputPath": "", "presentValue": "proportional", "missingValue": "none", "options": { "focus": "focus-tracking", "caret": "caret-tracking", "mouse": "mouse-tracking" } }, "screen-position": { "transform": { "type": "fluid.transforms.valueMapper", "defaultInputPath": "http://registry\\.gpii\\.net/common/magnifierPosition", "match": { "FullScreen": "full-screen", "Lens": "full-screen", "LeftHalf": "left-half", "RightHalf": "right-half", "TopHalf": "top-half", "BottomHalf": "bottom-half" }, "noMatch": { "outputValue": "full-screen" } } } }, "inverseCapabilitiesTransformations": { "http://registry\\.gpii\\.net/common/magnification": "mag-factor", "http://registry\\.gpii\\.net/common/showCrosshairs": "show-cross-hairs", "transform": [ { "type": "fluid.transforms.valueMapper", "defaultInputPath": "screen-position", "defaultOutputPath": "http://registry\\.gpii\\.net/common/magnifierPosition", "match": { "full-screen": "FullScreen", "left-half": "LeftHalf", "right-half": "RightHalf", "top-half": "TopHalf", "bottom-half": "BottomHalf" } }, { "type": "fluid.transforms.valueMapper", "defaultOutputPath": "http://registry\\.gpii\\.net/common/tracking", "defaultInputPath": "mouse-tracking", "match": { "centered": "mouse" } } ] }, "settings": { "mag-factor": 1, "screen-position": "full-screen" } } }, "launchHandlers": { "launcher": { "type": "gpii.gsettings.launch", "options": { "schema": "org.gnome.desktop.a11y.applications", "key": "screen-magnifier-enabled" }, "settings": { "running": true } } }, "update": [ "settings.configuration" ], "isInstalled": [ { "type": "gpii.packageKit.find", "name": "gnome-shell" } ], "active": true }, "org.alsa-project": { "name": "ALSA System Volume", "settingsHandlers": { "configuration": { "type": "gpii.alsa", "liveness": "live", "supportedSettings": { "masterVolume": { } }, "capabilitiesTransformations": { "masterVolume": { "transform": { "type": "fluid.transforms.linearScale", "inputPath": "http://registry\\.gpii\\.net/common/volume", "factor": 100 } } }, "settings": { "masterVolume": 10 } } }, "isInstalled": [ { "type": "gpii.packageKit.find", "name": "alsa" }, { "type": "gpii.packageKit.find", "name": "alsa-lib" } ], "active": true } }, expected: { "org.gnome.desktop.a11y.magnifier": { "mag-factor": 1.5, "screen-position": undefined }, "org.alsa-project": { "masterVolume": 50 } } } }; fluid.each(testCases, function (testCase) { var result = gpii.lifecycleManager.getMatchMakerSettings(testCase.settingValues, testCase.matchMakerSolutionRegistryEntries); jqUnit.assertDeepEq(testCase.message, testCase.expected, result); }); }); jqUnit.test("Test gpii.lifecycleManager.filterMatchedPrefs() to find matched preferences", function () { jqUnit.expect(1); var testCases = { common: { message: "Find matched preferences", preferences: { "http://registry.gpii.net/applications/com.microsoft.office": { "word-ribbon": "StandardSet", "excel-ribbon": "Basics+StandardSet" }, "http://registry.gpii.net/common/magnification": 2, "http://registry.gpii.net/common/volume": 1.5 }, prefsSearchFor: { "http://registry.gpii.net/applications/com.microsoft.office": { "word-ribbon": "StandardSet" }, "http://registry.gpii.net/common/magnification": 1, "http://registry.gpii.net/common/nonexistent": true }, expected: { "http://registry.gpii.net/applications/com.microsoft.office": { "word-ribbon": "StandardSet" }, "http://registry.gpii.net/common/magnification": 2 } } }; fluid.each(testCases, function (testCase) { var result = gpii.lifecycleManager.filterMatchedPrefs(testCase.preferences, testCase.prefsSearchFor); jqUnit.assertDeepEq(testCase.message, testCase.expected, result); }); }); });