All files / universal/gpii/node_modules/canopyMatchMaker/test/web/js CanopyMatchMakerUtilitiesTests.js

100% Statements 57/57
50% Branches 1/2
100% Functions 13/13
100% Lines 57/57

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304                                            2x 2x   2x   2x                                         2x                           2x                   2x                                   2x                       2x 2x 10x             2x 2x 10x         2x 2x 2x 4x   2x     2x 2x   2x 2x 2x 2x 2x     2x 2x 2x 2x   2x             2x 2x 2x 2x     2x 2x 2x       2x                   2x 2x 2x                           2x 2x   2x 2x 2x       2x       2x                                                                                                                                                             2x 2x   2x 2x 2x                         2x 2x   2x        
/*
 * GPII Canopy MatchMaker Tests
 *
 * Copyright 2012 OCAD University
 * Copyright 2012 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
 */
 
// Declare dependencies
/*global jqUnit, $, require */
 
"use strict";
 
var fluid = fluid || require("infusion");
var gpii = fluid.registerNamespace("gpii");
 
fluid.registerNamespace("gpii.tests.canopyMatchMaker");
 
var magnifier = {
    "settingsHandlers": {
        "myconf": {
            "type": "gpii.integrationTesting.mockSettingsHandler",
            "capabilitiesTransformations": {
                "mag-factor": "display.screenEnhancement.magnification",
                "show-cross-hairs": "display.screenEnhancement.-provisional-showCrosshairs",
                "mouse-tracking": {
                    "transform": {
                        "type": "fluid.transforms.valueMapper",
                        "defaultInputPath": "display.screenEnhancement.tracking",
                        "match": {
                            "mouse": "centered"
                        }
                    }
                }
            }
        }
    }
};
 
var lesserMagnifier = {
    "settingsHandlers": {
        "myconf": {
            "type": "gpii.integrationTesting.mockSettingsHandler",
            "capabilitiesTransformations": {
                "mag-factor": "display.screenEnhancement.magnification"
            }
        },
        "yourconf": {
            "type": "gpii.integrationTesting.mockSettingsHandler"
        }
    }
};
 
var magnifierSkeleton = {
    display: {
        screenEnhancement: {
            magnification: {},
            "-provisional-showCrosshairs": {},
            tracking: {}
        }
    }
};
 
var sammyProfile = {
    "display": {
        "screenEnhancement": {
            "fontSize": 24,
            "foregroundColor": "white",
            "backgroundColor": "black",
            "fontFace": {
                "fontName": ["Comic Sans"],
                "genericFontFace": "sans serif"
            },
            "magnification": 2.0,
            "tracking": ["mouse"],
            "invertImages": true,
            "-provisional-showCrosshairs": true
        }
    }
};
 
var sammyLeaves = [
    "display.screenEnhancement.-provisional-showCrosshairs",
    "display.screenEnhancement.backgroundColor",
    "display.screenEnhancement.fontFace.fontName.0",
    "display.screenEnhancement.fontFace.genericFontFace",
    "display.screenEnhancement.fontSize",
    "display.screenEnhancement.foregroundColor",
    "display.screenEnhancement.invertImages",
    "display.screenEnhancement.magnification",
    "display.screenEnhancement.tracking.0"
];
 
var expandFitness = function (fitnesses) {
    return fluid.transform(fitnesses, function (fit, index) {
        return {
            fitness: fit,
            index: index
        };
    });
};
 
var extractIndices = function (solns) {
    return fluid.transform(solns, function (soln) {
        return soln.index;
    });
};
 
// only used by canopyMatchMaker tests - moved from MatchMakerFramework
gpii.canopyMatchMaker.utils.extractDispositions = function (solrecs) {
    var togo = {};
    fluid.each(solrecs, function (soln) {
        togo[soln.index] = soln.disposition;
    });
    return togo;
};
 
