Skip to content

Commit 02e76da

Browse files
refactor: extract constants for weather electron tests (#3845)
I find the tests with clear variable names much easier to understand.
1 parent 7f8935a commit 02e76da

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ Thanks to: @dathbe.
1919
- [core] Enhance system information logging format and include additional env and RAM details (#3839, #3843)
2020
- [refactor] Add new file `js/module_functions.js` to move code used in several modules to one place (#3837)
2121
- [tests] refactor: simplify jest config file (#3844)
22+
- [tests] refactor: extract constants for weather electron tests (#3845)
2223

2324
### Updated
2425

tests/electron/modules/weather_spec.js

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@ const helpers = require("../helpers/global-setup");
22
const weatherHelper = require("../helpers/weather-setup");
33
const { cleanupMockData } = require("../../utils/weather_mocker");
44

5+
const CURRENT_WEATHER_CONFIG = "tests/configs/modules/weather/currentweather_default.js";
6+
const SUNRISE_DATE = "13 Jan 2019 00:30:00 GMT";
7+
const SUNSET_DATE = "13 Jan 2019 12:30:00 GMT";
8+
const SUN_EVENT_SELECTOR = ".weather .normal.medium span:nth-child(4)";
9+
const EXPECTED_SUNRISE_TEXT = "7:00 am";
10+
const EXPECTED_SUNSET_TEXT = "3:45 pm";
11+
512
describe("Weather module", () => {
613
afterEach(async () => {
714
await helpers.stopApplication();
@@ -10,21 +17,23 @@ describe("Weather module", () => {
1017

1118
describe("Current weather with sunrise", () => {
1219
beforeAll(async () => {
13-
await weatherHelper.startApp("tests/configs/modules/weather/currentweather_default.js", "13 Jan 2019 00:30:00 GMT");
20+
await weatherHelper.startApp(CURRENT_WEATHER_CONFIG, SUNRISE_DATE);
1421
});
1522

1623
it("should render sunrise", async () => {
17-
await expect(weatherHelper.getText(".weather .normal.medium span:nth-child(4)", "7:00 am")).resolves.toBe(true);
24+
const isSunriseRendered = await weatherHelper.getText(SUN_EVENT_SELECTOR, EXPECTED_SUNRISE_TEXT);
25+
expect(isSunriseRendered).toBe(true);
1826
});
1927
});
2028

2129
describe("Current weather with sunset", () => {
2230
beforeAll(async () => {
23-
await weatherHelper.startApp("tests/configs/modules/weather/currentweather_default.js", "13 Jan 2019 12:30:00 GMT");
31+
await weatherHelper.startApp(CURRENT_WEATHER_CONFIG, SUNSET_DATE);
2432
});
2533

2634
it("should render sunset", async () => {
27-
await expect(weatherHelper.getText(".weather .normal.medium span:nth-child(4)", "3:45 pm")).resolves.toBe(true);
35+
const isSunsetRendered = await weatherHelper.getText(SUN_EVENT_SELECTOR, EXPECTED_SUNSET_TEXT);
36+
expect(isSunsetRendered).toBe(true);
2837
});
2938
});
3039
});

0 commit comments

Comments
 (0)