Fix empty part-of-day logic (#3726)

Fixes #3727

---------

Co-authored-by: veeck <gitkraken@veeck.de>
This commit is contained in:
Veeck 2025-02-27 19:31:00 +01:00 committed by GitHub
parent 28bcee7de6
commit 4a398f03eb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 60 additions and 27 deletions

View File

@ -42,6 +42,7 @@ planned for 2025-04-01
- [core] Fix wrong port in log message when starting server only (#3696) - [core] Fix wrong port in log message when starting server only (#3696)
- [calendar] Fix NewYork event processed on system in Central timezone shows wrong time #3701 - [calendar] Fix NewYork event processed on system in Central timezone shows wrong time #3701
- [weather/yr] The Yr weather provider is now able to recover from bad API responses instead of freezing (#3296) - [weather/yr] The Yr weather provider is now able to recover from bad API responses instead of freezing (#3296)
- [compliments] Fix evening events being shown during the day (#3727)
## [2.30.0] - 2025-01-01 ## [2.30.0] - 2025-01-01

View File

@ -139,12 +139,17 @@ Module.register("compliments", {
let compliments = []; let compliments = [];
// Add time of day compliments // Add time of day compliments
if (hour >= this.config.morningStartTime && hour < this.config.morningEndTime && this.config.compliments.hasOwnProperty("morning")) { let timeOfDay;
compliments = [...this.config.compliments.morning]; if (hour >= this.config.morningStartTime && hour < this.config.morningEndTime) {
} else if (hour >= this.config.afternoonStartTime && hour < this.config.afternoonEndTime && this.config.compliments.hasOwnProperty("afternoon")) { timeOfDay = "morning";
compliments = [...this.config.compliments.afternoon]; } else if (hour >= this.config.afternoonStartTime && hour < this.config.afternoonEndTime) {
} else if (this.config.compliments.hasOwnProperty("evening")) { timeOfDay = "afternoon";
compliments = [...this.config.compliments.evening]; } else {
timeOfDay = "evening";
}
if (timeOfDay && this.config.compliments.hasOwnProperty(timeOfDay)) {
compliments = [...this.config.compliments[timeOfDay]];
} }
// Add compliments based on weather // Add compliments based on weather

22
package-lock.json generated
View File

@ -11,7 +11,7 @@
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"ajv": "^8.17.1", "ajv": "^8.17.1",
"ansis": "^3.10.0", "ansis": "^3.16.0",
"console-stamp": "^3.1.2", "console-stamp": "^3.1.2",
"envsub": "^4.1.0", "envsub": "^4.1.0",
"eslint": "^9.21.0", "eslint": "^9.21.0",
@ -31,8 +31,8 @@
"undici": "^7.3.0" "undici": "^7.3.0"
}, },
"devDependencies": { "devDependencies": {
"@stylistic/eslint-plugin": "^4.0.1", "@stylistic/eslint-plugin": "^4.1.0",
"cspell": "^8.17.3", "cspell": "^8.17.5",
"eslint-plugin-import": "^2.31.0", "eslint-plugin-import": "^2.31.0",
"eslint-plugin-jest": "^28.11.0", "eslint-plugin-jest": "^28.11.0",
"eslint-plugin-jsdoc": "^50.6.3", "eslint-plugin-jsdoc": "^50.6.3",
@ -44,7 +44,7 @@
"lint-staged": "^15.4.3", "lint-staged": "^15.4.3",
"markdownlint-cli2": "^0.17.2", "markdownlint-cli2": "^0.17.2",
"playwright": "^1.50.1", "playwright": "^1.50.1",
"prettier": "^3.4.2", "prettier": "^3.5.2",
"sinon": "^19.0.2", "sinon": "^19.0.2",
"stylelint": "^16.14.1", "stylelint": "^16.14.1",
"stylelint-config-standard": "^37.0.0", "stylelint-config-standard": "^37.0.0",
@ -2584,9 +2584,9 @@
"license": "MIT" "license": "MIT"
}, },
"node_modules/@stylistic/eslint-plugin": { "node_modules/@stylistic/eslint-plugin": {
"version": "4.0.1", "version": "4.1.0",
"resolved": "https://registry.npmjs.org/@stylistic/eslint-plugin/-/eslint-plugin-4.0.1.tgz", "resolved": "https://registry.npmjs.org/@stylistic/eslint-plugin/-/eslint-plugin-4.1.0.tgz",
"integrity": "sha512-RwKkRKiDrF4ptiur54ckDhOByQYKYZ1dEmI5K8BJCmuGpauFJXzVL1UQYTA2zq702CqMFdYiJcVFJWfokIgFxw==", "integrity": "sha512-bytbL7qiici7yPyEiId0fGPK9kjQbzcPMj2aftPfzTCyJ/CRSKdtI+iVjM0LSGzGxfunflI+MDDU9vyIIeIpoQ==",
"dev": true, "dev": true,
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
@ -3078,12 +3078,12 @@
} }
}, },
"node_modules/ansis": { "node_modules/ansis": {
"version": "3.10.0", "version": "3.16.0",
"resolved": "https://registry.npmjs.org/ansis/-/ansis-3.10.0.tgz", "resolved": "https://registry.npmjs.org/ansis/-/ansis-3.16.0.tgz",
"integrity": "sha512-hxDKLYT7hy3Y4sF3HxI926A3urzPxi73mZBB629m9bCVF+NyKNxbwCqqm+C/YrGPtxLwnl6d8/ZASCsz6SyvJA==", "integrity": "sha512-sU7d/tfZiYrsIAXbdL/CNZld5bCkruzwT5KmqmadCJYxuLxHAOBjidxD5+iLmN/6xEfjcQq1l7OpsiCBlc4LzA==",
"license": "ISC", "license": "ISC",
"engines": { "engines": {
"node": ">=16" "node": ">=14"
} }
}, },
"node_modules/anymatch": { "node_modules/anymatch": {

View File

@ -63,7 +63,7 @@
}, },
"dependencies": { "dependencies": {
"ajv": "^8.17.1", "ajv": "^8.17.1",
"ansis": "^3.10.0", "ansis": "^3.16.0",
"console-stamp": "^3.1.2", "console-stamp": "^3.1.2",
"envsub": "^4.1.0", "envsub": "^4.1.0",
"eslint": "^9.21.0", "eslint": "^9.21.0",
@ -83,8 +83,8 @@
"undici": "^7.3.0" "undici": "^7.3.0"
}, },
"devDependencies": { "devDependencies": {
"@stylistic/eslint-plugin": "^4.0.1", "@stylistic/eslint-plugin": "^4.1.0",
"cspell": "^8.17.3", "cspell": "^8.17.5",
"eslint-plugin-import": "^2.31.0", "eslint-plugin-import": "^2.31.0",
"eslint-plugin-jest": "^28.11.0", "eslint-plugin-jest": "^28.11.0",
"eslint-plugin-jsdoc": "^50.6.3", "eslint-plugin-jsdoc": "^50.6.3",
@ -96,7 +96,7 @@
"lint-staged": "^15.4.3", "lint-staged": "^15.4.3",
"markdownlint-cli2": "^0.17.2", "markdownlint-cli2": "^0.17.2",
"playwright": "^1.50.1", "playwright": "^1.50.1",
"prettier": "^3.4.2", "prettier": "^3.5.2",
"sinon": "^19.0.2", "sinon": "^19.0.2",
"stylelint": "^16.14.1", "stylelint": "^16.14.1",
"stylelint-config-standard": "^37.0.0", "stylelint-config-standard": "^37.0.0",

View File

@ -0,0 +1,22 @@
let config = {
address: "0.0.0.0",
ipWhitelist: [],
timeFormat: 12,
modules: [
{
module: "compliments",
position: "middle_center",
config: {
compliments: {
evening: ["Evening here"]
}
}
}
]
};
/*************** DO NOT EDIT THE LINE BELOW ***************/
if (typeof module !== "undefined") {
module.exports = config;
}

View File

@ -49,10 +49,10 @@ exports.stopApplication = async () => {
process.env.MOCK_DATE = undefined; process.env.MOCK_DATE = undefined;
}; };
exports.getElement = async (selector) => { exports.getElement = async (selector, state = "visible") => {
expect(global.page).not.toBeNull(); expect(global.page).not.toBeNull();
let elem = global.page.locator(selector); const elem = global.page.locator(selector);
await elem.waitFor(); await elem.waitFor({ state: state });
expect(elem).not.toBeNull(); expect(elem).not.toBeNull();
return elem; return elem;
}; };

View File

@ -7,9 +7,9 @@ describe("Compliments module", () => {
* @param {Array} complimentsArray The array of compliments. * @param {Array} complimentsArray The array of compliments.
* @returns {boolean} result * @returns {boolean} result
*/ */
const doTest = async (complimentsArray) => { const doTest = async (complimentsArray, state = "visible") => {
await helpers.getElement(".compliments"); await helpers.getElement(".compliments", state);
const elem = await helpers.getElement(".module-content"); const elem = await helpers.getElement(".module-content", state);
expect(elem).not.toBeNull(); expect(elem).not.toBeNull();
expect(complimentsArray).toContain(await elem.textContent()); expect(complimentsArray).toContain(await elem.textContent());
return true; return true;
@ -34,6 +34,11 @@ describe("Compliments module", () => {
await helpers.startApplication("tests/configs/modules/compliments/compliments_parts_day.js", "01 Oct 2022 20:00:00 GMT"); await helpers.startApplication("tests/configs/modules/compliments/compliments_parts_day.js", "01 Oct 2022 20:00:00 GMT");
await expect(doTest(["Hello There", "Good Evening", "Evening test"])).resolves.toBe(true); await expect(doTest(["Hello There", "Good Evening", "Evening test"])).resolves.toBe(true);
}); });
it("doesnt show evening compliments during the day when the other parts of day are not set", async () => {
await helpers.startApplication("tests/configs/modules/compliments/compliments_evening.js", "01 Oct 2022 08:00:00 GMT");
await expect(doTest([""], "attached")).resolves.toBe(true);
});
}); });
describe("Feature date in compliments module", () => { describe("Feature date in compliments module", () => {