gpii.tests.canopyMatchMaker.runBasicTests = function () {
    jqUnit.module("Utilities");
 
    jqUnit.test("Path Utilities", function () {
        jqUnit.assertEquals("Exact depth", 0, gpii.canopyMatchMaker.utils.prefixLength("display.screenEnhancement.fontSize", sammyProfile));
        jqUnit.assertEquals("Near depth", 0, gpii.canopyMatchMaker.utils.prefixLength("display.screenEnhancement", sammyProfile));
        jqUnit.assertEquals("Mid depth", -1, gpii.canopyMatchMaker.utils.prefixLength("display.unrecognizable", sammyProfile));
        jqUnit.assertEquals("Far depth", -2, gpii.canopyMatchMaker.utils.prefixLength("display.unrecognizable.thing", sammyProfile));
    });
 
    jqUnit.test("Fitness computation", function () {
        var fitness = gpii.canopyMatchMaker.utils.computeFitness(sammyLeaves, magnifierSkeleton, gpii.canopyMatchMaker.utils.prefixLength);
        var expected = [0, 0, -1, -1, -1, -1, -1, -2, -3];
        jqUnit.assertDeepEq("Computed fitness vector", expected, fitness);
 
        var fitnesses = {
            "sol0": [-1, -3, 0],
            "sol1": [0, 0, 0],
            "sol2": [0, 0],
            "sol3": [0, 0, 0, 0],
            "sol4": [-1, -3, -1]
        };
        var solns = gpii.canopyMatchMaker.utils.sortSolutions(expandFitness(fitnesses));
        var indices = extractIndices(solns);
        var expected2 = ["sol3", "sol1", "sol2", "sol0", "sol4"];
        jqUnit.assertDeepEq("Ranked fitnesses", expected2, indices);
    });
 
    jqUnit.module("MatchMaker");
    jqUnit.test("Rank and dispose solutions", function () {
        var solutions = {
            "lesserMag": lesserMagnifier,
            "mag": magnifier
        };
        var capabilities = {
            lesserMag: [
                "display.screenEnhancement.magnification"
            ],
            mag: [
                "display.screenEnhancement.magnification",
                "display.screenEnhancement.-provisional-showCrosshairs",
                "display.screenEnhancement.tracking"
            ]
        };
        var solrecs = gpii.matchMakerFramework.utils.expandSolutions(solutions, capabilities, { "*": "*" });
        var ranked = gpii.canopyMatchMaker.utils.rankSolutions(sammyLeaves, solrecs, gpii.canopyMatchMaker.utils.ISO24751.ontologicalMetric);
        var minimalData = {
            solutionTypes: {
                "lesserMag": "http://registry.gpii.net/common/magnifier",
                "mag": "http://registry.gpii.net/common/magnifier"
            },
            solutionTypeMapping: {
                "http://registry.gpii.net/common/magnifier": [ "lesserMag", "mag" ]
            },
            specialPreferences: {},
            specialCapabilities: {},
            solutionsRegistryEntries: {}
        };
 
        // var indices = extractIndices(ranked);
        var expected = ["mag", "lesserMag"];
        jqUnit.assertDeepEq("Ranked solutions", expected, ranked);
 
        var disposed = gpii.canopyMatchMaker.utils.disposeFromCanopy(sammyLeaves, ranked, solrecs, minimalData, "gpii-default", gpii.canopyMatchMaker.utils.ISO24751.ontologicalMetric);
        var itions = gpii.canopyMatchMaker.utils.extractDispositions(disposed);
        expected = {
            "mag": "accept",
            "lesserMag": "reject"
        };
        jqUnit.assertDeepEq("Disposed solutions", expected, itions);
    });
};
 
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": {
                "solution": {
                    "name": "Test dummy",
                    "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": {
                            "id": {}
                        }
                    },
                    "display": {
                        "screenEnhancement": {
                            "fontSize": {},
                            "magnification": {},
                            "-provisional-magnification/enabled": {}
                        },
                        "screenReader": {
                            "-provisional-screenReaderTTS/enabled": {}
                        }
                    }
                },
                "index": "test.dummy"
            },
            "test.dummy_2": {
                "solution": {
                    "name": "Test dummy 2",
                    "contexts": {},
                    "settingsHandlers": {
                        "myconf": {
                            "type": "gpii.settingsHandlers.noSettings"
                        }
                    }
                },
                "skeleton": {
                    "applications": {
                        "test.dummy_2": {
                            "id": {}
                        }
                    }
                },
                "index": "test.dummy_2"
            }
        },
        expect: {
            "test.dummy_2": {
                disposition: "reject"
            },
            "test.dummy": {
                disposition: "accept"
            }
        }
    }
];
 
gpii.tests.canopyMatchMaker.disposeStrategyTests = function () {
    jqUnit.module("Dispose Strategy Tests");
 
    fluid.each(disposeStrategyFixtures, function (fixture) {
        jqUnit.test(fixture.description, function () {
            var data = {
                solutionTypes: {
                    "test.dummy": "http://registry.gpii.net/common/sometype",
                    "test.dummy_2": "http://registry.gpii.net/common/someOtherType"
                },
                solutionTypeMapping: {
                    "http://registry.gpii.net/common/someType": [ "test.dummy" ],
                    "http://registry.gpii.net/common/someOtherType": [ "test.dummy_2" ]
                },
                specialPreferences: {},
                specialCapabilities: {},
                solutionsRegistryEntries: {}
            };
            var result = gpii.canopyMatchMaker.utils.disposeStrategy(fixture.leavesArg, fixture.solRecsArg, data);
            var expected = $.extend(true, {}, fixture.solRecsArg, fixture.expect);
 
            jqUnit.assertDeepEq(fixture.description, expected, result);
        });
    });
};