2017-07-24 22:08:12 +02:00
|
|
|
const helpers = require("../global-setup");
|
2020-08-02 15:19:36 +02:00
|
|
|
const moment = require("moment");
|
2017-07-24 22:08:12 +02:00
|
|
|
|
2020-05-11 22:22:32 +02:00
|
|
|
describe("Clock module", function () {
|
2017-07-24 22:08:12 +02:00
|
|
|
helpers.setupTimeout(this);
|
|
|
|
|
2021-03-17 22:29:20 +01:00
|
|
|
let app = null;
|
2017-07-24 22:08:12 +02:00
|
|
|
|
2021-06-14 17:02:11 +02:00
|
|
|
testMatch = async function (element, regex) {
|
|
|
|
await app.client.waitUntilWindowLoaded();
|
|
|
|
const elem = await app.client.$(element);
|
|
|
|
const txt = await elem.getText(element);
|
|
|
|
return txt.match(regex);
|
|
|
|
};
|
|
|
|
|
2020-05-11 22:22:32 +02:00
|
|
|
beforeEach(function () {
|
2017-07-24 22:08:12 +02:00
|
|
|
return helpers
|
|
|
|
.startApplication({
|
|
|
|
args: ["js/electron.js"]
|
|
|
|
})
|
2020-05-11 22:22:32 +02:00
|
|
|
.then(function (startedApp) {
|
2017-07-24 22:08:12 +02:00
|
|
|
app = startedApp;
|
|
|
|
});
|
|
|
|
});
|
2017-01-31 10:37:03 -08:00
|
|
|
|
2020-05-11 22:22:32 +02:00
|
|
|
afterEach(function () {
|
2017-07-24 22:08:12 +02:00
|
|
|
return helpers.stopApplication(app);
|
|
|
|
});
|
2017-01-31 10:37:03 -08:00
|
|
|
|
2020-05-11 22:22:32 +02:00
|
|
|
describe("with default 24hr clock config", function () {
|
2021-06-08 00:47:40 +02:00
|
|
|
beforeAll(function () {
|
2017-01-31 10:37:03 -08:00
|
|
|
// Set config sample for use in test
|
|
|
|
process.env.MM_CONFIG_FILE = "tests/configs/modules/clock/clock_24hr.js";
|
|
|
|
});
|
|
|
|
|
2021-01-30 20:29:59 +01:00
|
|
|
it("should show the date in the correct format", async function () {
|
2017-01-31 10:37:03 -08: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}$/;
|
2021-06-14 17:02:11 +02:00
|
|
|
return testMatch(".clock .date", dateRegex);
|
2017-01-31 10:37:03 -08:00
|
|
|
});
|
|
|
|
|
2021-01-30 20:29:59 +01:00
|
|
|
it("should show the time in 24hr format", async function () {
|
2017-07-24 22:08:12 +02:00
|
|
|
const timeRegex = /^(?:2[0-3]|[01]\d):[0-5]\d[0-5]\d$/;
|
2021-06-14 17:02:11 +02:00
|
|
|
return testMatch(".clock .time", timeRegex);
|
2017-01-31 10:37:03 -08:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-05-11 22:22:32 +02:00
|
|
|
describe("with default 12hr clock config", function () {
|
2021-06-08 00:47:40 +02:00
|
|
|
beforeAll(function () {
|
2017-01-31 10:37:03 -08:00
|
|
|
// Set config sample for use in test
|
|
|
|
process.env.MM_CONFIG_FILE = "tests/configs/modules/clock/clock_12hr.js";
|
|
|
|
});
|
|
|
|
|
2021-01-30 20:29:59 +01:00
|
|
|
it("should show the date in the correct format", async function () {
|
2017-01-31 10:37:03 -08: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}$/;
|
2021-06-14 17:02:11 +02:00
|
|
|
return testMatch(".clock .date", dateRegex);
|
2017-01-31 10:37:03 -08:00
|
|
|
});
|
|
|
|
|
2021-01-30 20:29:59 +01:00
|
|
|
it("should show the time in 12hr format", async function () {
|
2017-01-31 12:24:11 -08:00
|
|
|
const timeRegex = /^(?:1[0-2]|[1-9]):[0-5]\d[0-5]\d[ap]m$/;
|
2021-06-14 17:02:11 +02:00
|
|
|
return testMatch(".clock .time", timeRegex);
|
2017-01-31 10:37:03 -08:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-05-11 22:22:32 +02:00
|
|
|
describe("with showPeriodUpper config enabled", function () {
|
2021-06-08 00:47:40 +02:00
|
|
|
beforeAll(function () {
|
2017-01-31 10:37:03 -08:00
|
|
|
// Set config sample for use in test
|
|
|
|
process.env.MM_CONFIG_FILE = "tests/configs/modules/clock/clock_showPeriodUpper.js";
|
|
|
|
});
|
|
|
|
|
2021-01-30 20:29:59 +01:00
|
|
|
it("should show 12hr time with upper case AM/PM", async function () {
|
2017-01-31 12:24:11 -08:00
|
|
|
const timeRegex = /^(?:1[0-2]|[1-9]):[0-5]\d[0-5]\d[AP]M$/;
|
2021-06-14 17:02:11 +02:00
|
|
|
return testMatch(".clock .time", timeRegex);
|
2017-01-31 10:37:03 -08:00
|
|
|
});
|
|
|
|
});
|
2017-02-01 14:33:17 -03:00
|
|
|
|
2020-05-11 22:22:32 +02:00
|
|
|
describe("with displaySeconds config disabled", function () {
|
2021-06-08 00:47:40 +02:00
|
|
|
beforeAll(function () {
|
2017-02-01 14:33:17 -03:00
|
|
|
// Set config sample for use in test
|
|
|
|
process.env.MM_CONFIG_FILE = "tests/configs/modules/clock/clock_displaySeconds_false.js";
|
|
|
|
});
|
|
|
|
|
2021-01-30 20:29:59 +01:00
|
|
|
it("should show 12hr time without seconds am/pm", async function () {
|
2017-02-01 14:33:17 -03:00
|
|
|
const timeRegex = /^(?:1[0-2]|[1-9]):[0-5]\d[ap]m$/;
|
2021-06-14 17:02:11 +02:00
|
|
|
return testMatch(".clock .time", timeRegex);
|
2017-02-01 14:33:17 -03:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-05-11 22:22:32 +02:00
|
|
|
describe("with showWeek config enabled", function () {
|
2021-06-08 00:47:40 +02:00
|
|
|
beforeAll(function () {
|
2017-03-28 22:02:30 +02:00
|
|
|
// Set config sample for use in test
|
|
|
|
process.env.MM_CONFIG_FILE = "tests/configs/modules/clock/clock_showWeek.js";
|
|
|
|
});
|
|
|
|
|
2021-01-30 20:29:59 +01:00
|
|
|
it("should show the week in the correct format", async function () {
|
2017-03-28 22:02:30 +02:00
|
|
|
const weekRegex = /^Week [0-9]{1,2}$/;
|
2021-06-14 17:02:11 +02:00
|
|
|
return testMatch(".clock .week", weekRegex);
|
2017-03-28 22:02:30 +02:00
|
|
|
});
|
2017-04-12 22:29:20 -03:00
|
|
|
|
2021-01-30 20:29:59 +01:00
|
|
|
it("should show the week with the correct number of week of year", async function () {
|
2020-08-02 15:19:36 +02:00
|
|
|
const currentWeekNumber = moment().week();
|
|
|
|
const weekToShow = "Week " + currentWeekNumber;
|
2021-06-14 17:02:11 +02:00
|
|
|
await app.client.waitUntilWindowLoaded();
|
2021-01-30 20:29:59 +01:00
|
|
|
const elem = await app.client.$(".clock .week");
|
2021-06-14 17:02:11 +02:00
|
|
|
const txt = await elem.getText(".clock .week");
|
|
|
|
return txt === weekToShow;
|
2017-04-12 22:29:20 -03:00
|
|
|
});
|
2017-03-28 22:02:30 +02:00
|
|
|
});
|
2020-07-21 11:27:45 +02:00
|
|
|
|
|
|
|
describe("with analog clock face enabled", function () {
|
2021-06-08 00:47:40 +02:00
|
|
|
beforeAll(function () {
|
2020-07-21 11:27:45 +02:00
|
|
|
// Set config sample for use in test
|
|
|
|
process.env.MM_CONFIG_FILE = "tests/configs/modules/clock/clock_analog.js";
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should show the analog clock face", async () => {
|
|
|
|
await app.client.waitUntilWindowLoaded(10000);
|
|
|
|
const clock = await app.client.$$(".clockCircle");
|
2021-06-09 00:19:43 +02:00
|
|
|
return expect(clock.length).toBe(1);
|
2020-07-21 11:27:45 +02:00
|
|
|
});
|
|
|
|
});
|
2017-01-31 10:37:03 -08:00
|
|
|
});
|