From 60c5d96037b4316f95dc7c41f8711404bcefa8f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rodrigo=20Ram=C3=ADrez=20Norambuena?= Date: Mon, 27 Mar 2017 12:18:36 -0300 Subject: [PATCH 1/5] fix documentation currentweather and weatherforecast function roundValue: This function toFixed return a string type not a number value. --- modules/default/currentweather/currentweather.js | 2 +- modules/default/weatherforecast/weatherforecast.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/default/currentweather/currentweather.js b/modules/default/currentweather/currentweather.js index 1b55e255..e2ca15b5 100644 --- a/modules/default/currentweather/currentweather.js +++ b/modules/default/currentweather/currentweather.js @@ -443,7 +443,7 @@ Module.register("currentweather",{ * * argument temperature number - Temperature. * - * return number - Rounded Temperature. + * return string - Rounded Temperature. */ roundValue: function(temperature) { var decimals = this.config.roundTemp ? 0 : 1; diff --git a/modules/default/weatherforecast/weatherforecast.js b/modules/default/weatherforecast/weatherforecast.js index b269a44a..faed2c9f 100644 --- a/modules/default/weatherforecast/weatherforecast.js +++ b/modules/default/weatherforecast/weatherforecast.js @@ -356,7 +356,7 @@ Module.register("weatherforecast",{ * * argument temperature number - Temperature. * - * return number - Rounded Temperature. + * return string - Rounded Temperature. */ roundValue: function(temperature) { var decimals = this.config.roundTemp ? 0 : 1; From 181cb235dfb1638bbe74ae4a9bceabd9fbc34ccc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rodrigo=20Ram=C3=ADrez=20Norambuena?= Date: Mon, 27 Mar 2017 14:01:30 -0300 Subject: [PATCH 2/5] Unit test currentweather module: Add roundValue unit test function currentweather module tests for this.config.roundTemp is true --- tests/unit/functions/currentweather_spec.js | 45 +++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 tests/unit/functions/currentweather_spec.js diff --git a/tests/unit/functions/currentweather_spec.js b/tests/unit/functions/currentweather_spec.js new file mode 100644 index 00000000..6252777d --- /dev/null +++ b/tests/unit/functions/currentweather_spec.js @@ -0,0 +1,45 @@ +var fs = require("fs"); +var path = require("path"); +var chai = require("chai"); +var expect = chai.expect; +var vm = require("vm"); + + +describe("Functions module currentweather", function() { + + // Fake for use by calendar.js + Module = {} + Module.definitions = {}; + Module.register = function (name, moduleDefinition) { + Module.definitions[name] = moduleDefinition; + }; + config = {}; + + describe("roundValue", function() { + describe("this.config.roundTemp is true", function() { + // load currentweather + require("../../../modules/default/currentweather/currentweather.js"); + + Module.definitions.currentweather.config = {}; + Module.definitions.currentweather.config.roundTemp = true; + + var values = [ + // index 0 value + // index 1 expect + [1 , "1"], + [1.0 , "1"], + [1.02 , "1"], + [10.12 , "10"], + [2.0 , "2"], + ["2.12" , "2"], + [10.1 , "10"] + ] + + values.forEach(value => { + it(`for ${value[0]} should be return ${value[1]}`, function() { + expect(Module.definitions.currentweather.roundValue(value[0])).to.equal(value[1]); + }); + }); + }); + }); +}); From af9fdfa224d28ecbf958221b720cb3fe5979f8e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rodrigo=20Ram=C3=ADrez=20Norambuena?= Date: Tue, 28 Mar 2017 22:15:48 -0300 Subject: [PATCH 3/5] Add roundValue unit test function currentweather module: - tests for this.config.roundTemp is false --- tests/unit/functions/currentweather_spec.js | 53 ++++++++++++++++----- 1 file changed, 41 insertions(+), 12 deletions(-) diff --git a/tests/unit/functions/currentweather_spec.js b/tests/unit/functions/currentweather_spec.js index 6252777d..8744fce2 100644 --- a/tests/unit/functions/currentweather_spec.js +++ b/tests/unit/functions/currentweather_spec.js @@ -7,21 +7,23 @@ var vm = require("vm"); describe("Functions module currentweather", function() { - // Fake for use by calendar.js - Module = {} - Module.definitions = {}; - Module.register = function (name, moduleDefinition) { - Module.definitions[name] = moduleDefinition; - }; - config = {}; + before(function(){ + Module = {}; + config = {}; + Module.definitions = {}; + Module.register = function (name, moduleDefinition) { + Module.definitions[name] = moduleDefinition; + }; + require("../../../modules/default/currentweather/currentweather.js"); + Module.definitions.currentweather.config = {}; + }); describe("roundValue", function() { - describe("this.config.roundTemp is true", function() { - // load currentweather - require("../../../modules/default/currentweather/currentweather.js"); - Module.definitions.currentweather.config = {}; - Module.definitions.currentweather.config.roundTemp = true; + describe("this.config.roundTemp is true", function() { + before(function(){ + Module.definitions.currentweather.config.roundTemp = true; + }); var values = [ // index 0 value @@ -41,5 +43,32 @@ describe("Functions module currentweather", function() { }); }); }); + + + describe("this.config.roundTemp is false", function() { + + before(function(){ + Module.definitions.currentweather.config.roundTemp = false; + }); + + var values = [ + // index 0 value + // index 1 expect + [1 , "1.0"], + [1.0 , "1.0"], + [1.02 , "1.0"], + [10.12 , "10.1"], + [2.0 , "2.0"], + ["2.12" , "2.1"], + [10.1 , "10.1"], + [10.10 , "10.1"] + ] + + values.forEach(value => { + it(`for ${value[0]} should be return ${value[1]}`, function() { + expect(Module.definitions.currentweather.roundValue(value[0])).to.equal(value[1]); + }); + }); + }); }); }); From 7fc82ccead6debd1df6fd73fa8b299aa83323359 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rodrigo=20Ram=C3=ADrez=20Norambuena?= Date: Mon, 7 Aug 2017 20:42:32 -0400 Subject: [PATCH 4/5] Update Changelog for unit tests for currentweather module --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5f762dbe..34cd778d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ This project adheres to [Semantic Versioning](http://semver.org/). - Add `.vscode/` folder to `.gitignore` to keep custom Visual Studio Code config out of git. - Add unit test the capitalizeFirstLetter function of newfeed module. - Add new unit tests for function `shorten` in calendar module. +- Add unit tests for function `roundValue` in currentweather module. ### Updated - Changed 'default.js' - listen on all attached interfaces by default. From 739fb99cedef43bb30b978f2f559c0c02ad0c228 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rodrigo=20Ram=C3=ADrez=20Norambuena?= Date: Sun, 6 Aug 2017 07:53:03 -0400 Subject: [PATCH 5/5] Resolved conflict unit tests between currentweather and newsfeed. --- tests/unit/functions/currentweather_spec.js | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/tests/unit/functions/currentweather_spec.js b/tests/unit/functions/currentweather_spec.js index 8744fce2..18b52c81 100644 --- a/tests/unit/functions/currentweather_spec.js +++ b/tests/unit/functions/currentweather_spec.js @@ -7,13 +7,17 @@ var vm = require("vm"); describe("Functions module currentweather", function() { + + // Fake for use by currentweather.js + Module = {}; + config = {}; + Module.definitions = {}; + Module.register = function (name, moduleDefinition) { + Module.definitions[name] = moduleDefinition; + }; + + before(function(){ - Module = {}; - config = {}; - Module.definitions = {}; - Module.register = function (name, moduleDefinition) { - Module.definitions[name] = moduleDefinition; - }; require("../../../modules/default/currentweather/currentweather.js"); Module.definitions.currentweather.config = {}; });