-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Split weather tests into current and forecast
- Loading branch information
veeck
committed
Aug 30, 2022
1 parent
c4bc3a6
commit 5c09bdd
Showing
2 changed files
with
143 additions
and
98 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,143 @@ | ||
const moment = require("moment"); | ||
const helpers = require("../global-setup"); | ||
const path = require("path"); | ||
const fs = require("fs"); | ||
const { generateWeather, generateWeatherForecast } = require("./mocks"); | ||
|
||
describe("Weather module", function () { | ||
/** | ||
* @param {string} element css selector | ||
* @param {string} result Expected text in given selector | ||
*/ | ||
function getText(element, result) { | ||
helpers.waitForElement(element).then((elem) => { | ||
expect(elem).not.toBe(null); | ||
expect( | ||
elem.textContent | ||
.trim() | ||
.replace(/(\r\n|\n|\r)/gm, "") | ||
.replace(/[ ]+/g, " ") | ||
).toBe(result); | ||
}); | ||
} | ||
|
||
/** | ||
* @param {string} configFile path to configuration file | ||
* @param {string} additionalMockData special data for mocking | ||
* @param {string} callback callback | ||
*/ | ||
function startApp(configFile, additionalMockData, callback) { | ||
let mockWeather; | ||
if (configFile.includes("forecast")) { | ||
mockWeather = generateWeatherForecast(additionalMockData); | ||
} else { | ||
mockWeather = generateWeather(additionalMockData); | ||
} | ||
let content = fs.readFileSync(path.resolve(__dirname + "../../../../" + configFile)).toString(); | ||
content = content.replace("#####WEATHERDATA#####", mockWeather); | ||
fs.writeFileSync(path.resolve(__dirname + "../../../../config/config.js"), content); | ||
helpers.startApplication(""); | ||
helpers.getDocument(callback); | ||
} | ||
|
||
afterAll(async function () { | ||
await helpers.stopApplication(); | ||
}); | ||
|
||
describe("Current weather", function () { | ||
describe("Default configuration", function () { | ||
beforeAll(function (done) { | ||
const sunrise = moment().startOf("day").unix(); | ||
const sunset = moment().endOf("day").unix(); | ||
startApp("tests/configs/modules/weather/currentweather_default.js", { sys: { sunrise, sunset } }, done); | ||
}); | ||
|
||
it("should render wind speed and wind direction", function () { | ||
getText(".weather .normal.medium span:nth-child(2)", "6 WSW"); | ||
}); | ||
|
||
it("should render temperature with icon", function () { | ||
getText(".weather .large.light span.bright", "1.5°"); | ||
}); | ||
|
||
it("should render feels like temperature", function () { | ||
getText(".weather .normal.medium.feelslike span.dimmed", "Feels like -5.6°"); | ||
}); | ||
|
||
it("should render sunrise", function () { | ||
getText(".weather .normal.medium span:nth-child(4)", "12:00 am"); | ||
}); | ||
|
||
it("should render sunset", function () { | ||
getText(".weather .normal.medium span:nth-child(4)", "11:59 pm"); | ||
}); | ||
}); | ||
}); | ||
|
||
describe("Compliments Integration", function () { | ||
beforeAll(function (done) { | ||
startApp("tests/configs/modules/weather/currentweather_compliments.js", {}, done); | ||
}); | ||
|
||
it("should render a compliment based on the current weather", function () { | ||
getText(".compliments .module-content span", "snow"); | ||
}); | ||
}); | ||
|
||
describe("Configuration Options", function () { | ||
beforeAll(function (done) { | ||
startApp("tests/configs/modules/weather/currentweather_options.js", {}, done); | ||
}); | ||
|
||
it("should render useBeaufort = false", function () { | ||
getText(".weather .normal.medium span:nth-child(2)", "12"); | ||
}); | ||
|
||
it("should render showWindDirectionAsArrow = true", function () { | ||
helpers.waitForElement(".weather .normal.medium sup i.fa-long-arrow-alt-up").then((elem) => { | ||
expect(elem).not.toBe(null); | ||
expect(elem.outerHTML).toContain("transform:rotate(250deg);"); | ||
}); | ||
}); | ||
|
||
it("should render showHumidity = true", function () { | ||
getText(".weather .normal.medium span:nth-child(3)", "93.7"); | ||
}); | ||
|
||
it("should render degreeLabel = true", function () { | ||
getText(".weather .large.light span.bright", "1°C"); | ||
getText(".weather .normal.medium.feelslike span.dimmed", "Feels like -6°C"); | ||
}); | ||
}); | ||
|
||
describe("Current weather units", function () { | ||
beforeAll(function (done) { | ||
startApp( | ||
"tests/configs/modules/weather/currentweather_units.js", | ||
{ | ||
main: { | ||
temp: (1.49 * 9) / 5 + 32, | ||
temp_min: (1 * 9) / 5 + 32, | ||
temp_max: (2 * 9) / 5 + 32 | ||
}, | ||
wind: { | ||
speed: 11.8 * 2.23694 | ||
} | ||
}, | ||
done | ||
); | ||
}); | ||
|
||
it("should render imperial units", function () { | ||
getText(".weather .normal.medium span:nth-child(2)", "6 WSW"); | ||
getText(".weather .large.light span.bright", "34,7°"); | ||
getText(".weather .normal.medium.feelslike span.dimmed", "Feels like 22,0°"); | ||
}); | ||
|
||
it("should render custom decimalSymbol = ','", function () { | ||
getText(".weather .normal.medium span:nth-child(3)", "93,7"); | ||
getText(".weather .large.light span.bright", "34,7°"); | ||
getText(".weather .normal.medium.feelslike span.dimmed", "Feels like 22,0°"); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters