UNPKG

gpii-universal

Version:

Cross platform, core components of the GPII personalization infrastructure.

219 lines (204 loc) 6.2 kB
/*! GPII Settings Transformer Tests Copyright 2012 OCAD University Copyright 2013 Raising the Floor 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 */ var fluid = fluid || require("infusion"), jqUnit = fluid.registerNamespace("jqUnit"), gpii = fluid.registerNamespace("gpii"); (function () { "use strict"; fluid.registerNamespace("gpii.tests.ontologyHandlerUtilities"); var full = { simple: { a: { b: 1, c: 2 } }, medium: { a: { a1: { a11: 14 }, a2: { a21: [ "a", "b" ] } } }, complex: { a: 12, b: {}, c: { c1: [ { hello: "world" } ] } } }; var testFixtures = [ { description: "Very simple non-nested removal of single key", full: full.simple, remove: { a: { b: 3 } }, expected: { a: { c: 2 } } }, { description: "simple value filtering", full: full.medium, remove: { a: { a1: { a11: 12 } } }, expected: { a: { a2: { a21: [ "a", "b" ] } } } }, { description: "Higher hierarchy filtering", full: full.medium, remove: { a: 13 }, expected: {} }, { description: "Filtering simple array value", full: full.medium, remove: { a: { a2: { a21: [ "a" ] } } }, expected: { a: { a1: { a11: 14 } } } }, { description: "filtering complementary objects", full: full.medium, remove: { b: 12 }, expected: full.medium }, { description: "removing multiple keys", full: full.complex, remove: { a: 15, c: 18 }, expected: { b: {} } }, { description: "Removing all keys", full: full.complex, remove: { a: { a1: "hello" }, b: "stupid", c: "cat" }, expected: {} }, { description: "empty object passed as 'full' parameter", full: {}, remove: { a: 15 }, expected: {} }, { description: "empty object passed as 'remove' parameter", full: { a: 15 }, remove: {}, expected: { a: 15 } } ]; gpii.tests.ontologyHandlerUtilities.applicationTransformTests = [ { name: "ISOtoFlat", input: { "applications": { "org.alsa-project": { "id": "org.alsa-project", "parameters": { "masterVolume": 14 } } } }, rules: { "": { "transform": { "type": "gpii.ontologyHandler.transforms.applicationISOToFlat", "inputPath": "applications", "outputPath": "" } } }, expected: { "http://registry.gpii.net/applications/org.alsa-project": { "masterVolume": 14 } }, invertedRules: { transform: [ { "type": "gpii.ontologyHandler.transforms.applicationFlatToISO", "inputPath": "", "outputPath": "applications" } ] } } ]; gpii.tests.ontologyHandlerUtilities.runTests = function () { jqUnit.test("ontologyServer.filter", function () { fluid.each(testFixtures, function (test) { var result = gpii.ontologyHandler.utils.filterPrefs(test.full, test.remove); jqUnit.assertDeepEq(test.description, test.expected, result); }); }); jqUnit.test("Testing Application Transformats; applicationFlatToISO and applicationISOToFlat", function () { fluid.each(gpii.tests.ontologyHandlerUtilities.applicationTransformTests, function (test) { var transformed = fluid.model.transform(test.input, test.rules); jqUnit.assertDeepEq(test.name, test.expected, transformed); var inverseRules = fluid.model.transform.invertConfiguration(test.rules); jqUnit.assertDeepEq("Rules inversion for " + test.name, test.invertedRules, inverseRules); var doubleTransformed = fluid.model.transform(transformed, inverseRules); jqUnit.assertDeepEq(test.name, test.input, doubleTransformed); }); } ); }; })();