Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update compliments module #3471

Merged
merged 10 commits into from
Jun 24, 2024
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; }
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

now youre just missing some actual test cases in the tests/e2e/modules/compliments_spec.js file, which load these configs and check the output of the MagicMirror

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);
});
});
});
});