From b08f8823247328b51e44192a2f8ac9738c2c6cbf Mon Sep 17 00:00:00 2001 From: rejas Date: Sat, 14 Mar 2020 21:14:45 +0100 Subject: [PATCH] Add (failing) test for new date field --- .../modules/compliments/compliments_date.js | 40 +++++++++++++++++++ tests/e2e/modules/compliments_spec.js | 37 +++++++++++++++++ 2 files changed, 77 insertions(+) create mode 100644 tests/configs/modules/compliments/compliments_date.js diff --git a/tests/configs/modules/compliments/compliments_date.js b/tests/configs/modules/compliments/compliments_date.js new file mode 100644 index 00000000..04acdde4 --- /dev/null +++ b/tests/configs/modules/compliments/compliments_date.js @@ -0,0 +1,40 @@ +/* Magic Mirror Test config compliments with date type + * + * By Rejas + * + * MIT Licensed. + */ + +let config = { + port: 8080, + ipWhitelist: ["127.0.0.1", "::ffff:127.0.0.1", "::1"], + + language: "en", + timeFormat: 12, + units: "metric", + electronOptions: { + webPreferences: { + nodeIntegration: true, + }, + }, + + modules: [ + { + module: "compliments", + position: "middle_center", + config: { + compliments: { + morning: [], + afternoon: [], + evening: [], + 1012: [ + "Happy birthday, Ada Lovelace!" + ] + } + } + } + ] +}; + +/*************** DO NOT EDIT THE LINE BELOW ***************/ +if (typeof module !== "undefined") {module.exports = config;} diff --git a/tests/e2e/modules/compliments_spec.js b/tests/e2e/modules/compliments_spec.js index 35529b19..68dcb7ff 100644 --- a/tests/e2e/modules/compliments_spec.js +++ b/tests/e2e/modules/compliments_spec.js @@ -1,5 +1,6 @@ const helpers = require("../global-setup"); const expect = require("chai").expect; +const moment = require("moment"); const describe = global.describe; const it = global.it; @@ -89,4 +90,40 @@ describe("Compliments module", function() { }); }); }); + + describe("Feature date in compliments module", function() { + describe("Set date and empty compliments for anytime, morning, evening and afternoon", function() { + let RealDate; + + before(function() { + // Set config sample for use in test + process.env.MM_CONFIG_FILE = "tests/configs/modules/compliments/compliments_date.js"; + + RealDate = Date; + let customTimeMs = moment("2015-10-12T06:00:00.000Z").valueOf(); + + function MockDate() { + return new RealDate(customTimeMs); + } + + MockDate.now = function () { + return new MockDate().valueOf(); + }; + + MockDate.prototype = RealDate.prototype; + + Date = MockDate; + }); + + it("Show anytime because if configure empty parts of day compliments and set anytime compliments", function() { + return app.client.waitUntilWindowLoaded().getText(".compliments").then(function(text) { + expect(text).to.be.oneOf(["Happy birthday, Ada Lovelace!"]); + }); + }); + + after(function() { + Date = RealDate; + }); + }); + }); });