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

Fix empty part-of-day logic #3726

Merged
merged 8 commits into from
Feb 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ planned for 2025-04-01
- [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
- [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

Expand Down
17 changes: 11 additions & 6 deletions modules/default/compliments/compliments.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,12 +139,17 @@ Module.register("compliments", {
let compliments = [];

// Add time of day compliments
if (hour >= this.config.morningStartTime && hour < this.config.morningEndTime && this.config.compliments.hasOwnProperty("morning")) {
compliments = [...this.config.compliments.morning];
} else if (hour >= this.config.afternoonStartTime && hour < this.config.afternoonEndTime && this.config.compliments.hasOwnProperty("afternoon")) {
compliments = [...this.config.compliments.afternoon];
} else if (this.config.compliments.hasOwnProperty("evening")) {
compliments = [...this.config.compliments.evening];
let timeOfDay;
if (hour >= this.config.morningStartTime && hour < this.config.morningEndTime) {
timeOfDay = "morning";
} else if (hour >= this.config.afternoonStartTime && hour < this.config.afternoonEndTime) {
timeOfDay = "afternoon";
} else {
timeOfDay = "evening";
}

if (timeOfDay && this.config.compliments.hasOwnProperty(timeOfDay)) {
compliments = [...this.config.compliments[timeOfDay]];
}

// Add compliments based on weather
Expand Down
22 changes: 11 additions & 11 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
},
"dependencies": {
"ajv": "^8.17.1",
"ansis": "^3.10.0",
"ansis": "^3.16.0",
"console-stamp": "^3.1.2",
"envsub": "^4.1.0",
"eslint": "^9.21.0",
Expand All @@ -83,8 +83,8 @@
"undici": "^7.3.0"
},
"devDependencies": {
"@stylistic/eslint-plugin": "^4.0.1",
"cspell": "^8.17.3",
"@stylistic/eslint-plugin": "^4.1.0",
"cspell": "^8.17.5",
"eslint-plugin-import": "^2.31.0",
"eslint-plugin-jest": "^28.11.0",
"eslint-plugin-jsdoc": "^50.6.3",
Expand All @@ -96,7 +96,7 @@
"lint-staged": "^15.4.3",
"markdownlint-cli2": "^0.17.2",
"playwright": "^1.50.1",
"prettier": "^3.4.2",
"prettier": "^3.5.2",
"sinon": "^19.0.2",
"stylelint": "^16.14.1",
"stylelint-config-standard": "^37.0.0",
Expand Down
22 changes: 22 additions & 0 deletions tests/configs/modules/compliments/compliments_evening.js
Original file line number Diff line number Diff line change
@@ -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;
}
6 changes: 3 additions & 3 deletions tests/electron/helpers/global-setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@ exports.stopApplication = async () => {
process.env.MOCK_DATE = undefined;
};

exports.getElement = async (selector) => {
exports.getElement = async (selector, state = "visible") => {
expect(global.page).not.toBeNull();
let elem = global.page.locator(selector);
await elem.waitFor();
const elem = global.page.locator(selector);
await elem.waitFor({ state: state });
expect(elem).not.toBeNull();
return elem;
};
11 changes: 8 additions & 3 deletions tests/electron/modules/compliments_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ describe("Compliments module", () => {
* @param {Array} complimentsArray The array of compliments.
* @returns {boolean} result
*/
const doTest = async (complimentsArray) => {
await helpers.getElement(".compliments");
const elem = await helpers.getElement(".module-content");
const doTest = async (complimentsArray, state = "visible") => {
await helpers.getElement(".compliments", state);
const elem = await helpers.getElement(".module-content", state);
expect(elem).not.toBeNull();
expect(complimentsArray).toContain(await elem.textContent());
return true;
Expand All @@ -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 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", () => {
Expand Down