2025-11-08 21:59:05 +01:00
|
|
|
const { expect } = require("playwright/test");
|
2023-01-01 18:09:08 +01:00
|
|
|
const helpers = require("../helpers/global-setup");
|
|
|
|
|
const weatherFunc = require("../helpers/weather-functions");
|
|
|
|
|
|
|
|
|
|
describe("Weather module: Weather Forecast", () => {
|
2025-11-08 21:59:05 +01:00
|
|
|
let page;
|
|
|
|
|
|
2023-01-01 18:09:08 +01:00
|
|
|
afterAll(async () => {
|
2025-07-20 08:23:52 +02:00
|
|
|
await weatherFunc.stopApplication();
|
2023-01-01 18:09:08 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
describe("Default configuration", () => {
|
|
|
|
|
beforeAll(async () => {
|
2026-02-23 10:27:29 +01:00
|
|
|
await weatherFunc.startApplication("tests/configs/modules/weather/forecastweather_default.js", "weather_onecall_forecast.json");
|
2025-11-08 21:59:05 +01:00
|
|
|
page = helpers.getPage();
|
2023-01-01 18:09:08 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const days = ["Today", "Tomorrow", "Sun", "Mon", "Tue"];
|
|
|
|
|
for (const [index, day] of days.entries()) {
|
2023-04-04 20:44:32 +02:00
|
|
|
it(`should render day ${day}`, async () => {
|
2025-11-08 21:59:05 +01:00
|
|
|
const dayCell = page.locator(`.weather table.small tr:nth-child(${index + 1}) td:nth-child(1)`);
|
|
|
|
|
await expect(dayCell).toHaveText(day);
|
2023-01-01 18:09:08 +01:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const icons = ["day-cloudy", "rain", "day-sunny", "day-sunny", "day-sunny"];
|
|
|
|
|
for (const [index, icon] of icons.entries()) {
|
2023-04-04 20:44:32 +02:00
|
|
|
it(`should render icon ${icon}`, async () => {
|
2025-11-08 21:59:05 +01:00
|
|
|
const iconElement = page.locator(`.weather table.small tr:nth-child(${index + 1}) td:nth-child(2) span.wi-${icon}`);
|
|
|
|
|
await expect(iconElement).toBeVisible();
|
2023-01-01 18:09:08 +01:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const maxTemps = ["24.4°", "21.0°", "22.9°", "23.4°", "20.6°"];
|
|
|
|
|
for (const [index, temp] of maxTemps.entries()) {
|
2023-04-04 20:44:32 +02:00
|
|
|
it(`should render max temperature ${temp}`, async () => {
|
2025-11-08 21:59:05 +01:00
|
|
|
const maxTempCell = page.locator(`.weather table.small tr:nth-child(${index + 1}) td:nth-child(3)`);
|
|
|
|
|
await expect(maxTempCell).toHaveText(temp);
|
2023-01-01 18:09:08 +01:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const minTemps = ["15.3°", "13.6°", "13.8°", "13.9°", "10.9°"];
|
|
|
|
|
for (const [index, temp] of minTemps.entries()) {
|
2023-04-04 20:44:32 +02:00
|
|
|
it(`should render min temperature ${temp}`, async () => {
|
2025-11-08 21:59:05 +01:00
|
|
|
const minTempCell = page.locator(`.weather table.small tr:nth-child(${index + 1}) td:nth-child(4)`);
|
|
|
|
|
await expect(minTempCell).toHaveText(temp);
|
2023-01-01 18:09:08 +01:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const opacities = [1, 1, 0.8, 0.5333333333333333, 0.2666666666666667];
|
|
|
|
|
for (const [index, opacity] of opacities.entries()) {
|
2023-04-04 20:44:32 +02:00
|
|
|
it(`should render fading of rows with opacity=${opacity}`, async () => {
|
2025-11-08 21:59:05 +01:00
|
|
|
const row = page.locator(`.weather table.small tr:nth-child(${index + 1})`);
|
|
|
|
|
await expect(row).toHaveAttribute("style", `opacity: ${opacity};`);
|
2023-01-01 18:09:08 +01:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
describe("Absolute configuration", () => {
|
|
|
|
|
beforeAll(async () => {
|
2026-02-23 10:27:29 +01:00
|
|
|
await weatherFunc.startApplication("tests/configs/modules/weather/forecastweather_absolute.js", "weather_onecall_forecast.json");
|
2025-11-08 21:59:05 +01:00
|
|
|
page = helpers.getPage();
|
2023-01-01 18:09:08 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const days = ["Fri", "Sat", "Sun", "Mon", "Tue"];
|
|
|
|
|
for (const [index, day] of days.entries()) {
|
2023-04-04 20:44:32 +02:00
|
|
|
it(`should render day ${day}`, async () => {
|
2025-11-08 21:59:05 +01:00
|
|
|
const dayCell = page.locator(`.weather table.small tr:nth-child(${index + 1}) td:nth-child(1)`);
|
|
|
|
|
await expect(dayCell).toHaveText(day);
|
2023-01-01 18:09:08 +01:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
describe("Configuration Options", () => {
|
|
|
|
|
beforeAll(async () => {
|
2026-02-23 10:27:29 +01:00
|
|
|
await weatherFunc.startApplication("tests/configs/modules/weather/forecastweather_options.js", "weather_onecall_forecast.json");
|
2025-11-08 21:59:05 +01:00
|
|
|
page = helpers.getPage();
|
2023-01-01 18:09:08 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("should render custom table class", async () => {
|
2025-11-08 21:59:05 +01:00
|
|
|
await expect(page.locator(".weather table.myTableClass")).toBeVisible();
|
2023-01-01 18:09:08 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("should render colored rows", async () => {
|
2025-11-08 21:59:05 +01:00
|
|
|
const rows = page.locator(".weather table.myTableClass tr");
|
|
|
|
|
await expect(rows).toHaveCount(5);
|
2023-01-01 18:09:08 +01:00
|
|
|
});
|
2023-04-04 20:44:32 +02:00
|
|
|
|
|
|
|
|
const precipitations = [undefined, "2.51 mm"];
|
|
|
|
|
for (const [index, precipitation] of precipitations.entries()) {
|
|
|
|
|
if (precipitation) {
|
|
|
|
|
it(`should render precipitation amount ${precipitation}`, async () => {
|
2025-11-08 21:59:05 +01:00
|
|
|
const precipCell = page.locator(`.weather table tr:nth-child(${index + 1}) td.precipitation-amount`);
|
|
|
|
|
await expect(precipCell).toHaveText(precipitation);
|
2023-04-04 20:44:32 +02:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-01-01 18:09:08 +01:00
|
|
|
});
|
|
|
|
|
|
2023-04-04 20:44:32 +02:00
|
|
|
describe("Forecast weather with imperial units", () => {
|
2023-01-01 18:09:08 +01:00
|
|
|
beforeAll(async () => {
|
2026-02-23 10:27:29 +01:00
|
|
|
await weatherFunc.startApplication("tests/configs/modules/weather/forecastweather_units.js", "weather_onecall_forecast.json");
|
2025-11-08 21:59:05 +01:00
|
|
|
page = helpers.getPage();
|
2023-01-01 18:09:08 +01:00
|
|
|
});
|
|
|
|
|
|
2023-04-04 20:44:32 +02:00
|
|
|
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 () => {
|
2025-11-08 21:59:05 +01:00
|
|
|
const tempCell = page.locator(`.weather table.small tr:nth-child(${index + 1}) td:nth-child(3)`);
|
|
|
|
|
await expect(tempCell).toHaveText(temp);
|
2023-04-04 20:44:32 +02:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
describe("Precipitation units", () => {
|
|
|
|
|
const precipitations = [undefined, "0.10 in"];
|
|
|
|
|
for (const [index, precipitation] of precipitations.entries()) {
|
|
|
|
|
if (precipitation) {
|
|
|
|
|
it(`should render precipitation amount ${precipitation}`, async () => {
|
2025-11-08 21:59:05 +01:00
|
|
|
const precipCell = page.locator(`.weather table.small tr:nth-child(${index + 1}) td.precipitation-amount`);
|
|
|
|
|
await expect(precipCell).toHaveText(precipitation);
|
2023-04-04 20:44:32 +02:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
2023-01-01 18:09:08 +01:00
|
|
|
});
|
|
|
|
|
});
|