mirror of
https://github.com/MichMich/MagicMirror.git
synced 2025-07-01 21:43:26 +00:00
Update compliments module (#3471)
`Fixes #3465` Add config option `specialDayUnique` that defaults to `false` and causes special day compliments to be added to the existing compliments array. Setting this option to `true` will only show the compliments that have been configured for that day. --------- Co-authored-by: Veeck <github@veeck.de> Co-authored-by: veeck <michael.veeck@nebenan.de> Co-authored-by: Karsten Hassel <hassel@gmx.de>
This commit is contained in:
parent
3d9d72e64e
commit
aefb3a0b6d
@ -14,6 +14,7 @@ Thanks to: @kleinmantara (to be continued before release)
|
||||
### Added
|
||||
|
||||
- [calendar] Added config option "showEndsOnlyWithDuration" for default calendar
|
||||
- [compliments] Added `specialDayUnique` config option, defaults to `false`. (#3465)
|
||||
|
||||
### Removed
|
||||
|
||||
|
@ -15,7 +15,8 @@ Module.register("compliments", {
|
||||
morningEndTime: 12,
|
||||
afternoonStartTime: 12,
|
||||
afternoonEndTime: 17,
|
||||
random: true
|
||||
random: true,
|
||||
specialDayUnique: false
|
||||
},
|
||||
lastIndexUsed: -1,
|
||||
// Set currentweather from module
|
||||
@ -98,6 +99,10 @@ Module.register("compliments", {
|
||||
// Add compliments for special days
|
||||
for (let entry in this.config.compliments) {
|
||||
if (new RegExp(entry).test(date)) {
|
||||
// Only display compliments configured for the day if specialDayUnique is set to true
|
||||
if (this.config.specialDayUnique) {
|
||||
compliments.length = 0;
|
||||
}
|
||||
Array.prototype.push.apply(compliments, this.config.compliments[entry]);
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,22 @@
|
||||
let config = {
|
||||
modules: [
|
||||
{
|
||||
module: "compliments",
|
||||
position: "middle_center",
|
||||
config: {
|
||||
specialDayUnique: false,
|
||||
compliments: {
|
||||
anytime: [
|
||||
"Typical message 1",
|
||||
"Typical message 2",
|
||||
"Typical message 3"
|
||||
],
|
||||
"....-..-..": ["Special day message"]
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
/*************** DO NOT EDIT THE LINE BELOW ***************/
|
||||
if (typeof module !== "undefined") { module.exports = config; }
|
@ -0,0 +1,22 @@
|
||||
let config = {
|
||||
modules: [
|
||||
{
|
||||
module: "compliments",
|
||||
position: "middle_center",
|
||||
config: {
|
||||
specialDayUnique: true,
|
||||
compliments: {
|
||||
anytime: [
|
||||
"Typical message 1",
|
||||
"Typical message 2",
|
||||
"Typical message 3"
|
||||
],
|
||||
"....-..-..": ["Special day message"]
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
/*************** DO NOT EDIT THE LINE BELOW ***************/
|
||||
if (typeof module !== "undefined") { module.exports = config; }
|
@ -54,4 +54,28 @@ describe("Compliments module", () => {
|
||||
await expect(doTest(["Remote compliment file works!"])).resolves.toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe("Feature specialDayUnique in compliments module", () => {
|
||||
describe("specialDayUnique is false", () => {
|
||||
beforeAll(async () => {
|
||||
await helpers.startApplication("tests/configs/modules/compliments/compliments_specialDayUnique_false.js");
|
||||
await helpers.getDocument();
|
||||
});
|
||||
|
||||
it("compliments array can contain all values", async () => {
|
||||
await expect(doTest(["Special day message", "Typical message 1", "Typical message 2", "Typical message 3"])).resolves.toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe("specialDayUnique is true", () => {
|
||||
beforeAll(async () => {
|
||||
await helpers.startApplication("tests/configs/modules/compliments/compliments_specialDayUnique_true.js");
|
||||
await helpers.getDocument();
|
||||
});
|
||||
|
||||
it("compliments array contains only special value", async () => {
|
||||
await expect(doTest(["Special day message"])).resolves.toBe(true);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user