2021-09-26 21:58:59 +02:00
|
|
|
const moment = require("moment");
|
2023-03-22 23:53:10 +01:00
|
|
|
const helpers = require("../helpers/global-setup");
|
2021-09-26 21:58:59 +02:00
|
|
|
|
2022-09-20 23:43:06 +02:00
|
|
|
describe("Clock module", () => {
|
|
|
|
afterAll(async () => {
|
2022-05-27 19:46:28 +02:00
|
|
|
await helpers.stopApplication();
|
2021-09-26 21:58:59 +02:00
|
|
|
});
|
|
|
|
|
2022-09-20 23:43:06 +02:00
|
|
|
describe("with default 24hr clock config", () => {
|
2022-10-04 10:15:24 +02:00
|
|
|
beforeAll(async () => {
|
2022-10-29 22:34:17 +02:00
|
|
|
await helpers.startApplication("tests/configs/modules/clock/clock_24hr.js");
|
2022-10-04 10:15:24 +02:00
|
|
|
await helpers.getDocument();
|
2021-09-26 21:58:59 +02:00
|
|
|
});
|
|
|
|
|
2022-10-04 10:15:24 +02:00
|
|
|
it("should show the date in the correct format", async () => {
|
2021-09-26 21:58:59 +02:00
|
|
|
const dateRegex = /^(?:Monday|Tuesday|Wednesday|Thursday|Friday|Saturday|Sunday), (?:January|February|March|April|May|June|July|August|September|October|November|December) \d{1,2}, \d{4}$/;
|
2022-10-04 10:15:24 +02:00
|
|
|
await helpers.testMatch(".clock .date", dateRegex);
|
2021-09-26 21:58:59 +02:00
|
|
|
});
|
|
|
|
|
2022-10-04 10:15:24 +02:00
|
|
|
it("should show the time in 24hr format", async () => {
|
2021-09-26 21:58:59 +02:00
|
|
|
const timeRegex = /^(?:2[0-3]|[01]\d):[0-5]\d[0-5]\d$/;
|
2022-10-04 10:15:24 +02:00
|
|
|
await helpers.testMatch(".clock .time", timeRegex);
|
2021-09-26 21:58:59 +02:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2022-09-20 23:43:06 +02:00
|
|
|
describe("with default 12hr clock config", () => {
|
2022-10-04 10:15:24 +02:00
|
|
|
beforeAll(async () => {
|
2022-10-29 22:34:17 +02:00
|
|
|
await helpers.startApplication("tests/configs/modules/clock/clock_12hr.js");
|
2022-10-04 10:15:24 +02:00
|
|
|
await helpers.getDocument();
|
2021-09-26 21:58:59 +02:00
|
|
|
});
|
|
|
|
|
2022-10-04 10:15:24 +02:00
|
|
|
it("should show the date in the correct format", async () => {
|
2021-09-26 21:58:59 +02:00
|
|
|
const dateRegex = /^(?:Monday|Tuesday|Wednesday|Thursday|Friday|Saturday|Sunday), (?:January|February|March|April|May|June|July|August|September|October|November|December) \d{1,2}, \d{4}$/;
|
2022-10-04 10:15:24 +02:00
|
|
|
await helpers.testMatch(".clock .date", dateRegex);
|
2021-09-26 21:58:59 +02:00
|
|
|
});
|
|
|
|
|
2022-10-04 10:15:24 +02:00
|
|
|
it("should show the time in 12hr format", async () => {
|
2021-09-26 21:58:59 +02:00
|
|
|
const timeRegex = /^(?:1[0-2]|[1-9]):[0-5]\d[0-5]\d[ap]m$/;
|
2022-10-04 10:15:24 +02:00
|
|
|
await helpers.testMatch(".clock .time", timeRegex);
|
2021-09-26 21:58:59 +02:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2022-09-20 23:43:06 +02:00
|
|
|
describe("with showPeriodUpper config enabled", () => {
|
2022-10-04 10:15:24 +02:00
|
|
|
beforeAll(async () => {
|
2022-10-29 22:34:17 +02:00
|
|
|
await helpers.startApplication("tests/configs/modules/clock/clock_showPeriodUpper.js");
|
2022-10-04 10:15:24 +02:00
|
|
|
await helpers.getDocument();
|
2021-09-26 21:58:59 +02:00
|
|
|
});
|
|
|
|
|
2022-10-04 10:15:24 +02:00
|
|
|
it("should show 12hr time with upper case AM/PM", async () => {
|
2021-09-26 21:58:59 +02:00
|
|
|
const timeRegex = /^(?:1[0-2]|[1-9]):[0-5]\d[0-5]\d[AP]M$/;
|
2022-10-04 10:15:24 +02:00
|
|
|
await helpers.testMatch(".clock .time", timeRegex);
|
2021-09-26 21:58:59 +02:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2022-09-20 23:43:06 +02:00
|
|
|
describe("with displaySeconds config disabled", () => {
|
2022-10-04 10:15:24 +02:00
|
|
|
beforeAll(async () => {
|
2022-10-29 22:34:17 +02:00
|
|
|
await helpers.startApplication("tests/configs/modules/clock/clock_displaySeconds_false.js");
|
2022-10-04 10:15:24 +02:00
|
|
|
await helpers.getDocument();
|
2021-09-26 21:58:59 +02:00
|
|
|
});
|
|
|
|
|
2022-10-04 10:15:24 +02:00
|
|
|
it("should show 12hr time without seconds am/pm", async () => {
|
2021-09-26 21:58:59 +02:00
|
|
|
const timeRegex = /^(?:1[0-2]|[1-9]):[0-5]\d[ap]m$/;
|
2022-10-04 10:15:24 +02:00
|
|
|
await helpers.testMatch(".clock .time", timeRegex);
|
2021-09-26 21:58:59 +02:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2022-09-20 23:43:06 +02:00
|
|
|
describe("with showTime config disabled", () => {
|
2022-10-04 10:15:24 +02:00
|
|
|
beforeAll(async () => {
|
2022-10-29 22:34:17 +02:00
|
|
|
await helpers.startApplication("tests/configs/modules/clock/clock_showTime.js");
|
2022-10-04 10:15:24 +02:00
|
|
|
await helpers.getDocument();
|
2021-09-26 21:58:59 +02:00
|
|
|
});
|
|
|
|
|
2022-10-04 10:15:24 +02:00
|
|
|
it("should not show the time when digital clock is shown", async () => {
|
2023-07-02 22:10:58 +02:00
|
|
|
const elem = document.querySelector(".clock .digital .time");
|
2022-09-20 23:43:06 +02:00
|
|
|
expect(elem).toBe(null);
|
2021-09-26 21:58:59 +02:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2023-07-02 22:10:58 +02:00
|
|
|
describe("with showSun/MoonTime enabled", () => {
|
|
|
|
beforeAll(async () => {
|
|
|
|
await helpers.startApplication("tests/configs/modules/clock/clock_showSunMoon.js");
|
|
|
|
await helpers.getDocument();
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should show the sun times", async () => {
|
|
|
|
const elem = await helpers.waitForElement(".clock .digital .sun");
|
|
|
|
expect(elem).not.toBe(null);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should show the moon times", async () => {
|
|
|
|
const elem = await helpers.waitForElement(".clock .digital .moon");
|
|
|
|
expect(elem).not.toBe(null);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2022-09-20 23:43:06 +02:00
|
|
|
describe("with showWeek config enabled", () => {
|
2022-10-04 10:15:24 +02:00
|
|
|
beforeAll(async () => {
|
2022-10-29 22:34:17 +02:00
|
|
|
await helpers.startApplication("tests/configs/modules/clock/clock_showWeek.js");
|
2022-10-04 10:15:24 +02:00
|
|
|
await helpers.getDocument();
|
2021-09-26 21:58:59 +02:00
|
|
|
});
|
|
|
|
|
2022-10-04 10:15:24 +02:00
|
|
|
it("should show the week in the correct format", async () => {
|
2021-09-26 21:58:59 +02:00
|
|
|
const weekRegex = /^Week [0-9]{1,2}$/;
|
2022-10-04 10:15:24 +02:00
|
|
|
await helpers.testMatch(".clock .week", weekRegex);
|
2021-09-26 21:58:59 +02:00
|
|
|
});
|
|
|
|
|
2022-10-04 10:15:24 +02:00
|
|
|
it("should show the week with the correct number of week of year", async () => {
|
2021-09-26 21:58:59 +02:00
|
|
|
const currentWeekNumber = moment().week();
|
2023-03-19 14:32:23 +01:00
|
|
|
const weekToShow = `Week ${currentWeekNumber}`;
|
2022-10-04 10:15:24 +02:00
|
|
|
const elem = await helpers.waitForElement(".clock .week");
|
|
|
|
expect(elem).not.toBe(null);
|
|
|
|
expect(elem.textContent).toBe(weekToShow);
|
2021-09-26 21:58:59 +02:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2022-09-20 23:43:06 +02:00
|
|
|
describe("with analog clock face enabled", () => {
|
2022-10-04 10:15:24 +02:00
|
|
|
beforeAll(async () => {
|
2022-10-29 22:34:17 +02:00
|
|
|
await helpers.startApplication("tests/configs/modules/clock/clock_analog.js");
|
2022-10-04 10:15:24 +02:00
|
|
|
await helpers.getDocument();
|
2021-09-26 21:58:59 +02:00
|
|
|
});
|
|
|
|
|
2022-10-04 10:15:24 +02:00
|
|
|
it("should show the analog clock face", async () => {
|
2023-02-19 21:36:50 +01:00
|
|
|
const elem = helpers.waitForElement(".clock-circle");
|
2022-10-04 10:15:24 +02:00
|
|
|
expect(elem).not.toBe(null);
|
2021-09-26 21:58:59 +02:00
|
|
|
});
|
|
|
|
});
|
2023-05-19 14:52:59 +02:00
|
|
|
|
|
|
|
describe("with analog clock face and date enabled", () => {
|
|
|
|
beforeAll(async () => {
|
|
|
|
await helpers.startApplication("tests/configs/modules/clock/clock_showDateAnalog.js");
|
|
|
|
await helpers.getDocument();
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should show the analog clock face and the date", async () => {
|
|
|
|
const elemClock = helpers.waitForElement(".clock-circle");
|
|
|
|
await expect(elemClock).not.toBe(null);
|
|
|
|
const elemDate = helpers.waitForElement(".clock .date");
|
|
|
|
await expect(elemDate).not.toBe(null);
|
|
|
|
});
|
|
|
|
});
|
2021-09-26 21:58:59 +02:00
|
|
|
});
|