All files / universal/gpii/node_modules/matchMakerFramework/test/js MatchMakerUtilitiesDisposeFromPriorityTests.js

80% Statements 28/35
62.5% Branches 5/8
88.89% Functions 8/9
80% Lines 28/35

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                                  2x 2x   2x   2x   2x                                                                                                                                                           2x                                                                       2x 50x           50x                 2x 10x     10x 10x 50x   10x     2x         2x 10x   10x 10x 50x 50x 50x       2x 2x 2x 10x 10x          
/*!
GPII MatchMaker Utilities: Dispose from priority 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
*/
 
/*global jqUnit */
 
var fluid = fluid || require("infusion"),
    gpii = fluid.registerNamespace("gpii");
 
(function () {
    "use strict";
    fluid.registerNamespace("gpii.tests.matchMakerUtilities.disposeFromPriority");
 
    var fullData = {
        solIds: [ "solA", "solB", "solC", "solD", "solE" ],
        solrecs: {
            solA: {
                solution: {},
                skeleton: {},
                index: "solA"
                // priority: 1024
            },
            solB: {
                solution: {},
                skeleton: {},
                index: "solB"
                // priority: 1024
            },
            solC: {
                solution: {},
                skeleton: {},
                index: "solC"
                // priority: 1024
            },
            solD: {
                solution: {},
                skeleton: {},
                index: "solD"
                // priority: 1024
            },
            solE: {
                solution: {},
                skeleton: {},
                index: "solE"
                // priority: 1024
            }
        },
        data: {
            solutionTypes: {
                solA: [
                    "http://registry\\.gpii\\.net/common/magnifierApplication",
                    "http://registry\\.gpii\\.net/common/screenReaderApplication"
                ],
                solB: [
                    "http://registry\\.gpii\\.net/common/magnifierApplication",
                    "http://registry\\.gpii\\.net/common/screenReaderApplication"
                ],
                solC: [
                    "http://registry\\.gpii\\.net/common/screenReaderApplication"
                ],
                solD: [
                    "http://registry\\.gpii\\.net/common/screenReaderApplication"
                ],
                solE: [
                    "http://registry\\.gpii\\.net/common/magnifierApplication"
                ]
            },
            solutionTypeMapping: {
                "http://registry\\.gpii\\.net/common/magnifierApplication": {
                    solA: true,
                    solB: true,
                    solE: true
                },
                "http://registry\\.gpii\\.net/common/screenReaderApplication": {
                    solA: true,
                    solB: true,
                    solC: true,
                    solD: true
                }
            },
            specialCapabilities: {},
            specialPreferences: {},
            solutionsRegistryEntries: {}
        }
    };
 
    // `undefined` disposition means that the solution is either tied with another solution
    // or not present on the device. `true` means that the solution should be configured and
    // launched on startup, and `false` means configured but NOT launched on startup.
    // Decisions are based on priority and solution type - see
    // the data block above.
    var testData = [{
        description: "Tie between highest priority, rest rejected",
        priorities: [2, 2, 1, 1, 1],
        expectedDispositions: [undefined, undefined, false, false, false]
    }, {
        description: "Single highest priority wins, rest rejected",
        priorities: [2, 1, 1, 1, 1],
        expectedDispositions: [true, false, false, false, false]
    }, {
    //     description: "Only solution covering all required solution types selected",
    //     priorities: [2, 1, 2, 1, 1],
    //     expectedDispositions: [true, "reject", "reject", "reject", "reject"]
    // }, {
        description: "Highest priority selected, solution type equivalents remove",
        priorities: [2, 1, 3, 1, 2],
        expectedDispositions: [false, false, true, false, true]
    }, {
        description: "Tie between multiple solutions of different types",
        priorities: [2, 1, 2, 2, 2],
        expectedDispositions: [undefined, false, undefined, undefined, undefined]
    }, {
        description: "Tie between multiple solutions of different types #2",
        priorities: [2, 1, 2, 1, 2],
        expectedDispositions: [undefined, false, undefined, false, undefined]
    // }, {
    //     description: "",
    //     priorities: [1, null, 2, null, null],
    //     expectedDispositions: [true, undefined, "reject", undefined, undefined]
    }];
 
 
    /**
     * Adjusts the 'testData' input object according to the solution and priority given. If priority
     * === null, the solution will be reported as not existing on the system. Else the solution will
     * be reported with the given priority.
     */
    gpii.tests.matchMakerUtilities.disposeFromPriority.setSinglePriority = function (testData, solId, priority) {
        Iif (priority === null) {
            delete testData.solrecs[solId];
            delete testData.data.solutionTypes[solId];
            delete testData.data.solutionTypeMapping["http://registry\\.gpii\\.net/common/magnifierApplication"][solId];
            delete testData.data.solutionTypeMapping["http://registry\\.gpii\\.net/common/screenReaderApplication"][solId];
        } else {
            testData.solrecs[solId].priority = priority;
        }
    };
 
    /**
     * Adjusts the 'testData' input object according to the solution and priority given. If priority
     * === null, the solution will be reported as not existing on the system. Else the solution will
     * be reported with the given priority.
     */
    gpii.tests.matchMakerUtilities.disposeFromPriority.setPriorities = function (priorities) {
        Iif (priorities.length !== fullData.solIds.length) {
            jqUnit.assertTrue("Priorities need to be specified for 5 solutions when testing priority disposition", false);
        }
        var cpy = fluid.copy(fullData);
        for (var i = 0; i < fullData.solIds.length; i++) {
            gpii.tests.matchMakerUtilities.disposeFromPriority.setSinglePriority(cpy, fullData.solIds[i], priorities[i]);
        }
        return cpy;
    };
 
    gpii.tests.matchMakerUtilities.disposeFromPriority.assertSolutionDisposition = function (input, solId, expDisposition) {
        var msg = "Expecting solution " + solId + " to have disposition: " + expDisposition;
        jqUnit.assertEquals(msg, expDisposition, input.solrecs[solId].disposition);
    };
 
    gpii.tests.matchMakerUtilities.disposeFromPriority.singleTest = function (priorities, expectedDispositions) {
        var input = gpii.tests.matchMakerUtilities.disposeFromPriority.setPriorities(priorities);
 
        gpii.matchMakerFramework.utils.disposeFromPriority(input.solrecs, input.data, undefined);
        fluid.each(fullData.solIds, function (solId, index) {
            var msg = "Expecting solution " + solId + " to be: " + expectedDispositions[index];
            var actual = input.solrecs[solId].disposition ? input.solrecs[solId].active : undefined;
            jqUnit.assertEquals(msg, expectedDispositions[index], actual);
        });
    };
 
    gpii.tests.matchMakerUtilities.disposeFromPriority.runTests = function () {
        jqUnit.module("MatchMakerUtilities - disposeFromPriority");
        fluid.each(testData, function (fixture) {
            jqUnit.test(fixture.description, function () {
                gpii.tests.matchMakerUtilities.disposeFromPriority.singleTest(fixture.priorities, fixture.expectedDispositions);
            });
        });
    };
})();