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 1/2] 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 2/2] 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]);
+ });
+ });
+ });
});
});