all files / spiSettingsHandler/test/ testSpiSettingsHandler.js

100% Statements 36/36
100% Branches 2/2
100% Functions 10/10
100% Lines 36/36
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                                                        10×   10×   10× 10×   10×   10×   10×   23×   23× 23×                                                      
/*!
 Windows SystemParametersInfo Settings Handler
 
 Copyright 2012 Antranig Basman
 Copyright 2012 Astea Solutions AD
 
 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 = require("universal"),
    jqUnit = fluid.require("node-jqunit"),
    gpii = fluid.registerNamespace("gpii"),
    $ = fluid.registerNamespace("jQuery");
 
require("../src/SpiSettingsHandler.js");
 
jqUnit.module("SpiSettingsHandler Module");
 
var testPayloads = ["testMouseTrails", "testFilterKeys", "testMouse", "testMouseClickLock", "testLogFont",
    "testNonClientMetrics", "testStickyKeys", "testHighContrast", "testHighContrastToEmpty", "testMouseKeys"];
 
fluid.each(testPayloads, function (name) {
 
    jqUnit.asyncTest("SpiSettingsHandler test - " + name, function () {
 
        var payload = require(__dirname + "/" + name);
 
        var expectedSettings = payload.settings;
        var expectedCount = 1 + fluid.keys(expectedSettings).length;
 
        jqUnit.expect(expectedCount);
 
        var oldSettings = gpii.windows.spi.getImpl(payload);
 
        return gpii.windows.spi.setImpl(payload)
            .then(function (newSettings) {
                for (var currentSetting in expectedSettings) {
                    var expected = expectedSettings[currentSetting];
 
                    jqUnit.assertDeepEq("Assert " + name + ": " + currentSetting, expected, newSettings[currentSetting].newValue);
                    payload.settings[currentSetting].value = oldSettings[currentSetting].value;
                }
 
                gpii.windows.spi.setImpl(payload).then(function () {
                    jqUnit.assertDeepEq(name + " restored", oldSettings, gpii.windows.spi.getImpl(payload));
                    jqUnit.start();
                });
            }, function (reason) {
                jqUnit.fail(reason && reason.message);
                jqUnit.start();
            });
    });
});
 
jqUnit.asyncTest("SpiSettingsHandler API test - ", function () {
    var testData = require(__dirname + "/testAPI.json");
 
    jqUnit.expect(2);
 
    var oldSettings = gpii.resolveSync(gpii.windows.spiSettingsHandler.get(testData.set.payload));
 
    // Set the initial settings to a known state
    var work = [];
    fluid.each(testData.init, function (initPayload) {
        work.push(function () {
            return gpii.windows.spi.setImpl(initPayload);
        });
    });
 
    fluid.promise.sequence(work)
        .then(function () {
            // Test get functionality:
            var result = gpii.windows.spiSettingsHandler.get(testData.get.payload);
            jqUnit.assertDeepEq("Checking that GET returns the correct payload", testData.get.expectedResult, gpii.resolveSync(result));
 
            // Test set functionality:
            gpii.windows.spiSettingsHandler.set(testData.set.payload)
                .then(function (result2) {
                    jqUnit.assertDeepEq("Checking that SET returns the correct payload", testData.set.expectedResult, result2);
 
                    // Restore original settings
                    gpii.windows.spiSettingsHandler.set($.extend(true, {}, testData.set.payload, oldSettings));
 
                    jqUnit.start();
                });
        });
});