gpii-universal
Version:
Cross platform, core components of the GPII personalization infrastructure.
413 lines (398 loc) • 18.3 kB
JavaScript
/*
* Flat MatchMaker Tests
*
* Copyright 2014 Raising the Floor - International
*
* 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
*/
/* eslint strict: ["error", "function"] */
// TODO: This should be converted to a set of browser tests
(function () {
"use strict";
var fluid = require("infusion"),
jqUnit = fluid.registerNamespace("jqUnit"),
kettle = require("kettle"),
gpii = fluid.registerNamespace("gpii");
kettle.loadTestingSupport();
require("flatMatchMaker");
require("ontologyHandler"); // TODO: We don't require to depend on the entire ontologyHandler
require("matchMakerFramework");
fluid.defaults("gpii.flatMatchMaker.tests", {
gradeNames: ["fluid.test.testEnvironment"],
components: {
tester: {
type: "gpii.flatMatchMaker.tests.testCaseHolder"
}
}
});
var disposeStrategyFixtures = [
{
description: "Basic test for disposeStrategy function",
leavesArg: [
"display.screenEnhancement.fontSize",
"display.screenEnhancement.magnification",
"display.screenEnhancement.-provisional-magnification/enabled",
"display.screenReader.-provisional-screenReaderTTS/enabled"
],
solRecsArg: {
"test.dummy.matched1": {
"solution": {
"name": "Test dummy - matched1",
"contexts": {},
"settingsHandlers": {
"myconf": {
"type": "gpii.settingsHandlers.JSONSettingsHandler.set",
"options": {
"path": "/some/path/to/file.json"
},
"capabilitiesTransformations": {
"setting1": "http://registry\\.gpii\\.net/common/fontSize",
"setting2.path1": "http://registry\\.gpii\\.net/common/screenReaderTTS/enabled",
"setting2.path2": "http://registry\\.gpii\\.net/common/magnification/enabled",
"setting2.path3.hello": "http://registry\\.gpii\\.net/common/magnification"
}
}
}
},
"skeleton": {
"applications": {
"test.dummy.matched1": {
"id": {}
}
},
"display": {
"screenEnhancement": {
"fontSize": {},
"magnification": {},
"-provisional-magnification/enabled": {}
},
"screenReader": {
"-provisional-screenReaderTTS/enabled": {}
}
}
},
"index": "test.dummy.matched1"
},
"test.dummy.unmatched": {
"solution": {
"name": "Test dummy - unmatched",
"contexts": {},
"settingsHandlers": {
"myconf": {
"type": "gpii.settingsHandlers.noSettings"
}
}
},
"skeleton": {
"applications": {
"test.dummy.unmatched": {
"id": {}
}
}
},
"index": "test.dummy.unmatched"
}
},
solutionTypeMapping: {},
expect: {
"test.dummy.matched1": {
disposition: "accept",
active: true
},
"test.dummy.unmatched": {
disposition: "reject",
active: false
}
}
},
{
description: "Test for disposeStrategy function with the solution type mapping",
leavesArg: [
"display.screenEnhancement.fontSize",
"display.screenEnhancement.magnification",
"display.screenEnhancement.-provisional-magnification/enabled",
"display.screenReader.-provisional-screenReaderTTS/enabled"
],
solRecsArg: {
"test.dummy.matched1": {
"solution": {
"name": "Test dummy - matched1",
"contexts": {},
"settingsHandlers": {
"myconf": {
"type": "gpii.settingsHandlers.JSONSettingsHandler.set",
"options": {
"path": "/some/path/to/file.json"
},
"capabilitiesTransformations": {
"setting1": "http://registry\\.gpii\\.net/common/fontSize",
"setting2.path1": "http://registry\\.gpii\\.net/common/screenReaderTTS/enabled",
"setting2.path2": "http://registry\\.gpii\\.net/common/magnification/enabled",
"setting2.path3.hello": "http://registry\\.gpii\\.net/common/magnification"
}
}
}
},
"skeleton": {
"applications": {
"test.dummy.matched1": {
"id": {}
}
},
"display": {
"screenEnhancement": {
"fontSize": {},
"magnification": {},
"-provisional-magnification/enabled": {}
},
"screenReader": {
"-provisional-screenReaderTTS/enabled": {}
}
}
},
"index": "test.dummy.matched1"
},
"test.dummy.matched2": {
"solution": {
"name": "Test dummy - matched2",
"contexts": {},
"settingsHandlers": {
"myconf": {
"type": "gpii.settingsHandlers.JSONSettingsHandler.set",
"options": {
"path": "/some/path/to/file.json"
},
"capabilitiesTransformations": {
"setting1": "http://registry\\.gpii\\.net/common/fontSize",
"setting2.path1": "http://registry\\.gpii\\.net/common/screenReaderTTS/enabled",
"setting2.path2": "http://registry\\.gpii\\.net/common/magnification/enabled",
"setting2.path3.hello": "http://registry\\.gpii\\.net/common/magnification"
}
}
}
},
"skeleton": {
"applications": {
"test.dummy.matched1": {
"id": {}
}
},
"display": {
"screenEnhancement": {
"fontSize": {},
"magnification": {},
"-provisional-magnification/enabled": {}
},
"screenReader": {
"-provisional-screenReaderTTS/enabled": {}
}
}
},
"index": "test.dummy.matched1"
},
"test.dummy.unmatched": {
"solution": {
"name": "Test dummy - unmatched",
"contexts": {},
"settingsHandlers": {
"myconf": {
"type": "gpii.settingsHandlers.noSettings"
}
}
},
"skeleton": {
"applications": {
"test.dummy.unmatched": {
"id": {}
}
}
},
"index": "test.dummy.unmatched"
}
},
solutionTypeMapping: {
"http://registry\\.gpii\\.net/common/fontSize": {
"test.dummy.matched1": true,
"test.dummy.matched2": true
},
"http://registry\\.gpii\\.net/common/screenReaderTTS/enabled": {
"test.dummy.matched1": true,
"test.dummy.matched2": true
},
"http://registry\\.gpii\\.net/common/magnification/enabled": {
"test.dummy.matched1": true,
"test.dummy.matched2": true
},
"http://registry\\.gpii\\.net/common/magnification": {
"test.dummy.matched1": true,
"test.dummy.matched2": true
}
},
expect: {
"test.dummy.matched1": {
disposition: "accept",
active: true
},
"test.dummy.matched2": {
disposition: "reject",
active: false
},
"test.dummy.unmatched": {
disposition: "reject",
active: false
}
}
}
];
gpii.flatMatchMaker.tests.disposeStrategy = function () {
fluid.each(disposeStrategyFixtures, function (fixture) {
var result = gpii.flatMatchMaker.disposeStrategy(fixture.leavesArg, fixture.solRecsArg, fixture.solutionTypeMapping);
var expected = fluid.extend(true, {}, fixture.solRecsArg, fixture.expect);
jqUnit.assertDeepEq(fixture.description, expected, result);
});
};
var matchFixtures = [
{
description: "Full match call test",
input: require("./data/pre_mm_payload1.json"),
expect: {
"inferredConfiguration": {
"gpii-default": {
"applications": {
"mac.dummy": {
"active": true,
"settings": {
"http://registry.gpii.net/common/fontSize": 16,
"http://registry.gpii.net/common/screenReaderTTS/enabled": false,
"http://registry.gpii.net/common/magnification/enabled": false,
"http://registry.gpii.net/common/magnification": 1
}
}
}
}
}
}
}, {
description: "GPII-3369: the top level high contrast theme is dispatched to both windows and UIO+",
input: require("./data/pre_mm_payload2.json"),
expect: {
"inferredConfiguration": {
"gpii-default": {
"applications": {
"com.microsoft.windows.highContrast": {
"active": true,
"settings": {
"http://registry.gpii.net/common/highContrast/enabled": true,
"http://registry.gpii.net/common/highContrastTheme": "white-black"
}
},
"net.gpii.uioPlus": {
"active": true,
"settings": {
"http://registry.gpii.net/common/highContrast/enabled": true,
"http://registry.gpii.net/common/highContrastTheme": "white-black"
}
}
}
}
}
}
}, {
description: "GPII-3388: Apptology: when there are multiple matched solutions for one solution type, only one is selected",
input: require("./data/pre_mm_payload3.json"),
expect: {
"inferredConfiguration": {
"gpii-default": {
"applications": {
"com.freedomscientific.jaws": {
"active": true,
"settings": {
"http://registry.gpii.net/common/keyEcho": false,
"http://registry.gpii.net/common/wordEcho": true,
"http://registry.gpii.net/common/announceCapitals": true,
"http://registry.gpii.net/common/readingUnit": "word",
"http://registry.gpii.net/common/punctuationVerbosity": "all",
"http://registry.gpii.net/common/screenReaderTTS/enabled": true,
"http://registry.gpii.net/common/speechRate": 400,
"http://registry.gpii.net/common/auditoryOutLanguage": "en-BS",
"http://registry.gpii.net/common/pitch": 0.1
}
}
}
}
}
}
}, {
description: "GPII-3388: Apptology: the specified application is selected for an application specific preference",
input: require("./data/pre_mm_payload4.json"),
expect: {
"inferredConfiguration": {
"gpii-default": {
"applications": {
"org.nvda-project": {
"active": true,
"settings": {
"http://registry.gpii.net/applications/org.nvda-project": {
"speech.synth": "espeak",
"speech.outputDevice": "Microsoft Sound Mapper",
"speech.symbolLevel": 300,
"speech.espeak.rate": 40,
"speech.espeak.voice": "en-us",
"speech.espeak.pitch": 60,
"speech.espeak.volume": 80,
"reviewCursor.followFocus": "False",
"reviewCursor.followCaret": "True",
"reviewCursor.followMouse": "True",
"keyboard.speakTypedWords": "True",
"speech.espeak.rateBoost": "True",
"keyboard.speakTypedCharacters": "False",
"presentation.reportHelpBalloons": "False",
"speech.espeak.sayCapForCapitals": "True",
"virtualBuffers.autoSayAllOnPageLoad": "False"
}
}
}
}
}
}
}
}
];
gpii.flatMatchMaker.tests.match = function (ontologyHandler) {
fluid.each(matchFixtures, function (fixture) {
fixture.input = gpii.matchMakerFramework.utils.preProcess(fixture.input);
var result = gpii.flatMatchMaker.match(ontologyHandler, fixture.input, gpii.flatMatchMaker.disposeStrategy);
jqUnit.assertDeepEq(fixture.description, fixture.expect, result);
});
};
fluid.defaults("gpii.flatMatchMaker.tests.testCaseHolder", {
gradeNames: ["fluid.test.testCaseHolder"],
components: {
"ontologyHandler": {
type: "gpii.ontologyHandler"
}
},
modules: [{
name: "flatMatchMakerTests",
tests: [{
expect: 2,
name: "gpii.flatMatchMaker.disposeStrategy tests",
func: "gpii.flatMatchMaker.tests.disposeStrategy"
}, {
expect: 4,
name: "gpii.flatMatchMaker.match tests",
func: "gpii.flatMatchMaker.tests.match",
args: "{ontologyHandler}"
}]
}]
});
module.exports = kettle.test.bootstrap("gpii.flatMatchMaker.tests");
})();