Merge pull request #1967 from MichMich/rejas-date

Rejas date
This commit is contained in:
Michael Teeuw 2020-04-01 11:15:31 +02:00 committed by GitHub
commit 8c85e240b7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 75 additions and 7 deletions

View File

@ -25,6 +25,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
- Run tests on long term support and latest stable version of nodejs - Run tests on long term support and latest stable version of nodejs
- Added the ability to configure a list of modules that shouldn't be update checked. - Added the ability to configure a list of modules that shouldn't be update checked.
- Run linters on git commits - Run linters on git commits
- Added date functionality to compliments: display birthday wishes or celebrate an anniversary
### Fixed ### Fixed
- Force declaration of public ip address in config file (ISSUE #1852) - Force declaration of public ip address in config file (ISSUE #1852)

View File

@ -28,6 +28,9 @@ Module.register("compliments", {
"Wow, you look hot!", "Wow, you look hot!",
"You look nice!", "You look nice!",
"Hi, sexy!" "Hi, sexy!"
],
"....-01-01": [
"Happy new year!"
] ]
}, },
updateInterval: 30000, updateInterval: 30000,
@ -37,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
@ -102,6 +106,7 @@ Module.register("compliments", {
*/ */
complimentArray: function() { complimentArray: function() {
var hour = moment().hour(); var hour = moment().hour();
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")) {
@ -122,6 +127,12 @@ Module.register("compliments", {
compliments.push.apply(compliments, this.config.compliments.anytime); compliments.push.apply(compliments, this.config.compliments.anytime);
for (entry in this.config.compliments) {
if (new RegExp(entry).test(date)) {
compliments.push.apply(compliments, this.config.compliments[entry]);
}
}
return compliments; return compliments;
}, },
@ -158,12 +169,12 @@ Module.register("compliments", {
index = this.randomIndex(compliments); index = this.randomIndex(compliments);
} }
else{ else{
// no, sequetial // no, sequential
// if doing sequential, don't fall off the end // if doing sequential, don't fall off the end
index = (this.lastIndexUsed >= (compliments.length-1))?0: ++this.lastIndexUsed; index = (this.lastIndexUsed >= (compliments.length-1))?0: ++this.lastIndexUsed;
} }
return compliments[index]; return compliments[index] || "";
}, },
// Override dom generator. // Override dom generator.

View File

@ -0,0 +1,41 @@
/* Magic Mirror Test config compliments with date type
*
* By Rejas
*
* MIT Licensed.
*/
let config = {
port: 8080,
ipWhitelist: ["127.0.0.1", "::ffff:127.0.0.1", "::1"],
language: "en",
timeFormat: 12,
units: "metric",
electronOptions: {
webPreferences: {
nodeIntegration: true,
},
},
modules: [
{
module: "compliments",
position: "middle_center",
config: {
mockDate: "2020-01-01",
compliments: {
morning: [],
afternoon: [],
evening: [],
"....-01-01": [
"Happy new year!"
]
}
}
}
]
};
/*************** DO NOT EDIT THE LINE BELOW ***************/
if (typeof module !== "undefined") {module.exports = config;}

View File

@ -89,4 +89,19 @@ describe("Compliments module", function() {
}); });
}); });
}); });
describe("Feature date in compliments module", function() {
describe("Set date and empty compliments for anytime, morning, evening and afternoon", function() {
before(function() {
// Set config sample for use in test
process.env.MM_CONFIG_FILE = "tests/configs/modules/compliments/compliments_date.js";
});
it("Show happy new year compliment on new years day", function() {
return app.client.waitUntilWindowLoaded().getText(".compliments").then(function(text) {
expect(text).to.be.oneOf(["Happy new year!"]);
});
});
});
});
}); });