mirror of
https://github.com/MichMich/MagicMirror.git
synced 2025-12-12 01:42:19 +00:00
### 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
99 lines
3.6 KiB
JavaScript
99 lines
3.6 KiB
JavaScript
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();
|
|
});
|
|
|
|
describe("Current weather", () => {
|
|
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(page.locator(".weather .normal.medium span:nth-child(2)")).toHaveText("12 WSW");
|
|
});
|
|
|
|
it("should render temperature with icon", async () => {
|
|
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(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(page.locator(".weather .normal.medium.feelslike span.dimmed .humidity")).toHaveText("93.7");
|
|
});
|
|
});
|
|
});
|
|
|
|
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 () => {
|
|
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(page.locator(".weather .normal.medium span:nth-child(2)")).toHaveText("6");
|
|
});
|
|
|
|
it("should render windDirection with an arrow", async () => {
|
|
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(page.locator(".weather .normal.medium .humidity")).toHaveText("93.7");
|
|
});
|
|
|
|
it("should render degreeLabel for temp", async () => {
|
|
await expect(page.locator(".weather .large span.bright.light")).toHaveText("1°C");
|
|
});
|
|
|
|
it("should render degreeLabel for feels like", async () => {
|
|
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(page.locator(".weather .normal.medium span:nth-child(2)")).toHaveText("26 WSW");
|
|
});
|
|
|
|
it("should render temperatures in fahrenheit", async () => {
|
|
await expect(page.locator(".weather .large span.bright.light")).toHaveText("34,7°");
|
|
});
|
|
|
|
it("should render 'feels like' in fahrenheit", async () => {
|
|
await expect(page.locator(".weather .normal.medium.feelslike span.dimmed")).toHaveText("Feels like 21,9°");
|
|
});
|
|
});
|
|
});
|