gpii-universal
Version:
Cross platform, core components of the GPII personalization infrastructure.
566 lines (547 loc) • 19.9 kB
JavaScript
/**
* GPII PSP Channel Tests
*
* Copyright 2017 Raising the Floor - International
*
* The R&D leading to these results received funding from the
* Department of Education - Grant H421A150005 (GPII-APCP). However,
* these results do not necessarily represent the policy of the
* Department of Education, and you should not assume endorsement by the
* Federal Government.
*
* 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/LICENSE.txt
*/
"use strict";
var fluid = require("infusion"),
jqUnit = fluid.require("node-jqunit", require, "jqUnit"),
gpii = fluid.registerNamespace("gpii");
fluid.require("%gpii-universal");
gpii.loadTestingSupport();
fluid.registerNamespace("gpii.tests.pspChannel");
gpii.tests.pspChannel.payloads = {
"connectWithNoUsers": {
"path": [],
"type": "ADD",
"value": {
"gpiiKey": "noUser",
"activePrefsSetName": "gpii-default",
"settingControls": {},
"preferences": {}
}
},
"logoutUser": {
"path": [],
"value": null,
"type": "DELETE"
},
"snapset_1a_loggedIn": {
"path": [],
"type": "ADD",
"value": {
"gpiiKey": "snapset_1a",
"activePrefsSetName": "gpii-default",
// TODO: Consolidate this kind of "canned" SR data so that we don't have to change schemas more than once.
"settingControls": {
"http://registry\\.gpii\\.net/common/DPIScale": {
"solutionName": "DPI Scale",
"value": 1,
"schema": {
"title": "DPI Scale",
"description": "DPI scale factor on default monitor",
"type": "integer",
"default": 0,
"minimum": -2,
"maximum": 4
},
"liveness": "live"
},
"http://registry\\.gpii\\.net/common/cursorSize": {
"solutionName": "Cursor Size",
"value": 1,
"schema": {
"title": "Cursor Size",
"description": "Cursor size",
"type": "number",
"default": 0.5,
"minimum": 0,
"maximum": 1,
"multipleOf": 0.1
},
"liveness": "liveRestart"
}
},
"preferences": {
"name": "Larger 125%",
"contexts": {
"gpii-default": {
"name": "Default preferences"
}
}
}
}
},
"snapset_2c_loggedIn": {
"path": [],
"type": "ADD",
"value": {
"gpiiKey": "snapset_2c",
"activePrefsSetName": "gpii-default",
// TODO: Consolidate this kind of "canned" SR data so that we don't have to change schemas more than once.
"settingControls": {
"http://registry\\.gpii\\.net/common/cursorSize": {
"solutionName": "Cursor Size",
"value": 1,
"schema": {
"title": "Cursor Size",
"description": "Cursor size",
"type": "number",
"default": 0.5,
"minimum": 0,
"maximum": 1,
"multipleOf": 0.1
},
"liveness": "liveRestart"
},
"http://registry\\.gpii\\.net/common/DPIScale": {
"solutionName": "DPI Scale",
"value": 3,
"schema": {
"title": "DPI Scale",
"description": "DPI scale factor on default monitor",
"type": "integer",
"default": 0,
"minimum": -2,
"maximum": 4
},
"liveness": "live"
},
"http://registry\\.gpii\\.net/common/highContrastTheme": {
"solutionName": "High Contrast theme",
"value": "white-black",
"schema": {
"title": "High Contrast theme",
"description": "High Contrast Theme",
"type": "string",
"default": "black-white",
"enum": [
"regular-contrast",
"black-white",
"white-black",
"yellow-black",
"black-yellow",
"lime-black",
"black-brown",
"grey-black",
"grey-white"
],
"enumLabels": [
"Regular Contrast",
"Black on White",
"White on Black",
"Yellow on Black",
"Black on Yellow",
"Lime on Black",
"Black on Brown",
"Grey on Dark",
"Grey on White"
]
},
"liveness": "live"
}
},
"preferences": {
"name": "Dark & Larger 175%",
"contexts": {
"gpii-default": {
"name": "Default preferences"
}
}
}
}
},
"context1_loggedIn": {
"path": [],
"type": "ADD",
"value": {
"gpiiKey": "context1",
"activePrefsSetName": "gpii-default",
// TODO: Consolidate this kind of "canned" SR data so that we don't have to change schemas more than once.
"settingControls": {
"http://registry\\.gpii\\.net/common/magnification": {
"solutionName": "Magnification",
"value": 1.5,
"schema": {
"title": "Magnification",
"description": "Level of magnification",
"type": "number",
"default": 1,
"minimum": 1,
"multipleOf": 0.1
},
"liveness": "liveRestart"
},
"http://registry\\.gpii\\.net/common/volume": {
"solutionName": "Volume",
"value": 0.5,
"schema": {
"title": "Volume",
"description": "General volume of the operating system",
"type": "number",
"minimum": 0,
"maximum": 1
},
"liveness": "live"
}
},
"preferences": {
"name": "Multiple Contexts",
"contexts": {
"gpii-default": {
"name": "Default preferences"
},
"bright": {
"name": "bright"
},
"noise": {
"name": "noise"
},
"brightandnoise": {
"name": "bright and noise"
}
}
}
}
},
"context1_bright": {
"path": [],
"type": "ADD",
"value": {
"gpiiKey": "context1",
"activePrefsSetName": "bright",
// TODO: Consolidate this kind of "canned" SR data so that we don't have to change schemas more than once.
"settingControls": {
"http://registry\\.gpii\\.net/common/magnification": {
"solutionName": "Magnification",
"value": 2,
"schema": {
"title": "Magnification",
"description": "Level of magnification",
"type": "number",
"default": 1,
"minimum": 1,
"multipleOf": 0.1
},
"liveness": "liveRestart"
}
},
"preferences": {
"name": "Multiple Contexts",
"contexts": {
"gpii-default": {
"name": "Default preferences"
},
"bright": {
"name": "bright"
},
"noise": {
"name": "noise"
},
"brightandnoise": {
"name": "bright and noise"
}
}
}
}
}
};
gpii.tests.pspChannel.connectionSucceeded = function (data) {
jqUnit.assertValue("Connection between client and server can be established", data);
};
gpii.tests.pspChannel.checkPayload = function (data, expected) {
jqUnit.assertDeepEq("Check PSP channel response is as expected", {
"type": "modelChanged",
"payload": gpii.tests.pspChannel.payloads[expected]
}, data);
};
fluid.defaults("gpii.tests.pspChannel.client", {
gradeNames: "kettle.test.request.ws",
path: "/pspChannel",
port: "{configuration}.options.mainServerPort",
events: {
connectionSucceeded: null
},
listeners: {
connectionSucceeded: {
funcName: "gpii.tests.pspChannel.connectionSucceeded",
args: ["{arguments}.0"]
}
}
});
fluid.defaults("gpii.tests.pspChannel.gpiiKeyRequest", {
gradeNames: "kettle.test.request.http",
termMap: {
gpiiKey: "{that}.options.gpiiKeyName"
}
});
fluid.defaults("gpii.tests.pspChannel.loginRequest", {
gradeNames: "gpii.tests.pspChannel.gpiiKeyRequest",
path: "/user/%gpiiKey/login"
});
fluid.defaults("gpii.tests.pspChannel.logoutRequest", {
gradeNames: "gpii.tests.pspChannel.gpiiKeyRequest",
path: "/user/%gpiiKey/logout"
});
gpii.tests.pspChannel.testDef = {
name: "PSP Channel - Basic user login/logout and client connect/disconnect tests",
expect: 10,
config: {
configName: "gpii.config.development.local.mock.windows",
configPath: "%gpii-universal/gpii/configs/mocks"
},
components: {
clientOne: {
type: "gpii.tests.pspChannel.client"
},
clientTwo: {
type: "gpii.tests.pspChannel.client"
},
loginUser1a: {
type: "gpii.tests.pspChannel.loginRequest",
options: {
gpiiKeyName: "snapset_1a"
}
},
loginUser2c: {
type: "gpii.tests.pspChannel.loginRequest",
options: {
gpiiKeyName: "snapset_2c"
}
},
logoutUser1a: {
type: "gpii.tests.pspChannel.logoutRequest",
options: {
gpiiKeyName: "snapset_1a"
}
}
},
sequence: [
{
func: "{clientOne}.connect"
},
{
event: "{clientOne}.events.onConnect",
listener: "gpii.tests.pspChannel.connectionSucceeded"
},
{
event: "{clientOne}.events.onReceiveMessage",
listener: "gpii.tests.pspChannel.checkPayload",
args: ["{arguments}.0", "connectWithNoUsers"]
},
{
func: "{loginUser1a}.send"
},
{
event: "{clientOne}.events.onReceiveMessage",
listener: "gpii.tests.pspChannel.checkPayload",
args: ["{arguments}.0", "logoutUser"]
},
{
event: "{clientOne}.events.onReceiveMessage",
listener: "gpii.tests.pspChannel.checkPayload",
args: ["{arguments}.0", "snapset_1a_loggedIn"]
},
{
func: "{clientOne}.disconnect"
},
{
func: "{clientTwo}.connect"
},
{
event: "{clientTwo}.events.onConnect",
listener: "gpii.tests.pspChannel.connectionSucceeded"
},
{
event: "{clientTwo}.events.onReceiveMessage",
listener: "gpii.tests.pspChannel.checkPayload",
args: ["{arguments}.0", "snapset_1a_loggedIn"]
},
{
func: "{logoutUser1a}.send"
},
{
event: "{clientTwo}.events.onReceiveMessage",
listener: "gpii.tests.pspChannel.checkPayload",
args: ["{arguments}.0", "logoutUser"]
},
{
event: "{clientTwo}.events.onReceiveMessage",
listener: "gpii.tests.pspChannel.checkPayload",
args: ["{arguments}.0", "connectWithNoUsers"]
},
{
func: "{loginUser2c}.send"
},
{
event: "{clientTwo}.events.onReceiveMessage",
listener: "gpii.tests.pspChannel.checkPayload",
args: ["{arguments}.0", "logoutUser"]
},
{
event: "{clientTwo}.events.onReceiveMessage",
listener: "gpii.tests.pspChannel.checkPayload",
args: ["{arguments}.0", "snapset_2c_loggedIn"]
}
]
};
gpii.tests.pspChannel.sendPrefsSetChange = function (client, newPrefsSet) {
client.send({
type: "modelChanged",
value: {
activePrefsSetName: newPrefsSet
}
});
};
gpii.tests.pspChannel.prefsSetTestDef = {
name: "PSP Channel - Test triggering preferences set changes and receiving updates",
expect: 5,
gradeNames: [
"gpii.test.integration.testCaseHolder.windows",
"gpii.test.integration.actionHandlersAware.windows"
],
config: {
configName: "gpii.tests.acceptance.windows.builtIn.config",
configPath: "%gpii-universal/tests/platform/windows/configs"
},
components: {
pspClient: {
type: "gpii.tests.pspChannel.client"
},
loginPrefsSetUser: {
type: "gpii.tests.pspChannel.loginRequest",
options: {
gpiiKeyName: "context1"
}
}
},
sequence: [{
func: "{pspClient}.connect"
}, {
event: "{pspClient}.events.onConnect",
listener: "gpii.tests.pspChannel.connectionSucceeded"
}, {
event: "{pspClient}.events.onReceiveMessage",
listener: "gpii.tests.pspChannel.checkPayload",
args: ["{arguments}.0", "connectWithNoUsers"]
}, {
func: "{loginPrefsSetUser}.send"
}, {
event: "{pspClient}.events.onReceiveMessage",
listener: "gpii.tests.pspChannel.checkPayload",
args: ["{arguments}.0", "logoutUser"]
}, {
event: "{pspClient}.events.onReceiveMessage",
listener: "gpii.tests.pspChannel.checkPayload",
args: ["{arguments}.0", "context1_loggedIn"]
}, {
funcName: "gpii.tests.pspChannel.sendPrefsSetChange",
args: ["{pspClient}", "bright"]
}, {
event: "{pspClient}.events.onReceiveMessage",
listener: "gpii.tests.pspChannel.checkPayload",
args: ["{arguments}.0", "context1_bright"]
}]
};
gpii.test.runCouchTestDefs([
gpii.tests.pspChannel.testDef,
gpii.tests.pspChannel.prefsSetTestDef
]);
jqUnit.test("gpii.pspChannel.getPreferenceInfo() tests", function () {
var schemas = {
"http://registry.gpii.net/common/announceCapitals": {
"$schema": "gss-v7-full#",
"title": "Announce capitals",
"description": "Whether to announce capitals",
"type": "boolean",
"default": false
},
"http://registry.gpii.net/applications/com.microsoft.windows.magnifier": {
"$schema": "gss-v7-full#",
"title": "Windows Built-in Screen Magnifier",
"type": "object",
"properties": {
"Invert": {
"title": "Invert Colours",
"description": "Enable colour inversion for Magnifier",
"enum": [0, 1],
"enumLabels": ["Off", "On"]
}
},
"additionalProperties": false
}
};
var testCases = {
"commonTermPref": {
name: "Process a common term",
prefsKey: "http://registry.gpii.net/common/announceCapitals",
prefsValue: 4,
expected: {
schema: {
"title": "Announce capitals",
"description": "Whether to announce capitals",
"type": "boolean",
"default": false
},
solutionName: "Announce capitals",
presentedCommonTerm: "http://registry.gpii.net/common/announceCapitals",
prefsValue: 4,
prefsKeySegs: ["http://registry.gpii.net/common/announceCapitals"]
}
},
"appTermWithoutSubCommonTerm": {
name: "Process an application specific term without having a common term being a sub-path",
prefsKey: "http://registry.gpii.net/applications/com.microsoft.windows.magnifier",
prefsValue: {
Invert: 0
},
expected: {
schema: {
"title": "Invert Colours",
"description": "Enable colour inversion for Magnifier",
"enum": [0, 1],
"enumLabels": ["Off", "On"]
},
solutionName: "Windows Built-in Screen Magnifier",
presentedCommonTerm: undefined,
prefsValue: 0,
prefsKeySegs: ["http://registry.gpii.net/applications/com.microsoft.windows.magnifier", "Invert"]
}
},
"appTermWithSubCommonTerm": {
name: "Process an application specific term with a common term being a sub-path",
prefsKey: "http://registry.gpii.net/applications/com.microsoft.windows.magnifier",
prefsValue: {
"http://registry.gpii.net/common/announceCapitals": true
},
expected: {
schema: {
"title": "Announce capitals",
"description": "Whether to announce capitals",
"type": "boolean",
"default": false
},
solutionName: "Windows Built-in Screen Magnifier",
presentedCommonTerm: "http://registry.gpii.net/common/announceCapitals",
prefsValue: true,
prefsKeySegs: ["http://registry.gpii.net/applications/com.microsoft.windows.magnifier", "http://registry.gpii.net/common/announceCapitals"]
}
}
};
fluid.each(testCases, function (oneTest) {
var result = gpii.pspChannel.getPreferenceInfo(schemas, oneTest.prefsKey, oneTest.prefsValue);
jqUnit.assertDeepEq("gpii.pspChannel.getPreferenceInfo() test - " + oneTest.name, oneTest.expected, result);
});
});