mirror of
https://github.com/MichMich/MagicMirror.git
synced 2025-08-21 12:55:22 +00:00
Fix date test.
This commit is contained in:
@@ -40,7 +40,8 @@ Module.register("compliments", {
|
|||||||
morningEndTime: 12,
|
morningEndTime: 12,
|
||||||
afternoonStartTime: 12,
|
afternoonStartTime: 12,
|
||||||
afternoonEndTime: 17,
|
afternoonEndTime: 17,
|
||||||
random: true
|
random: true,
|
||||||
|
mockDate: null
|
||||||
},
|
},
|
||||||
lastIndexUsed:-1,
|
lastIndexUsed:-1,
|
||||||
// Set currentweather from module
|
// Set currentweather from module
|
||||||
@@ -105,7 +106,7 @@ Module.register("compliments", {
|
|||||||
*/
|
*/
|
||||||
complimentArray: function() {
|
complimentArray: function() {
|
||||||
var hour = moment().hour();
|
var hour = moment().hour();
|
||||||
var date = moment().format("YYYY-MM-DD");
|
var date = this.config.mockDate ? this.config.mockDate : moment().format("YYYY-MM-DD");
|
||||||
var compliments;
|
var compliments;
|
||||||
|
|
||||||
if (hour >= this.config.morningStartTime && hour < this.config.morningEndTime && this.config.compliments.hasOwnProperty("morning")) {
|
if (hour >= this.config.morningStartTime && hour < this.config.morningEndTime && this.config.compliments.hasOwnProperty("morning")) {
|
||||||
|
@@ -23,6 +23,7 @@ let config = {
|
|||||||
module: "compliments",
|
module: "compliments",
|
||||||
position: "middle_center",
|
position: "middle_center",
|
||||||
config: {
|
config: {
|
||||||
|
mockDate: "2020-01-01",
|
||||||
compliments: {
|
compliments: {
|
||||||
morning: [],
|
morning: [],
|
||||||
afternoon: [],
|
afternoon: [],
|
||||||
|
@@ -1,6 +1,5 @@
|
|||||||
const helpers = require("../global-setup");
|
const helpers = require("../global-setup");
|
||||||
const expect = require("chai").expect;
|
const expect = require("chai").expect;
|
||||||
const MockDate = require("./mocks/date.js");
|
|
||||||
|
|
||||||
const describe = global.describe;
|
const describe = global.describe;
|
||||||
const it = global.it;
|
const it = global.it;
|
||||||
@@ -96,7 +95,6 @@ describe("Compliments module", function() {
|
|||||||
before(function() {
|
before(function() {
|
||||||
// Set config sample for use in test
|
// Set config sample for use in test
|
||||||
process.env.MM_CONFIG_FILE = "tests/configs/modules/compliments/compliments_date.js";
|
process.env.MM_CONFIG_FILE = "tests/configs/modules/compliments/compliments_date.js";
|
||||||
MockDate.set("2000-01-01");
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Show happy new year compliment on new years day", function() {
|
it("Show happy new year compliment on new years day", function() {
|
||||||
@@ -104,10 +102,6 @@ describe("Compliments module", function() {
|
|||||||
expect(text).to.be.oneOf(["Happy new year!"]);
|
expect(text).to.be.oneOf(["Happy new year!"]);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
after(function() {
|
|
||||||
MockDate.reset();
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@@ -1,93 +0,0 @@
|
|||||||
/**
|
|
||||||
* MockDate
|
|
||||||
*
|
|
||||||
* By Bob Lauer (https://github.com/boblauer/MockDate
|
|
||||||
* MIT Licensed.
|
|
||||||
*/
|
|
||||||
|
|
||||||
(function(name, definition) {
|
|
||||||
if (typeof module !== "undefined") {module.exports = definition();}
|
|
||||||
else if (typeof define === "function" && typeof define.amd === "object") {define(definition);}
|
|
||||||
else {this[name] = definition();}
|
|
||||||
}("MockDate", function() {
|
|
||||||
"use strict";
|
|
||||||
|
|
||||||
var _Date = Date
|
|
||||||
, _getTimezoneOffset = Date.prototype.getTimezoneOffset
|
|
||||||
, now = null
|
|
||||||
;
|
|
||||||
|
|
||||||
function MockDate(y, m, d, h, M, s, ms) {
|
|
||||||
var date;
|
|
||||||
|
|
||||||
switch (arguments.length) {
|
|
||||||
|
|
||||||
case 0:
|
|
||||||
if (now !== null) {
|
|
||||||
date = new _Date(now);
|
|
||||||
} else {
|
|
||||||
date = new _Date();
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 1:
|
|
||||||
date = new _Date(y);
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
d = typeof d === "undefined" ? 1 : d;
|
|
||||||
h = h || 0;
|
|
||||||
M = M || 0;
|
|
||||||
s = s || 0;
|
|
||||||
ms = ms || 0;
|
|
||||||
date = new _Date(y, m, d, h, M, s, ms);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
return date;
|
|
||||||
}
|
|
||||||
|
|
||||||
MockDate.UTC = _Date.UTC;
|
|
||||||
|
|
||||||
MockDate.now = function() {
|
|
||||||
return new MockDate().valueOf();
|
|
||||||
};
|
|
||||||
|
|
||||||
MockDate.parse = function(dateString) {
|
|
||||||
return _Date.parse(dateString);
|
|
||||||
};
|
|
||||||
|
|
||||||
MockDate.toString = function() {
|
|
||||||
return _Date.toString();
|
|
||||||
};
|
|
||||||
|
|
||||||
MockDate.prototype = _Date.prototype;
|
|
||||||
|
|
||||||
function set(date, timezoneOffset) {
|
|
||||||
var dateObj = new Date(date);
|
|
||||||
if (isNaN(dateObj.getTime())) {
|
|
||||||
throw new TypeError("mockdate: The time set is an invalid date: " + date);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (typeof timezoneOffset === "number") {
|
|
||||||
MockDate.prototype.getTimezoneOffset = function() {
|
|
||||||
return timezoneOffset;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
Date = MockDate;
|
|
||||||
|
|
||||||
now = dateObj.valueOf();
|
|
||||||
}
|
|
||||||
|
|
||||||
function reset() {
|
|
||||||
Date = _Date;
|
|
||||||
Date.prototype.getTimezoneOffset = _getTimezoneOffset;
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
set: set,
|
|
||||||
reset: reset
|
|
||||||
};
|
|
||||||
|
|
||||||
}));
|
|
Reference in New Issue
Block a user