Skip to content

Commit

Permalink
Update compliments module (#3471)
Browse files Browse the repository at this point in the history
`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>
  • Loading branch information
4 people authored Jun 24, 2024
1 parent 3d9d72e commit aefb3a0
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
7 changes: 6 additions & 1 deletion modules/default/compliments/compliments.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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]);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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; }
Original file line number Diff line number Diff line change
@@ -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; }
24 changes: 24 additions & 0 deletions tests/e2e/modules/compliments_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});
});
});

0 comments on commit aefb3a0

Please sign in to comment.