mirror of
https://github.com/MichMich/MagicMirror.git
synced 2025-12-12 18:02:15 +00:00
[core] refactor: replace XMLHttpRequest with fetch and migrate e2e tests to Playwright (#3950)
### 1. Replace `XMLHttpRequest` with the modern `fetch` API for loading translation files #### Changes - **translator.js**: Use `fetch` with `async/await` instead of XHR callbacks - **loader.js**: Align URL handling and add error handling (follow-up to fetch migration) - **Tests**: Update infrastructure for `fetch` compatibility #### Benefits - Modern standard API - Cleaner, more readable code - Better error handling and fallback mechanisms ### 2. Migrate e2e tests to Playwright This wasn't originally planned for this PR, but is related. While investigating suspicious log entries which surfaced after the fetch migration I kept running into JSDOM’s limitations. That pushed me to migrate the E2E suite to Playwright instead. #### Changes - switch e2e harness to Playwright (`tests/e2e/helpers/global-setup.js`) - rewrite specs to use Playwright locators + shared `expectTextContent` - install Chromium via `npx playwright install --with-deps` in CI #### Benefits - much closer to real browser behaviour - and no more fighting JSDOM’s quirks
This commit is contained in:
committed by
GitHub
parent
2b08288346
commit
f29f424a62
@@ -1,6 +1,9 @@
|
||||
const { expect } = require("playwright/test");
|
||||
const helpers = require("../helpers/global-setup");
|
||||
|
||||
describe("Alert module", () => {
|
||||
let page;
|
||||
|
||||
afterAll(async () => {
|
||||
await helpers.stopApplication();
|
||||
});
|
||||
@@ -9,6 +12,7 @@ describe("Alert module", () => {
|
||||
beforeAll(async () => {
|
||||
await helpers.startApplication("tests/configs/modules/alert/welcome_false.js");
|
||||
await helpers.getDocument();
|
||||
page = helpers.getPage();
|
||||
});
|
||||
|
||||
it("should not show any welcome message", async () => {
|
||||
@@ -16,8 +20,7 @@ describe("Alert module", () => {
|
||||
await new Promise((resolve) => setTimeout(resolve, 1000));
|
||||
|
||||
// Check that no alert/notification elements are present
|
||||
const alertElements = document.querySelectorAll(".ns-box .ns-box-inner .light.bright.small");
|
||||
expect(alertElements).toHaveLength(0);
|
||||
await expect(page.locator(".ns-box .ns-box-inner .light.bright.small")).toHaveCount(0);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -25,15 +28,14 @@ describe("Alert module", () => {
|
||||
beforeAll(async () => {
|
||||
await helpers.startApplication("tests/configs/modules/alert/welcome_true.js");
|
||||
await helpers.getDocument();
|
||||
page = helpers.getPage();
|
||||
|
||||
// Wait for the application to initialize
|
||||
await new Promise((resolve) => setTimeout(resolve, 1000));
|
||||
});
|
||||
|
||||
it("should show the translated welcome message", async () => {
|
||||
const elem = await helpers.waitForElement(".ns-box .ns-box-inner .light.bright.small");
|
||||
expect(elem).not.toBeNull();
|
||||
expect(elem.textContent).toContain("Welcome, start was successful!");
|
||||
await expect(page.locator(".ns-box .ns-box-inner .light.bright.small")).toContainText("Welcome, start was successful!");
|
||||
});
|
||||
});
|
||||
|
||||
@@ -41,12 +43,11 @@ describe("Alert module", () => {
|
||||
beforeAll(async () => {
|
||||
await helpers.startApplication("tests/configs/modules/alert/welcome_string.js");
|
||||
await helpers.getDocument();
|
||||
page = helpers.getPage();
|
||||
});
|
||||
|
||||
it("should show the custom welcome message", async () => {
|
||||
const elem = await helpers.waitForElement(".ns-box .ns-box-inner .light.bright.small");
|
||||
expect(elem).not.toBeNull();
|
||||
expect(elem.textContent).toContain("Custom welcome message!");
|
||||
await expect(page.locator(".ns-box .ns-box-inner .light.bright.small")).toContainText("Custom welcome message!");
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,30 +1,28 @@
|
||||
const { expect } = require("playwright/test");
|
||||
const helpers = require("../helpers/global-setup");
|
||||
const serverBasicAuth = require("../helpers/basic-auth");
|
||||
|
||||
describe("Calendar module", () => {
|
||||
let page;
|
||||
|
||||
/**
|
||||
* @param {string} element css selector
|
||||
* @param {string} result expected number
|
||||
* @param {string} not reverse result
|
||||
* @returns {boolean} result
|
||||
* Assert the number of matching elements.
|
||||
* @param {string} selector css selector
|
||||
* @param {number} expectedLength expected number of elements
|
||||
* @param {string} [not] optional negation marker (use "not" to negate)
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
const testElementLength = async (element, result, not) => {
|
||||
const elem = await helpers.waitForAllElements(element);
|
||||
expect(elem).not.toBeNull();
|
||||
const testElementLength = async (selector, expectedLength, not) => {
|
||||
const locator = page.locator(selector);
|
||||
if (not === "not") {
|
||||
expect(elem).not.toHaveLength(result);
|
||||
await expect(locator).not.toHaveCount(expectedLength);
|
||||
} else {
|
||||
expect(elem).toHaveLength(result);
|
||||
await expect(locator).toHaveCount(expectedLength);
|
||||
}
|
||||
return true;
|
||||
};
|
||||
|
||||
const testTextContain = async (element, text) => {
|
||||
const elem = await helpers.waitForElement(element, "undefinedLoading");
|
||||
expect(elem).not.toBeNull();
|
||||
expect(elem.textContent).toContain(text);
|
||||
return true;
|
||||
const testTextContain = async (selector, expectedText) => {
|
||||
await expect(page.locator(selector).first()).toContainText(expectedText);
|
||||
};
|
||||
|
||||
afterAll(async () => {
|
||||
@@ -35,14 +33,15 @@ describe("Calendar module", () => {
|
||||
beforeAll(async () => {
|
||||
await helpers.startApplication("tests/configs/modules/calendar/default.js");
|
||||
await helpers.getDocument();
|
||||
page = helpers.getPage();
|
||||
});
|
||||
|
||||
it("should show the default maximumEntries of 10", async () => {
|
||||
await expect(testElementLength(".calendar .event", 10)).resolves.toBe(true);
|
||||
await testElementLength(".calendar .event", 10);
|
||||
});
|
||||
|
||||
it("should show the default calendar symbol in each event", async () => {
|
||||
await expect(testElementLength(".calendar .event .fa-calendar-days", 0, "not")).resolves.toBe(true);
|
||||
await testElementLength(".calendar .event .fa-calendar-days", 0, "not");
|
||||
});
|
||||
});
|
||||
|
||||
@@ -50,30 +49,31 @@ describe("Calendar module", () => {
|
||||
beforeAll(async () => {
|
||||
await helpers.startApplication("tests/configs/modules/calendar/custom.js");
|
||||
await helpers.getDocument();
|
||||
page = helpers.getPage();
|
||||
});
|
||||
|
||||
it("should show the custom maximumEntries of 5", async () => {
|
||||
await expect(testElementLength(".calendar .event", 5)).resolves.toBe(true);
|
||||
await testElementLength(".calendar .event", 5);
|
||||
});
|
||||
|
||||
it("should show the custom calendar symbol in four events", async () => {
|
||||
await expect(testElementLength(".calendar .event .fa-birthday-cake", 4)).resolves.toBe(true);
|
||||
await testElementLength(".calendar .event .fa-birthday-cake", 4);
|
||||
});
|
||||
|
||||
it("should show a customEvent calendar symbol in one event", async () => {
|
||||
await expect(testElementLength(".calendar .event .fa-dice", 1)).resolves.toBe(true);
|
||||
await testElementLength(".calendar .event .fa-dice", 1);
|
||||
});
|
||||
|
||||
it("should show a customEvent calendar eventClass in one event", async () => {
|
||||
await expect(testElementLength(".calendar .event.undo", 1)).resolves.toBe(true);
|
||||
await testElementLength(".calendar .event.undo", 1);
|
||||
});
|
||||
|
||||
it("should show two custom icons for repeating events", async () => {
|
||||
await expect(testElementLength(".calendar .event .fa-undo", 2)).resolves.toBe(true);
|
||||
await testElementLength(".calendar .event .fa-undo", 2);
|
||||
});
|
||||
|
||||
it("should show two custom icons for day events", async () => {
|
||||
await expect(testElementLength(".calendar .event .fa-calendar-day", 2)).resolves.toBe(true);
|
||||
await testElementLength(".calendar .event .fa-calendar-day", 2);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -81,10 +81,11 @@ describe("Calendar module", () => {
|
||||
beforeAll(async () => {
|
||||
await helpers.startApplication("tests/configs/modules/calendar/recurring.js");
|
||||
await helpers.getDocument();
|
||||
page = helpers.getPage();
|
||||
});
|
||||
|
||||
it("should show the recurring birthday event 6 times", async () => {
|
||||
await expect(testElementLength(".calendar .event", 6)).resolves.toBe(true);
|
||||
await testElementLength(".calendar .event", 6);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -93,15 +94,16 @@ describe("Calendar module", () => {
|
||||
beforeAll(async () => {
|
||||
await helpers.startApplication("tests/configs/modules/calendar/long-fullday-event.js");
|
||||
await helpers.getDocument();
|
||||
page = helpers.getPage();
|
||||
});
|
||||
|
||||
it("should contain text 'Ends in' with the left days", async () => {
|
||||
await expect(testTextContain(".calendar .today .time", "Ends in")).resolves.toBe(true);
|
||||
await expect(testTextContain(".calendar .yesterday .time", "Today")).resolves.toBe(true);
|
||||
await expect(testTextContain(".calendar .tomorrow .time", "Tomorrow")).resolves.toBe(true);
|
||||
await testTextContain(".calendar .today .time", "Ends in");
|
||||
await testTextContain(".calendar .yesterday .time", "Today");
|
||||
await testTextContain(".calendar .tomorrow .time", "Tomorrow");
|
||||
});
|
||||
it("should contain in total three events", async () => {
|
||||
await expect(testElementLength(".calendar .event", 3)).resolves.toBe(true);
|
||||
await testElementLength(".calendar .event", 3);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -109,13 +111,14 @@ describe("Calendar module", () => {
|
||||
beforeAll(async () => {
|
||||
await helpers.startApplication("tests/configs/modules/calendar/single-fullday-event.js");
|
||||
await helpers.getDocument();
|
||||
page = helpers.getPage();
|
||||
});
|
||||
|
||||
it("should contain text 'Today'", async () => {
|
||||
await expect(testTextContain(".calendar .time", "Today")).resolves.toBe(true);
|
||||
await testTextContain(".calendar .time", "Today");
|
||||
});
|
||||
it("should contain in total two events", async () => {
|
||||
await expect(testElementLength(".calendar .event", 2)).resolves.toBe(true);
|
||||
await testElementLength(".calendar .event", 2);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -124,6 +127,7 @@ describe("Calendar module", () => {
|
||||
await helpers.startApplication("tests/configs/modules/calendar/changed-port.js");
|
||||
serverBasicAuth.listen(8010);
|
||||
await helpers.getDocument();
|
||||
page = helpers.getPage();
|
||||
});
|
||||
|
||||
afterAll(async () => {
|
||||
@@ -131,7 +135,7 @@ describe("Calendar module", () => {
|
||||
});
|
||||
|
||||
it("should return TestEvents", async () => {
|
||||
await expect(testElementLength(".calendar .event", 0, "not")).resolves.toBe(true);
|
||||
await testElementLength(".calendar .event", 0, "not");
|
||||
});
|
||||
});
|
||||
|
||||
@@ -139,10 +143,11 @@ describe("Calendar module", () => {
|
||||
beforeAll(async () => {
|
||||
await helpers.startApplication("tests/configs/modules/calendar/basic-auth.js");
|
||||
await helpers.getDocument();
|
||||
page = helpers.getPage();
|
||||
});
|
||||
|
||||
it("should return TestEvents", async () => {
|
||||
await expect(testElementLength(".calendar .event", 0, "not")).resolves.toBe(true);
|
||||
await testElementLength(".calendar .event", 0, "not");
|
||||
});
|
||||
});
|
||||
|
||||
@@ -150,10 +155,11 @@ describe("Calendar module", () => {
|
||||
beforeAll(async () => {
|
||||
await helpers.startApplication("tests/configs/modules/calendar/auth-default.js");
|
||||
await helpers.getDocument();
|
||||
page = helpers.getPage();
|
||||
});
|
||||
|
||||
it("should return TestEvents", async () => {
|
||||
await expect(testElementLength(".calendar .event", 0, "not")).resolves.toBe(true);
|
||||
await testElementLength(".calendar .event", 0, "not");
|
||||
});
|
||||
});
|
||||
|
||||
@@ -161,10 +167,11 @@ describe("Calendar module", () => {
|
||||
beforeAll(async () => {
|
||||
await helpers.startApplication("tests/configs/modules/calendar/old-basic-auth.js");
|
||||
await helpers.getDocument();
|
||||
page = helpers.getPage();
|
||||
});
|
||||
|
||||
it("should return TestEvents", async () => {
|
||||
await expect(testElementLength(".calendar .event", 0, "not")).resolves.toBe(true);
|
||||
await testElementLength(".calendar .event", 0, "not");
|
||||
});
|
||||
});
|
||||
|
||||
@@ -173,6 +180,7 @@ describe("Calendar module", () => {
|
||||
await helpers.startApplication("tests/configs/modules/calendar/fail-basic-auth.js");
|
||||
serverBasicAuth.listen(8020);
|
||||
await helpers.getDocument();
|
||||
page = helpers.getPage();
|
||||
});
|
||||
|
||||
afterAll(async () => {
|
||||
@@ -180,7 +188,7 @@ describe("Calendar module", () => {
|
||||
});
|
||||
|
||||
it("should show Unauthorized error", async () => {
|
||||
await expect(testTextContain(".calendar", "Error in the calendar module. Authorization failed")).resolves.toBe(true);
|
||||
await testTextContain(".calendar", "Error in the calendar module. Authorization failed");
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
const { expect } = require("playwright/test");
|
||||
const helpers = require("../helpers/global-setup");
|
||||
|
||||
describe("Clock set to german language module", () => {
|
||||
let page;
|
||||
|
||||
afterAll(async () => {
|
||||
await helpers.stopApplication();
|
||||
});
|
||||
@@ -9,11 +12,12 @@ describe("Clock set to german language module", () => {
|
||||
beforeAll(async () => {
|
||||
await helpers.startApplication("tests/configs/modules/clock/de/clock_showWeek.js");
|
||||
await helpers.getDocument();
|
||||
page = helpers.getPage();
|
||||
});
|
||||
|
||||
it("shows week with correct format", async () => {
|
||||
const weekRegex = /^[0-9]{1,2}. Kalenderwoche$/;
|
||||
await expect(helpers.testMatch(".clock .week", weekRegex)).resolves.toBe(true);
|
||||
await expect(page.locator(".clock .week")).toHaveText(weekRegex);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -21,11 +25,12 @@ describe("Clock set to german language module", () => {
|
||||
beforeAll(async () => {
|
||||
await helpers.startApplication("tests/configs/modules/clock/de/clock_showWeek_short.js");
|
||||
await helpers.getDocument();
|
||||
page = helpers.getPage();
|
||||
});
|
||||
|
||||
it("shows week with correct format", async () => {
|
||||
const weekRegex = /^[0-9]{1,2}KW$/;
|
||||
await expect(helpers.testMatch(".clock .week", weekRegex)).resolves.toBe(true);
|
||||
await expect(page.locator(".clock .week")).toHaveText(weekRegex);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
const { expect } = require("playwright/test");
|
||||
const helpers = require("../helpers/global-setup");
|
||||
|
||||
describe("Clock set to spanish language module", () => {
|
||||
let page;
|
||||
|
||||
afterAll(async () => {
|
||||
await helpers.stopApplication();
|
||||
});
|
||||
@@ -9,16 +12,17 @@ describe("Clock set to spanish language module", () => {
|
||||
beforeAll(async () => {
|
||||
await helpers.startApplication("tests/configs/modules/clock/es/clock_24hr.js");
|
||||
await helpers.getDocument();
|
||||
page = helpers.getPage();
|
||||
});
|
||||
|
||||
it("shows date with correct format", async () => {
|
||||
const dateRegex = /^(?:lunes|martes|miércoles|jueves|viernes|sábado|domingo), \d{1,2} de (?:enero|febrero|marzo|abril|mayo|junio|julio|agosto|septiembre|octubre|noviembre|diciembre) de \d{4}$/;
|
||||
await expect(helpers.testMatch(".clock .date", dateRegex)).resolves.toBe(true);
|
||||
await expect(page.locator(".clock .date")).toHaveText(dateRegex);
|
||||
});
|
||||
|
||||
it("shows time in 24hr format", async () => {
|
||||
const timeRegex = /^(?:2[0-3]|[01]\d):[0-5]\d[0-5]\d$/;
|
||||
await expect(helpers.testMatch(".clock .time", timeRegex)).resolves.toBe(true);
|
||||
await expect(page.locator(".clock .time")).toHaveText(timeRegex);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -26,16 +30,17 @@ describe("Clock set to spanish language module", () => {
|
||||
beforeAll(async () => {
|
||||
await helpers.startApplication("tests/configs/modules/clock/es/clock_12hr.js");
|
||||
await helpers.getDocument();
|
||||
page = helpers.getPage();
|
||||
});
|
||||
|
||||
it("shows date with correct format", async () => {
|
||||
const dateRegex = /^(?:lunes|martes|miércoles|jueves|viernes|sábado|domingo), \d{1,2} de (?:enero|febrero|marzo|abril|mayo|junio|julio|agosto|septiembre|octubre|noviembre|diciembre) de \d{4}$/;
|
||||
await expect(helpers.testMatch(".clock .date", dateRegex)).resolves.toBe(true);
|
||||
await expect(page.locator(".clock .date")).toHaveText(dateRegex);
|
||||
});
|
||||
|
||||
it("shows time in 12hr format", async () => {
|
||||
const timeRegex = /^(?:1[0-2]|[1-9]):[0-5]\d[0-5]\d[ap]m$/;
|
||||
await expect(helpers.testMatch(".clock .time", timeRegex)).resolves.toBe(true);
|
||||
await expect(page.locator(".clock .time")).toHaveText(timeRegex);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -43,11 +48,12 @@ describe("Clock set to spanish language module", () => {
|
||||
beforeAll(async () => {
|
||||
await helpers.startApplication("tests/configs/modules/clock/es/clock_showPeriodUpper.js");
|
||||
await helpers.getDocument();
|
||||
page = helpers.getPage();
|
||||
});
|
||||
|
||||
it("shows 12hr time with upper case AM/PM", async () => {
|
||||
const timeRegex = /^(?:1[0-2]|[1-9]):[0-5]\d[0-5]\d[AP]M$/;
|
||||
await expect(helpers.testMatch(".clock .time", timeRegex)).resolves.toBe(true);
|
||||
await expect(page.locator(".clock .time")).toHaveText(timeRegex);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -55,11 +61,12 @@ describe("Clock set to spanish language module", () => {
|
||||
beforeAll(async () => {
|
||||
await helpers.startApplication("tests/configs/modules/clock/es/clock_showWeek.js");
|
||||
await helpers.getDocument();
|
||||
page = helpers.getPage();
|
||||
});
|
||||
|
||||
it("shows week with correct format", async () => {
|
||||
const weekRegex = /^Semana [0-9]{1,2}$/;
|
||||
await expect(helpers.testMatch(".clock .week", weekRegex)).resolves.toBe(true);
|
||||
await expect(page.locator(".clock .week")).toHaveText(weekRegex);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -67,11 +74,12 @@ describe("Clock set to spanish language module", () => {
|
||||
beforeAll(async () => {
|
||||
await helpers.startApplication("tests/configs/modules/clock/es/clock_showWeek_short.js");
|
||||
await helpers.getDocument();
|
||||
page = helpers.getPage();
|
||||
});
|
||||
|
||||
it("shows week with correct format", async () => {
|
||||
const weekRegex = /^S[0-9]{1,2}$/;
|
||||
await expect(helpers.testMatch(".clock .week", weekRegex)).resolves.toBe(true);
|
||||
await expect(page.locator(".clock .week")).toHaveText(weekRegex);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
const { expect } = require("playwright/test");
|
||||
const moment = require("moment");
|
||||
const helpers = require("../helpers/global-setup");
|
||||
|
||||
describe("Clock module", () => {
|
||||
let page;
|
||||
|
||||
afterAll(async () => {
|
||||
await helpers.stopApplication();
|
||||
});
|
||||
@@ -10,16 +13,17 @@ describe("Clock module", () => {
|
||||
beforeAll(async () => {
|
||||
await helpers.startApplication("tests/configs/modules/clock/clock_24hr.js");
|
||||
await helpers.getDocument();
|
||||
page = helpers.getPage();
|
||||
});
|
||||
|
||||
it("should show the date in the correct format", async () => {
|
||||
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}$/;
|
||||
await expect(helpers.testMatch(".clock .date", dateRegex)).resolves.toBe(true);
|
||||
await expect(page.locator(".clock .date")).toHaveText(dateRegex);
|
||||
});
|
||||
|
||||
it("should show the time in 24hr format", async () => {
|
||||
const timeRegex = /^(?:2[0-3]|[01]\d):[0-5]\d[0-5]\d$/;
|
||||
await expect(helpers.testMatch(".clock .time", timeRegex)).resolves.toBe(true);
|
||||
await expect(page.locator(".clock .time")).toHaveText(timeRegex);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -27,23 +31,22 @@ describe("Clock module", () => {
|
||||
beforeAll(async () => {
|
||||
await helpers.startApplication("tests/configs/modules/clock/clock_12hr.js");
|
||||
await helpers.getDocument();
|
||||
page = helpers.getPage();
|
||||
});
|
||||
|
||||
it("should show the date in the correct format", async () => {
|
||||
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}$/;
|
||||
await expect(helpers.testMatch(".clock .date", dateRegex)).resolves.toBe(true);
|
||||
await expect(page.locator(".clock .date")).toHaveText(dateRegex);
|
||||
});
|
||||
|
||||
it("should show the time in 12hr format", async () => {
|
||||
const timeRegex = /^(?:1[0-2]|[1-9]):[0-5]\d[0-5]\d[ap]m$/;
|
||||
await expect(helpers.testMatch(".clock .time", timeRegex)).resolves.toBe(true);
|
||||
await expect(page.locator(".clock .time")).toHaveText(timeRegex);
|
||||
});
|
||||
|
||||
it("check for discreet elements of clock", async () => {
|
||||
let elemClock = await helpers.waitForElement(".clock-hour-digital");
|
||||
await expect(elemClock).not.toBeNull();
|
||||
elemClock = await helpers.waitForElement(".clock-minute-digital");
|
||||
await expect(elemClock).not.toBeNull();
|
||||
await expect(page.locator(".clock-hour-digital")).toBeVisible();
|
||||
await expect(page.locator(".clock-minute-digital")).toBeVisible();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -51,11 +54,12 @@ describe("Clock module", () => {
|
||||
beforeAll(async () => {
|
||||
await helpers.startApplication("tests/configs/modules/clock/clock_showPeriodUpper.js");
|
||||
await helpers.getDocument();
|
||||
page = helpers.getPage();
|
||||
});
|
||||
|
||||
it("should show 12hr time with upper case AM/PM", async () => {
|
||||
const timeRegex = /^(?:1[0-2]|[1-9]):[0-5]\d[0-5]\d[AP]M$/;
|
||||
await expect(helpers.testMatch(".clock .time", timeRegex)).resolves.toBe(true);
|
||||
await expect(page.locator(".clock .time")).toHaveText(timeRegex);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -63,11 +67,12 @@ describe("Clock module", () => {
|
||||
beforeAll(async () => {
|
||||
await helpers.startApplication("tests/configs/modules/clock/clock_displaySeconds_false.js");
|
||||
await helpers.getDocument();
|
||||
page = helpers.getPage();
|
||||
});
|
||||
|
||||
it("should show 12hr time without seconds am/pm", async () => {
|
||||
const timeRegex = /^(?:1[0-2]|[1-9]):[0-5]\d[ap]m$/;
|
||||
await expect(helpers.testMatch(".clock .time", timeRegex)).resolves.toBe(true);
|
||||
await expect(page.locator(".clock .time")).toHaveText(timeRegex);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -75,11 +80,11 @@ describe("Clock module", () => {
|
||||
beforeAll(async () => {
|
||||
await helpers.startApplication("tests/configs/modules/clock/clock_showTime.js");
|
||||
await helpers.getDocument();
|
||||
page = helpers.getPage();
|
||||
});
|
||||
|
||||
it("should not show the time when digital clock is shown", async () => {
|
||||
const elem = document.querySelector(".clock .digital .time");
|
||||
expect(elem).toBeNull();
|
||||
await expect(page.locator(".clock .digital .time")).toHaveCount(0);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -87,19 +92,16 @@ describe("Clock module", () => {
|
||||
beforeAll(async () => {
|
||||
await helpers.startApplication("tests/configs/modules/clock/clock_showSunMoon.js");
|
||||
await helpers.getDocument();
|
||||
page = helpers.getPage();
|
||||
});
|
||||
|
||||
it("should show the sun times", async () => {
|
||||
const elem = await helpers.waitForElement(".clock .digital .sun");
|
||||
expect(elem).not.toBeNull();
|
||||
|
||||
const elem2 = await helpers.waitForElement(".clock .digital .sun .fas.fa-sun");
|
||||
expect(elem2).not.toBeNull();
|
||||
await expect(page.locator(".clock .digital .sun")).toBeVisible();
|
||||
await expect(page.locator(".clock .digital .sun .fas.fa-sun")).toBeVisible();
|
||||
});
|
||||
|
||||
it("should show the moon times", async () => {
|
||||
const elem = await helpers.waitForElement(".clock .digital .moon");
|
||||
expect(elem).not.toBeNull();
|
||||
await expect(page.locator(".clock .digital .moon")).toBeVisible();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -107,14 +109,12 @@ describe("Clock module", () => {
|
||||
beforeAll(async () => {
|
||||
await helpers.startApplication("tests/configs/modules/clock/clock_showSunNoEvent.js");
|
||||
await helpers.getDocument();
|
||||
page = helpers.getPage();
|
||||
});
|
||||
|
||||
it("should show the sun times", async () => {
|
||||
const elem = await helpers.waitForElement(".clock .digital .sun");
|
||||
expect(elem).not.toBeNull();
|
||||
|
||||
const elem2 = document.querySelector(".clock .digital .sun .fas.fa-sun");
|
||||
expect(elem2).toBeNull();
|
||||
await expect(page.locator(".clock .digital .sun")).toBeVisible();
|
||||
await expect(page.locator(".clock .digital .sun .fas.fa-sun")).toHaveCount(0);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -122,19 +122,18 @@ describe("Clock module", () => {
|
||||
beforeAll(async () => {
|
||||
await helpers.startApplication("tests/configs/modules/clock/clock_showWeek.js");
|
||||
await helpers.getDocument();
|
||||
page = helpers.getPage();
|
||||
});
|
||||
|
||||
it("should show the week in the correct format", async () => {
|
||||
const weekRegex = /^Week [0-9]{1,2}$/;
|
||||
await expect(helpers.testMatch(".clock .week", weekRegex)).resolves.toBe(true);
|
||||
await expect(page.locator(".clock .week")).toHaveText(weekRegex);
|
||||
});
|
||||
|
||||
it("should show the week with the correct number of week of year", async () => {
|
||||
const currentWeekNumber = moment().week();
|
||||
const weekToShow = `Week ${currentWeekNumber}`;
|
||||
const elem = await helpers.waitForElement(".clock .week");
|
||||
expect(elem).not.toBeNull();
|
||||
expect(elem.textContent).toBe(weekToShow);
|
||||
await expect(page.locator(".clock .week")).toHaveText(weekToShow);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -142,19 +141,18 @@ describe("Clock module", () => {
|
||||
beforeAll(async () => {
|
||||
await helpers.startApplication("tests/configs/modules/clock/clock_showWeek_short.js");
|
||||
await helpers.getDocument();
|
||||
page = helpers.getPage();
|
||||
});
|
||||
|
||||
it("should show the week in the correct format", async () => {
|
||||
const weekRegex = /^W[0-9]{1,2}$/;
|
||||
await expect(helpers.testMatch(".clock .week", weekRegex)).resolves.toBe(true);
|
||||
await expect(page.locator(".clock .week")).toHaveText(weekRegex);
|
||||
});
|
||||
|
||||
it("should show the week with the correct number of week of year", async () => {
|
||||
const currentWeekNumber = moment().week();
|
||||
const weekToShow = `W${currentWeekNumber}`;
|
||||
const elem = await helpers.waitForElement(".clock .week");
|
||||
expect(elem).not.toBeNull();
|
||||
expect(elem.textContent).toBe(weekToShow);
|
||||
await expect(page.locator(".clock .week")).toHaveText(weekToShow);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -162,11 +160,11 @@ describe("Clock module", () => {
|
||||
beforeAll(async () => {
|
||||
await helpers.startApplication("tests/configs/modules/clock/clock_analog.js");
|
||||
await helpers.getDocument();
|
||||
page = helpers.getPage();
|
||||
});
|
||||
|
||||
it("should show the analog clock face", async () => {
|
||||
const elem = await helpers.waitForElement(".clock-circle");
|
||||
expect(elem).not.toBeNull();
|
||||
await expect(page.locator(".clock-circle")).toBeVisible();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -174,13 +172,12 @@ describe("Clock module", () => {
|
||||
beforeAll(async () => {
|
||||
await helpers.startApplication("tests/configs/modules/clock/clock_showDateAnalog.js");
|
||||
await helpers.getDocument();
|
||||
page = helpers.getPage();
|
||||
});
|
||||
|
||||
it("should show the analog clock face and the date", async () => {
|
||||
const elemClock = await helpers.waitForElement(".clock-circle");
|
||||
await expect(elemClock).not.toBeNull();
|
||||
const elemDate = await helpers.waitForElement(".clock .date");
|
||||
await expect(elemDate).not.toBeNull();
|
||||
await expect(page.locator(".clock-circle")).toBeVisible();
|
||||
await expect(page.locator(".clock .date")).toBeVisible();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,19 +1,20 @@
|
||||
const { expect } = require("playwright/test");
|
||||
const helpers = require("../helpers/global-setup");
|
||||
|
||||
describe("Compliments module", () => {
|
||||
let page;
|
||||
|
||||
/**
|
||||
* move similar tests in function doTest
|
||||
* @param {Array} complimentsArray The array of compliments.
|
||||
* @returns {boolean} result
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
const doTest = async (complimentsArray) => {
|
||||
let elem = await helpers.waitForElement(".compliments");
|
||||
expect(elem).not.toBeNull();
|
||||
elem = await helpers.waitForElement(".module-content");
|
||||
expect(elem).not.toBeNull();
|
||||
expect(complimentsArray).toContain(elem.textContent);
|
||||
return true;
|
||||
await expect(page.locator(".compliments")).toBeVisible();
|
||||
const contentLocator = page.locator(".module-content");
|
||||
await contentLocator.waitFor({ state: "visible" });
|
||||
const content = await contentLocator.textContent();
|
||||
expect(complimentsArray).toContain(content);
|
||||
};
|
||||
|
||||
afterAll(async () => {
|
||||
@@ -25,10 +26,11 @@ describe("Compliments module", () => {
|
||||
beforeAll(async () => {
|
||||
await helpers.startApplication("tests/configs/modules/compliments/compliments_anytime.js");
|
||||
await helpers.getDocument();
|
||||
page = helpers.getPage();
|
||||
});
|
||||
|
||||
it("shows anytime because if configure empty parts of day compliments and set anytime compliments", async () => {
|
||||
await expect(doTest(["Anytime here"])).resolves.toBe(true);
|
||||
await doTest(["Anytime here"]);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -36,10 +38,11 @@ describe("Compliments module", () => {
|
||||
beforeAll(async () => {
|
||||
await helpers.startApplication("tests/configs/modules/compliments/compliments_only_anytime.js");
|
||||
await helpers.getDocument();
|
||||
page = helpers.getPage();
|
||||
});
|
||||
|
||||
it("shows anytime compliments", async () => {
|
||||
await expect(doTest(["Anytime here"])).resolves.toBe(true);
|
||||
await doTest(["Anytime here"]);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -48,10 +51,11 @@ describe("Compliments module", () => {
|
||||
beforeAll(async () => {
|
||||
await helpers.startApplication("tests/configs/modules/compliments/compliments_remote.js");
|
||||
await helpers.getDocument();
|
||||
page = helpers.getPage();
|
||||
});
|
||||
|
||||
it("should show compliments from a remote file", async () => {
|
||||
await expect(doTest(["Remote compliment file works!"])).resolves.toBe(true);
|
||||
await doTest(["Remote compliment file works!"]);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -60,10 +64,11 @@ describe("Compliments module", () => {
|
||||
beforeAll(async () => {
|
||||
await helpers.startApplication("tests/configs/modules/compliments/compliments_specialDayUnique_false.js");
|
||||
await helpers.getDocument();
|
||||
page = helpers.getPage();
|
||||
});
|
||||
|
||||
it("compliments array can contain all values", async () => {
|
||||
await expect(doTest(["Special day message", "Typical message 1", "Typical message 2", "Typical message 3"])).resolves.toBe(true);
|
||||
await doTest(["Special day message", "Typical message 1", "Typical message 2", "Typical message 3"]);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -71,10 +76,11 @@ describe("Compliments module", () => {
|
||||
beforeAll(async () => {
|
||||
await helpers.startApplication("tests/configs/modules/compliments/compliments_specialDayUnique_true.js");
|
||||
await helpers.getDocument();
|
||||
page = helpers.getPage();
|
||||
});
|
||||
|
||||
it("compliments array contains only special value", async () => {
|
||||
await expect(doTest(["Special day message"])).resolves.toBe(true);
|
||||
await doTest(["Special day message"]);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -82,10 +88,11 @@ describe("Compliments module", () => {
|
||||
beforeAll(async () => {
|
||||
await helpers.startApplication("tests/configs/modules/compliments/compliments_e2e_cron_entry.js");
|
||||
await helpers.getDocument();
|
||||
page = helpers.getPage();
|
||||
});
|
||||
|
||||
it("compliments array contains only special value", async () => {
|
||||
await expect(doTest(["anytime cron"])).resolves.toBe(true);
|
||||
await doTest(["anytime cron"]);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -95,10 +102,11 @@ describe("Compliments module", () => {
|
||||
beforeAll(async () => {
|
||||
await helpers.startApplication("tests/configs/modules/compliments/compliments_file.js");
|
||||
await helpers.getDocument();
|
||||
page = helpers.getPage();
|
||||
});
|
||||
it("shows 'Remote compliment file works!' as only anytime list set", async () => {
|
||||
//await helpers.startApplication("tests/configs/modules/compliments/compliments_file.js", "01 Jan 2022 10:00:00 GMT");
|
||||
await expect(doTest(["Remote compliment file works!"])).resolves.toBe(true);
|
||||
await doTest(["Remote compliment file works!"]);
|
||||
});
|
||||
// afterAll(async () =>{
|
||||
// await helpers.stopApplication()
|
||||
@@ -109,12 +117,13 @@ describe("Compliments module", () => {
|
||||
beforeAll(async () => {
|
||||
await helpers.startApplication("tests/configs/modules/compliments/compliments_file_change.js");
|
||||
await helpers.getDocument();
|
||||
page = helpers.getPage();
|
||||
});
|
||||
it("shows 'test in morning' as test time set to 10am", async () => {
|
||||
//await helpers.startApplication("tests/configs/modules/compliments/compliments_file_change.js", "01 Jan 2022 10:00:00 GMT");
|
||||
await expect(doTest(["Remote compliment file works!"])).resolves.toBe(true);
|
||||
await doTest(["Remote compliment file works!"]);
|
||||
await new Promise((r) => setTimeout(r, 10000));
|
||||
await expect(doTest(["test in morning"])).resolves.toBe(true);
|
||||
await doTest(["test in morning"]);
|
||||
});
|
||||
// afterAll(async () =>{
|
||||
// await helpers.stopApplication()
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
const { expect } = require("playwright/test");
|
||||
const helpers = require("../helpers/global-setup");
|
||||
|
||||
describe("Test helloworld module", () => {
|
||||
let page;
|
||||
|
||||
afterAll(async () => {
|
||||
await helpers.stopApplication();
|
||||
});
|
||||
@@ -9,12 +12,11 @@ describe("Test helloworld module", () => {
|
||||
beforeAll(async () => {
|
||||
await helpers.startApplication("tests/configs/modules/helloworld/helloworld.js");
|
||||
await helpers.getDocument();
|
||||
page = helpers.getPage();
|
||||
});
|
||||
|
||||
it("Test message helloworld module", async () => {
|
||||
const elem = await helpers.waitForElement(".helloworld");
|
||||
expect(elem).not.toBeNull();
|
||||
expect(elem.textContent).toContain("Test HelloWorld Module");
|
||||
await expect(page.locator(".helloworld")).toContainText("Test HelloWorld Module");
|
||||
});
|
||||
});
|
||||
|
||||
@@ -22,12 +24,11 @@ describe("Test helloworld module", () => {
|
||||
beforeAll(async () => {
|
||||
await helpers.startApplication("tests/configs/modules/helloworld/helloworld_default.js");
|
||||
await helpers.getDocument();
|
||||
page = helpers.getPage();
|
||||
});
|
||||
|
||||
it("Test message helloworld module", async () => {
|
||||
const elem = await helpers.waitForElement(".helloworld");
|
||||
expect(elem).not.toBeNull();
|
||||
expect(elem.textContent).toContain("Hello World!");
|
||||
await expect(page.locator(".helloworld")).toContainText("Hello World!");
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,29 +1,28 @@
|
||||
const fs = require("node:fs");
|
||||
const { expect } = require("playwright/test");
|
||||
const helpers = require("../helpers/global-setup");
|
||||
|
||||
const runTests = async () => {
|
||||
let page;
|
||||
|
||||
describe("Default configuration", () => {
|
||||
beforeAll(async () => {
|
||||
await helpers.startApplication("tests/configs/modules/newsfeed/default.js");
|
||||
await helpers.getDocument();
|
||||
page = helpers.getPage();
|
||||
});
|
||||
|
||||
it("should show the newsfeed title", async () => {
|
||||
const elem = await helpers.waitForElement(".newsfeed .newsfeed-source");
|
||||
expect(elem).not.toBeNull();
|
||||
expect(elem.textContent).toContain("Rodrigo Ramirez Blog");
|
||||
await expect(page.locator(".newsfeed .newsfeed-source")).toContainText("Rodrigo Ramirez Blog");
|
||||
});
|
||||
|
||||
it("should show the newsfeed article", async () => {
|
||||
const elem = await helpers.waitForElement(".newsfeed .newsfeed-title");
|
||||
expect(elem).not.toBeNull();
|
||||
expect(elem.textContent).toContain("QPanel");
|
||||
await expect(page.locator(".newsfeed .newsfeed-title")).toContainText("QPanel");
|
||||
});
|
||||
|
||||
it("should NOT show the newsfeed description", async () => {
|
||||
await helpers.waitForElement(".newsfeed");
|
||||
const elem = document.querySelector(".newsfeed .newsfeed-desc");
|
||||
expect(elem).toBeNull();
|
||||
await page.locator(".newsfeed").waitFor({ state: "visible" });
|
||||
await expect(page.locator(".newsfeed .newsfeed-desc")).toHaveCount(0);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -31,18 +30,18 @@ const runTests = async () => {
|
||||
beforeAll(async () => {
|
||||
await helpers.startApplication("tests/configs/modules/newsfeed/prohibited_words.js");
|
||||
await helpers.getDocument();
|
||||
page = helpers.getPage();
|
||||
});
|
||||
|
||||
it("should not show articles with prohibited words", async () => {
|
||||
const elem = await helpers.waitForElement(".newsfeed .newsfeed-title");
|
||||
expect(elem).not.toBeNull();
|
||||
expect(elem.textContent).toContain("Problema VirtualBox");
|
||||
await expect(page.locator(".newsfeed .newsfeed-title")).toContainText("Problema VirtualBox");
|
||||
});
|
||||
|
||||
it("should show the newsfeed description", async () => {
|
||||
const elem = await helpers.waitForElement(".newsfeed .newsfeed-desc");
|
||||
expect(elem).not.toBeNull();
|
||||
expect(elem.textContent).not.toHaveLength(0);
|
||||
const locator = page.locator(".newsfeed .newsfeed-desc");
|
||||
await expect(locator).toBeVisible();
|
||||
const text = await locator.textContent();
|
||||
expect(text).toMatch(/\S/);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -50,12 +49,11 @@ const runTests = async () => {
|
||||
beforeAll(async () => {
|
||||
await helpers.startApplication("tests/configs/modules/newsfeed/incorrect_url.js");
|
||||
await helpers.getDocument();
|
||||
page = helpers.getPage();
|
||||
});
|
||||
|
||||
it("should show malformed url warning", async () => {
|
||||
const elem = await helpers.waitForElement(".newsfeed .small", "No news at the moment.");
|
||||
expect(elem).not.toBeNull();
|
||||
expect(elem.textContent).toContain("Error in the Newsfeed module. Malformed url.");
|
||||
await expect(page.locator(".newsfeed .small")).toContainText("Error in the Newsfeed module. Malformed url.");
|
||||
});
|
||||
});
|
||||
|
||||
@@ -63,12 +61,11 @@ const runTests = async () => {
|
||||
beforeAll(async () => {
|
||||
await helpers.startApplication("tests/configs/modules/newsfeed/ignore_items.js");
|
||||
await helpers.getDocument();
|
||||
page = helpers.getPage();
|
||||
});
|
||||
|
||||
it("should show empty items info message", async () => {
|
||||
const elem = await helpers.waitForElement(".newsfeed .small");
|
||||
expect(elem).not.toBeNull();
|
||||
expect(elem.textContent).toContain("No news at the moment.");
|
||||
await expect(page.locator(".newsfeed .small")).toContainText("No news at the moment.");
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
const { expect } = require("playwright/test");
|
||||
const helpers = require("../helpers/global-setup");
|
||||
const weatherFunc = require("../helpers/weather-functions");
|
||||
|
||||
describe("Weather module", () => {
|
||||
let page;
|
||||
|
||||
afterAll(async () => {
|
||||
await weatherFunc.stopApplication();
|
||||
});
|
||||
@@ -10,26 +13,25 @@ describe("Weather module", () => {
|
||||
describe("Default configuration", () => {
|
||||
beforeAll(async () => {
|
||||
await weatherFunc.startApplication("tests/configs/modules/weather/currentweather_default.js", {});
|
||||
page = helpers.getPage();
|
||||
});
|
||||
|
||||
it("should render wind speed and wind direction", async () => {
|
||||
await expect(weatherFunc.getText(".weather .normal.medium span:nth-child(2)", "12 WSW")).resolves.toBe(true);
|
||||
await expect(page.locator(".weather .normal.medium span:nth-child(2)")).toHaveText("12 WSW");
|
||||
});
|
||||
|
||||
it("should render temperature with icon", async () => {
|
||||
await expect(weatherFunc.getText(".weather .large span.light.bright", "1.5°")).resolves.toBe(true);
|
||||
|
||||
const elem = await helpers.waitForElement(".weather .large span.weathericon");
|
||||
expect(elem).not.toBeNull();
|
||||
await expect(page.locator(".weather .large span.light.bright")).toHaveText("1.5°");
|
||||
await expect(page.locator(".weather .large span.weathericon")).toBeVisible();
|
||||
});
|
||||
|
||||
it("should render feels like temperature", async () => {
|
||||
// Template contains which renders as \xa0
|
||||
await expect(weatherFunc.getText(".weather .normal.medium.feelslike span.dimmed", "93.7\xa0 Feels like -5.6°")).resolves.toBe(true);
|
||||
await expect(page.locator(".weather .normal.medium.feelslike span.dimmed")).toHaveText("93.7\xa0 Feels like -5.6°");
|
||||
});
|
||||
|
||||
it("should render humidity next to feels-like", async () => {
|
||||
await expect(weatherFunc.getText(".weather .normal.medium.feelslike span.dimmed .humidity", "93.7")).resolves.toBe(true);
|
||||
await expect(page.locator(".weather .normal.medium.feelslike span.dimmed .humidity")).toHaveText("93.7");
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -37,56 +39,60 @@ describe("Weather module", () => {
|
||||
describe("Compliments Integration", () => {
|
||||
beforeAll(async () => {
|
||||
await weatherFunc.startApplication("tests/configs/modules/weather/currentweather_compliments.js", {});
|
||||
page = helpers.getPage();
|
||||
});
|
||||
|
||||
it("should render a compliment based on the current weather", async () => {
|
||||
await expect(weatherFunc.getText(".compliments .module-content span", "snow")).resolves.toBe(true);
|
||||
const compliment = page.locator(".compliments .module-content span");
|
||||
await compliment.waitFor({ state: "visible" });
|
||||
await expect(compliment).toHaveText("snow");
|
||||
});
|
||||
});
|
||||
|
||||
describe("Configuration Options", () => {
|
||||
beforeAll(async () => {
|
||||
await weatherFunc.startApplication("tests/configs/modules/weather/currentweather_options.js", {});
|
||||
page = helpers.getPage();
|
||||
});
|
||||
|
||||
it("should render windUnits in beaufort", async () => {
|
||||
await expect(weatherFunc.getText(".weather .normal.medium span:nth-child(2)", "6")).resolves.toBe(true);
|
||||
await expect(page.locator(".weather .normal.medium span:nth-child(2)")).toHaveText("6");
|
||||
});
|
||||
|
||||
it("should render windDirection with an arrow", async () => {
|
||||
const elem = await helpers.waitForElement(".weather .normal.medium sup i.fa-long-arrow-alt-down");
|
||||
expect(elem).not.toBeNull();
|
||||
expect(elem.outerHTML).toContain("transform:rotate(250deg)");
|
||||
const arrow = page.locator(".weather .normal.medium sup i.fa-long-arrow-alt-down");
|
||||
await expect(arrow).toHaveAttribute("style", "transform:rotate(250deg)");
|
||||
});
|
||||
|
||||
it("should render humidity next to wind", async () => {
|
||||
await expect(weatherFunc.getText(".weather .normal.medium .humidity", "93.7")).resolves.toBe(true);
|
||||
await expect(page.locator(".weather .normal.medium .humidity")).toHaveText("93.7");
|
||||
});
|
||||
|
||||
it("should render degreeLabel for temp", async () => {
|
||||
await expect(weatherFunc.getText(".weather .large span.bright.light", "1°C")).resolves.toBe(true);
|
||||
await expect(page.locator(".weather .large span.bright.light")).toHaveText("1°C");
|
||||
});
|
||||
|
||||
it("should render degreeLabel for feels like", async () => {
|
||||
await expect(weatherFunc.getText(".weather .normal.medium.feelslike span.dimmed", "Feels like -6°C")).resolves.toBe(true);
|
||||
await expect(page.locator(".weather .normal.medium.feelslike span.dimmed")).toHaveText("Feels like -6°C");
|
||||
});
|
||||
});
|
||||
|
||||
describe("Current weather with imperial units", () => {
|
||||
beforeAll(async () => {
|
||||
await weatherFunc.startApplication("tests/configs/modules/weather/currentweather_units.js", {});
|
||||
page = helpers.getPage();
|
||||
});
|
||||
|
||||
it("should render wind in imperial units", async () => {
|
||||
await expect(weatherFunc.getText(".weather .normal.medium span:nth-child(2)", "26 WSW")).resolves.toBe(true);
|
||||
await expect(page.locator(".weather .normal.medium span:nth-child(2)")).toHaveText("26 WSW");
|
||||
});
|
||||
|
||||
it("should render temperatures in fahrenheit", async () => {
|
||||
await expect(weatherFunc.getText(".weather .large span.bright.light", "34,7°")).resolves.toBe(true);
|
||||
await expect(page.locator(".weather .large span.bright.light")).toHaveText("34,7°");
|
||||
});
|
||||
|
||||
it("should render 'feels like' in fahrenheit", async () => {
|
||||
await expect(weatherFunc.getText(".weather .normal.medium.feelslike span.dimmed", "Feels like 21,9°")).resolves.toBe(true);
|
||||
await expect(page.locator(".weather .normal.medium.feelslike span.dimmed")).toHaveText("Feels like 21,9°");
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
const { expect } = require("playwright/test");
|
||||
const helpers = require("../helpers/global-setup");
|
||||
const weatherFunc = require("../helpers/weather-functions");
|
||||
|
||||
describe("Weather module: Weather Forecast", () => {
|
||||
let page;
|
||||
|
||||
afterAll(async () => {
|
||||
await weatherFunc.stopApplication();
|
||||
});
|
||||
@@ -9,43 +12,46 @@ describe("Weather module: Weather Forecast", () => {
|
||||
describe("Default configuration", () => {
|
||||
beforeAll(async () => {
|
||||
await weatherFunc.startApplication("tests/configs/modules/weather/forecastweather_default.js", {});
|
||||
page = helpers.getPage();
|
||||
});
|
||||
|
||||
const days = ["Today", "Tomorrow", "Sun", "Mon", "Tue"];
|
||||
for (const [index, day] of days.entries()) {
|
||||
it(`should render day ${day}`, async () => {
|
||||
await expect(weatherFunc.getText(`.weather table.small tr:nth-child(${index + 1}) td:nth-child(1)`, day)).resolves.toBe(true);
|
||||
const dayCell = page.locator(`.weather table.small tr:nth-child(${index + 1}) td:nth-child(1)`);
|
||||
await expect(dayCell).toHaveText(day);
|
||||
});
|
||||
}
|
||||
|
||||
const icons = ["day-cloudy", "rain", "day-sunny", "day-sunny", "day-sunny"];
|
||||
for (const [index, icon] of icons.entries()) {
|
||||
it(`should render icon ${icon}`, async () => {
|
||||
const elem = await helpers.waitForElement(`.weather table.small tr:nth-child(${index + 1}) td:nth-child(2) span.wi-${icon}`);
|
||||
expect(elem).not.toBeNull();
|
||||
const iconElement = page.locator(`.weather table.small tr:nth-child(${index + 1}) td:nth-child(2) span.wi-${icon}`);
|
||||
await expect(iconElement).toBeVisible();
|
||||
});
|
||||
}
|
||||
|
||||
const maxTemps = ["24.4°", "21.0°", "22.9°", "23.4°", "20.6°"];
|
||||
for (const [index, temp] of maxTemps.entries()) {
|
||||
it(`should render max temperature ${temp}`, async () => {
|
||||
await expect(weatherFunc.getText(`.weather table.small tr:nth-child(${index + 1}) td:nth-child(3)`, temp)).resolves.toBe(true);
|
||||
const maxTempCell = page.locator(`.weather table.small tr:nth-child(${index + 1}) td:nth-child(3)`);
|
||||
await expect(maxTempCell).toHaveText(temp);
|
||||
});
|
||||
}
|
||||
|
||||
const minTemps = ["15.3°", "13.6°", "13.8°", "13.9°", "10.9°"];
|
||||
for (const [index, temp] of minTemps.entries()) {
|
||||
it(`should render min temperature ${temp}`, async () => {
|
||||
await expect(weatherFunc.getText(`.weather table.small tr:nth-child(${index + 1}) td:nth-child(4)`, temp)).resolves.toBe(true);
|
||||
const minTempCell = page.locator(`.weather table.small tr:nth-child(${index + 1}) td:nth-child(4)`);
|
||||
await expect(minTempCell).toHaveText(temp);
|
||||
});
|
||||
}
|
||||
|
||||
const opacities = [1, 1, 0.8, 0.5333333333333333, 0.2666666666666667];
|
||||
for (const [index, opacity] of opacities.entries()) {
|
||||
it(`should render fading of rows with opacity=${opacity}`, async () => {
|
||||
const elem = await helpers.waitForElement(`.weather table.small tr:nth-child(${index + 1})`);
|
||||
expect(elem).not.toBeNull();
|
||||
expect(elem.outerHTML).toContain(`<tr style="opacity: ${opacity};">`);
|
||||
const row = page.locator(`.weather table.small tr:nth-child(${index + 1})`);
|
||||
await expect(row).toHaveAttribute("style", `opacity: ${opacity};`);
|
||||
});
|
||||
}
|
||||
});
|
||||
@@ -53,12 +59,14 @@ describe("Weather module: Weather Forecast", () => {
|
||||
describe("Absolute configuration", () => {
|
||||
beforeAll(async () => {
|
||||
await weatherFunc.startApplication("tests/configs/modules/weather/forecastweather_absolute.js", {});
|
||||
page = helpers.getPage();
|
||||
});
|
||||
|
||||
const days = ["Fri", "Sat", "Sun", "Mon", "Tue"];
|
||||
for (const [index, day] of days.entries()) {
|
||||
it(`should render day ${day}`, async () => {
|
||||
await expect(weatherFunc.getText(`.weather table.small tr:nth-child(${index + 1}) td:nth-child(1)`, day)).resolves.toBe(true);
|
||||
const dayCell = page.locator(`.weather table.small tr:nth-child(${index + 1}) td:nth-child(1)`);
|
||||
await expect(dayCell).toHaveText(day);
|
||||
});
|
||||
}
|
||||
});
|
||||
@@ -66,25 +74,24 @@ describe("Weather module: Weather Forecast", () => {
|
||||
describe("Configuration Options", () => {
|
||||
beforeAll(async () => {
|
||||
await weatherFunc.startApplication("tests/configs/modules/weather/forecastweather_options.js", {});
|
||||
page = helpers.getPage();
|
||||
});
|
||||
|
||||
it("should render custom table class", async () => {
|
||||
const elem = await helpers.waitForElement(".weather table.myTableClass");
|
||||
expect(elem).not.toBeNull();
|
||||
await expect(page.locator(".weather table.myTableClass")).toBeVisible();
|
||||
});
|
||||
|
||||
it("should render colored rows", async () => {
|
||||
const table = await helpers.waitForElement(".weather table.myTableClass");
|
||||
expect(table).not.toBeNull();
|
||||
expect(table.rows).not.toBeNull();
|
||||
expect(table.rows).toHaveLength(5);
|
||||
const rows = page.locator(".weather table.myTableClass tr");
|
||||
await expect(rows).toHaveCount(5);
|
||||
});
|
||||
|
||||
const precipitations = [undefined, "2.51 mm"];
|
||||
for (const [index, precipitation] of precipitations.entries()) {
|
||||
if (precipitation) {
|
||||
it(`should render precipitation amount ${precipitation}`, async () => {
|
||||
await expect(weatherFunc.getText(`.weather table tr:nth-child(${index + 1}) td.precipitation-amount`, precipitation)).resolves.toBe(true);
|
||||
const precipCell = page.locator(`.weather table tr:nth-child(${index + 1}) td.precipitation-amount`);
|
||||
await expect(precipCell).toHaveText(precipitation);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -93,13 +100,15 @@ describe("Weather module: Weather Forecast", () => {
|
||||
describe("Forecast weather with imperial units", () => {
|
||||
beforeAll(async () => {
|
||||
await weatherFunc.startApplication("tests/configs/modules/weather/forecastweather_units.js", {});
|
||||
page = helpers.getPage();
|
||||
});
|
||||
|
||||
describe("Temperature units", () => {
|
||||
const temperatures = ["75_9°", "69_8°", "73_2°", "74_1°", "69_1°"];
|
||||
for (const [index, temp] of temperatures.entries()) {
|
||||
it(`should render custom decimalSymbol = '_' for temp ${temp}`, async () => {
|
||||
await expect(weatherFunc.getText(`.weather table.small tr:nth-child(${index + 1}) td:nth-child(3)`, temp)).resolves.toBe(true);
|
||||
const tempCell = page.locator(`.weather table.small tr:nth-child(${index + 1}) td:nth-child(3)`);
|
||||
await expect(tempCell).toHaveText(temp);
|
||||
});
|
||||
}
|
||||
});
|
||||
@@ -109,7 +118,8 @@ describe("Weather module: Weather Forecast", () => {
|
||||
for (const [index, precipitation] of precipitations.entries()) {
|
||||
if (precipitation) {
|
||||
it(`should render precipitation amount ${precipitation}`, async () => {
|
||||
await expect(weatherFunc.getText(`.weather table.small tr:nth-child(${index + 1}) td.precipitation-amount`, precipitation)).resolves.toBe(true);
|
||||
const precipCell = page.locator(`.weather table.small tr:nth-child(${index + 1}) td.precipitation-amount`);
|
||||
await expect(precipCell).toHaveText(precipitation);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
const { expect } = require("playwright/test");
|
||||
const helpers = require("../helpers/global-setup");
|
||||
const weatherFunc = require("../helpers/weather-functions");
|
||||
|
||||
describe("Weather module: Weather Hourly Forecast", () => {
|
||||
let page;
|
||||
|
||||
afterAll(async () => {
|
||||
await weatherFunc.stopApplication();
|
||||
});
|
||||
@@ -8,12 +12,14 @@ describe("Weather module: Weather Hourly Forecast", () => {
|
||||
describe("Default configuration", () => {
|
||||
beforeAll(async () => {
|
||||
await weatherFunc.startApplication("tests/configs/modules/weather/hourlyweather_default.js", {});
|
||||
page = helpers.getPage();
|
||||
});
|
||||
|
||||
const minTemps = ["7:00 pm", "8:00 pm", "9:00 pm", "10:00 pm", "11:00 pm"];
|
||||
for (const [index, hour] of minTemps.entries()) {
|
||||
it(`should render forecast for hour ${hour}`, async () => {
|
||||
await expect(weatherFunc.getText(`.weather table.small tr:nth-child(${index + 1}) td.day`, hour)).resolves.toBe(true);
|
||||
const dayCell = page.locator(`.weather table.small tr:nth-child(${index + 1}) td.day`);
|
||||
await expect(dayCell).toHaveText(hour);
|
||||
});
|
||||
}
|
||||
});
|
||||
@@ -21,13 +27,15 @@ describe("Weather module: Weather Hourly Forecast", () => {
|
||||
describe("Hourly weather options", () => {
|
||||
beforeAll(async () => {
|
||||
await weatherFunc.startApplication("tests/configs/modules/weather/hourlyweather_options.js", {});
|
||||
page = helpers.getPage();
|
||||
});
|
||||
|
||||
describe("Hourly increments of 2", () => {
|
||||
const minTemps = ["7:00 pm", "9:00 pm", "11:00 pm", "1:00 am", "3:00 am"];
|
||||
for (const [index, hour] of minTemps.entries()) {
|
||||
it(`should render forecast for hour ${hour}`, async () => {
|
||||
await expect(weatherFunc.getText(`.weather table.small tr:nth-child(${index + 1}) td.day`, hour)).resolves.toBe(true);
|
||||
const dayCell = page.locator(`.weather table.small tr:nth-child(${index + 1}) td.day`);
|
||||
await expect(dayCell).toHaveText(hour);
|
||||
});
|
||||
}
|
||||
});
|
||||
@@ -36,6 +44,7 @@ describe("Weather module: Weather Hourly Forecast", () => {
|
||||
describe("Show precipitations", () => {
|
||||
beforeAll(async () => {
|
||||
await weatherFunc.startApplication("tests/configs/modules/weather/hourlyweather_showPrecipitation.js", {});
|
||||
page = helpers.getPage();
|
||||
});
|
||||
|
||||
describe("Shows precipitation amount", () => {
|
||||
@@ -43,7 +52,8 @@ describe("Weather module: Weather Hourly Forecast", () => {
|
||||
for (const [index, amount] of amounts.entries()) {
|
||||
if (amount) {
|
||||
it(`should render precipitation amount ${amount}`, async () => {
|
||||
await expect(weatherFunc.getText(`.weather table.small tr:nth-child(${index + 1}) td.precipitation-amount`, amount)).resolves.toBe(true);
|
||||
const amountCell = page.locator(`.weather table.small tr:nth-child(${index + 1}) td.precipitation-amount`);
|
||||
await expect(amountCell).toHaveText(amount);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -51,10 +61,11 @@ describe("Weather module: Weather Hourly Forecast", () => {
|
||||
|
||||
describe("Shows precipitation probability", () => {
|
||||
const probabilities = [undefined, undefined, "12 %", "36 %", "44 %"];
|
||||
for (const [index, pop] of probabilities.entries()) {
|
||||
if (pop) {
|
||||
it(`should render probability ${pop}`, async () => {
|
||||
await expect(weatherFunc.getText(`.weather table.small tr:nth-child(${index + 1}) td.precipitation-prob`, pop)).resolves.toBe(true);
|
||||
for (const [index, probability] of probabilities.entries()) {
|
||||
if (probability) {
|
||||
it(`should render probability ${probability}`, async () => {
|
||||
const probabilityCell = page.locator(`.weather table.small tr:nth-child(${index + 1}) td.precipitation-prob`);
|
||||
await expect(probabilityCell).toHaveText(probability);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user