Skip to content
47 changes: 40 additions & 7 deletions gpii/node_modules/deviceReporter/src/DeviceReporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ fluid.defaults("gpii.deviceReporter", {
gradeNames: ["fluid.component"],
components: {
platformReporter: {
type: "gpii.platformReporter.native"
type: "gpii.platformReporter"
}
},
invokers: {
Expand Down Expand Up @@ -149,21 +149,54 @@ gpii.deviceReporter.filterByInstalledSolutions = function (entries, deviceReport
return installedSolutions;
};

fluid.defaults("gpii.platformReporter.native", {
gradeNames: ["fluid.component"],
fluid.defaults("gpii.platformReporter", {
gradeNames: ["fluid.component", "fluid.contextAware"],
contextAwareness: {
platform: {
checks: {
linux: {
contextValue: "{gpii.contexts.linux}",
gradeNames: "gpii.platformReporter.linux"
},
windows: {
contextValue: "{gpii.contexts.windows}",
gradeNames: "gpii.platformReporter.windows"
}
}
}
},
invokers: {
reportPlatform: {
funcName: "gpii.platformReporter.native.reportPlatform"
}
funcName: "gpii.platformReporter.reportAll",
args: ["{that}"]
},
getBasicOS: "gpii.platformReporter.getBasicOS"
}
});

gpii.platformReporter["native"].reportPlatform = function () { // "native" is a reserved word
/**
* Returns the OS name and its version.
*
* @return {Object} - An object consisting of "id" and "version" properties.
*/
gpii.platformReporter.getBasicOS = function () {
return {
// TODO: need to report more details - windowmanager, etc.
id: os.platform(),
// TODO: Need a better strategy - Node semver fails horribly
// in the face of the benign underscore (eg. x86_64).
version: os.release().replace("_", "-")
};
};

/**
* Returns platform information such as OS, OS version, screen resolution
* and so on.
*
* @param {Component} that - A platform reporter instance.
* @return {Object} - An object that has properties describing platform
* features/capabilities; at least basic information such ss
* the version of the OS.
*/
gpii.platformReporter.reportAll = function (that) {
return that.getBasicOS();
};
93 changes: 93 additions & 0 deletions gpii/node_modules/deviceReporter/test/PlatformReporterTests.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
/*
* GPII Web-based PlatformReporter unit tests/
*
* Copyright 2017 Inclusive Design Research Centre, OCAD University
*
* Licensed under the New BSD license. You may not use this file except in
* compliance with this License. You may obtain a copy of the License at
* https://github.com/gpii/universal/LICENSE.txt
*/

/* global require */

"use strict";

var fluid = require("infusion"),
jqUnit = fluid.require("node-jqunit");

require("../index.js");

var gpii = fluid.registerNamespace("gpii");
fluid.registerNamespace("gpii.tests.platformReporter");

fluid.defaults("gpii.tests.platformReporter", {
gradeNames: ["gpii.platformReporter", "gpii.contexts.test"],
invokers: {
reportPlatform: {
funcName: "gpii.tests.platformReporter.reportAll",
args: ["{that}"]
}
}
});

// Mock OS info, e.g., screen resolutions.
gpii.tests.platformReporter.OSinfo = fluid.freezeRecursive({
"screen-resolution": { width: 640, height: 480 },
"available-resolutions": [
{ width: 640, height: 480 },
{ width: 1440, height: 900 },
{ width: 1680, height: 1050 }
]
});

/**
* Return a mock of screen resolutions.
*
* @param {Component} that - A platform reporter instance.
* @return {Object} - Basic OS + current and available screen resolutions.
*/
gpii.tests.platformReporter.reportAll = function (that) {
var allInfo = that.getBasicOS();
return Object.assign(allInfo, gpii.tests.platformReporter.OSinfo);
};

var platformReporter = gpii.tests.platformReporter();

jqUnit.module("Platform Reporter");
jqUnit.test(
"Test getBasicOS()",
function () {
var basicOS = platformReporter.getBasicOS();
jqUnit.assertDeepEq(
"Basic OS informaiton", 2, Object.keys(basicOS).length
);
jqUnit.assertNotNull("ID property", basicOS.id);
jqUnit.assertNotNull("Version property", basicOS.version);
}
);
jqUnit.test(
"Test reportPlatform()",
function () {
var platform = platformReporter.reportPlatform();
jqUnit.assertEquals(
"OS ID",
platformReporter.getBasicOS().id,
platform.id
);
jqUnit.assertEquals(
"OS Version",
platformReporter.getBasicOS().version,
platform.version
);
jqUnit.assertDeepEq(
"Screen resolution",
gpii.tests.platformReporter.OSinfo["screen-resolution"],
platform["screen-resolution"]
);
jqUnit.assertDeepEq(
"Available resolutions",
gpii.tests.platformReporter.OSinfo["available-resolutions"],
platform["available-resolutions"]
);
}
);
27 changes: 27 additions & 0 deletions gpii/node_modules/deviceReporter/test/all-tests.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/**
* GPII Device Reporter Tests
*
* Copyright 2017 Inclusive Design Research Centre, OCAD University
*
* Licensed under the New BSD license. You may not use this file except in
* compliance with this License.
*
* You may obtain a copy of the License at
* https://github.com/gpii/universal/LICENSE.txt
*/
"use strict";

var fluid = require("infusion"),
kettle = fluid.require("kettle");

kettle.loadTestingSupport();

var testIncludes = [
"./PlatformReporterTests.js"
];

var tests = [];

fluid.each(testIncludes, function (path) {
tests = tests.concat(fluid.require(path, require));
});
3 changes: 2 additions & 1 deletion tests/all-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ var testIncludes = [
"../gpii/node_modules/singleInstance/test/SingleInstanceTests.js",
"../gpii/node_modules/solutionsRegistry/test/all-tests.js",
"../gpii/node_modules/transformer/test/TransformerTests.js",
"../gpii/node_modules/userListeners/test/all-tests.js"
"../gpii/node_modules/userListeners/test/all-tests.js",
"../gpii/node_modules/deviceReporter/test/all-tests.js"
];

fluid.each(testIncludes, function (path) {
Expand Down