gpii-universal
Version:
Cross platform, core components of the GPII personalization infrastructure.
214 lines (195 loc) • 5 kB
JavaScript
/*
* Metrics Tests
*
* Copyright 2017 Raising the Floor - International
*
* Licensed under the New BSD license. You may not use this file except in
* compliance with this License.
*
* 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.
*
* You may obtain a copy of the License at
* https://github.com/GPII/universal/blob/master/LICENSE.txt
*/
"use strict";
var fluid = require("infusion");
var jqUnit = fluid.require("node-jqunit");
var gpii = fluid.registerNamespace("gpii");
fluid.registerNamespace("gpii.tests.metrics");
require("../../lifecycleManager/");
require("../index.js");
var teardowns = [];
jqUnit.module("gpii.tests.metrics", {
teardown: function () {
while (teardowns.length) {
teardowns.pop()();
}
}
});
// Tests ensure preferenceChanged logs added and changed preferences.
gpii.tests.metrics.preferenceChangedTestData = fluid.freezeRecursive({
"unchanged 1/1": {
previous: {
pref1: "value1"
},
current: {
pref1: "value1"
},
expect: []
},
"unchanged 2/2": {
previous: {
pref1: "value1",
pref2: "value2"
},
current: {
pref1: "value1",
pref2: "value2"
},
expect: []
},
"changed 1/1": {
previous: {
pref1: "value1"
},
current: {
pref1: "changed value1"
},
expect: {
name: "pref1",
newValue: "changed value1"
}
},
"changed 2/2": {
previous: {
pref1: "value1",
pref2: "value2"
},
current: {
pref1: "changed value1",
pref2: "changed value2"
},
expect: [{
name: "pref1",
newValue: "changed value1"
}, {
name: "pref2",
newValue: "changed value2"
}]
},
"changed 2/3": {
previous: {
pref1: "value1",
pref2: "value2",
pref3: "value3"
},
current: {
pref1: "changed value1",
pref2: "changed value2",
pref3: "value3"
},
expect: [{
name: "pref1",
newValue: "changed value1"
}, {
name: "pref2",
newValue: "changed value2"
}]
},
"add 1+1": {
previous: {
pref1: "value1"
},
current: {
pref1: "value1",
pref2: "new value2"
},
expect: [{
name: "pref2",
newValue: "new value2"
}]
},
"add+change": {
previous: {
pref1: "value1"
},
current: {
pref1: "changed value1",
pref2: "new value2"
},
expect: [{
name: "pref1",
newValue: "changed value1"
}, {
name: "pref2",
newValue: "new value2"
}]
},
"remove 1-1": {
previous: {
pref1: "value1"
},
current: {
},
expect: []
},
"remove 2-1": {
previous: {
pref1: "value1",
pref2: "value2"
},
current: {
pref2: "value2"
},
expect: []
},
"remove+change+static+add": {
previous: {
pref1: "value1",
pref2: "value2",
pref3: "value3"
},
current: {
pref2: "changed value2",
pref3: "value3",
pref4: "new value4"
},
expect: [{
name: "pref2",
newValue: "changed value2"
}, {
name: "pref4",
newValue: "new value4"
}]
}
});
fluid.defaults("gpii.tests.metricsWrapper", {
gradeNames: ["fluid.component", "gpii.metrics", "gpii.eventLog", "gpii.lifecycleManager"],
listeners: {
"onStartMetrics.application": null,
"onStartMetrics.input": null,
"onStopMetrics.application": null,
"onStopMetrics.input": null
}
});
jqUnit.test("preferenceChanged", function () {
var tests = gpii.tests.metrics.preferenceChangedTestData;
var logValues;
var metrics = gpii.tests.metricsWrapper({
invokers: {
"logMetric": function (metric, data) {
logValues.push(data);
}
}
});
fluid.each(tests, function (test) {
logValues = [];
gpii.metrics.preferenceChanged(metrics, test.current, test.previous);
jqUnit.assertDeepEq("preferenceChanged should have logged the expected value.",
fluid.makeArray(test.expect), logValues);
});
});