-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
/
Copy pathweather_spec.js
270 lines (201 loc) · 8.89 KB
/
weather_spec.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
const expect = require("chai").expect;
const fs = require("fs");
const moment = require("moment");
const path = require("path");
const wdajaxstub = require("webdriverajaxstub");
const helpers = require("../global-setup");
const {generateWeather, generateWeatherForecast} = require("./mocks");
const wait = () => new Promise(res => setTimeout(res, 3000));
describe("Weather module", function() {
let app;
helpers.setupTimeout(this);
async function setup(responses) {
app = await helpers.startApplication({
args: ["js/electron.js"]
});
wdajaxstub.init(app.client, responses);
app.client.setupStub();
}
afterEach(function() {
return helpers.stopApplication(app);
});
describe("Current weather", function() {
let template;
before(function() {
template = fs.readFileSync(path.join(__dirname, "..", "..", "..", "modules", "default", "weather", "current.njk"), "utf8");
});
describe("Default configuration", function() {
before(function() {
process.env.MM_CONFIG_FILE = "tests/configs/modules/weather/currentweather_default.js";
});
it("should render wind speed and wind direction", async function() {
const weather = generateWeather();
await setup([weather, template]);
return app.client.waitUntilTextExists(".weather .normal.medium span:nth-child(2)", "6 WSW", 10000);
});
it("should render sunrise", async function() {
const sunrise = moment().startOf("day").unix();
const sunset = moment().startOf("day").unix();
const weather = generateWeather({sys: {sunrise, sunset}});
await setup([weather, template]);
await app.client.waitForExist(".weather .normal.medium span.wi.dimmed.wi-sunrise", 10000);
return app.client.waitUntilTextExists(".weather .normal.medium span:nth-child(4)", "12:00 am", 10000);
});
it("should render sunset", async function() {
const sunrise = moment().startOf("day").unix();
const sunset = moment().endOf("day").unix();
const weather = generateWeather({sys: {sunrise, sunset}});
await setup([weather, template]);
await app.client.waitForExist(".weather .normal.medium span.wi.dimmed.wi-sunset", 10000);
return app.client.waitUntilTextExists(".weather .normal.medium span:nth-child(4)", "11:59 pm", 10000);
});
it("should render temperature with icon", async function() {
const weather = generateWeather();
await setup([weather, template]);
await app.client.waitForExist(".weather .large.light span.wi.weathericon.wi-snow", 10000);
return app.client.waitUntilTextExists(".weather .large.light span.bright", "1.5°", 10000);
});
it("should render feels like temperature", async function() {
const weather = generateWeather();
await setup([weather, template]);
return app.client.waitUntilTextExists(".weather .normal.medium span.dimmed", "Feels like -5.6°", 10000);
});
});
describe("Configuration Options", function() {
before(function() {
process.env.MM_CONFIG_FILE = "tests/configs/modules/weather/currentweather_options.js";
});
it("should render useBeaufort = false", async function() {
const weather = generateWeather();
await setup([weather, template]);
return app.client.waitUntilTextExists(".weather .normal.medium span:nth-child(2)", "12", 10000);
});
it("should render showWindDirectionAsArrow = true", async function() {
const weather = generateWeather();
await setup([weather, template]);
await app.client.waitForExist(".weather .normal.medium sup i.fa-long-arrow-up", 10000);
const element = await app.client.getHTML(".weather .normal.medium sup i.fa-long-arrow-up");
expect(element).to.include("transform:rotate(250deg);");
});
it("should render showHumidity = true", async function() {
const weather = generateWeather();
await setup([weather, template]);
await app.client.waitUntilTextExists(".weather .normal.medium span:nth-child(3)", "93", 10000);
return app.client.waitForExist(".weather .normal.medium sup i.wi-humidity", 10000);
});
it("should render degreeLabel = true", async function() {
const weather = generateWeather();
await setup([weather, template]);
await app.client.waitUntilTextExists(".weather .large.light span.bright", "1°C", 10000);
return app.client.waitUntilTextExists(".weather .normal.medium span.dimmed", "Feels like -6°C", 10000);
});
});
describe("Current weather units", function() {
before(function() {
process.env.MM_CONFIG_FILE = "tests/configs/modules/weather/currentweather_units.js";
});
it("should render imperial units", async function() {
const weather = generateWeather({
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
},
});
await setup([weather, template]);
await app.client.waitUntilTextExists(".weather .normal.medium span:nth-child(2)", "6 WSW", 10000);
await app.client.waitUntilTextExists(".weather .large.light span.bright", "34,7°", 10000);
return app.client.waitUntilTextExists(".weather .normal.medium span.dimmed", "22,0°", 10000);
});
it("should render decimalSymbol = ','", async function() {
const weather = generateWeather({
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
},
});
await setup([weather, template]);
await app.client.waitUntilTextExists(".weather .normal.medium span:nth-child(3)", "93,7", 10000);
await app.client.waitUntilTextExists(".weather .large.light span.bright", "34,7°", 10000);
return app.client.waitUntilTextExists(".weather .normal.medium span.dimmed", "22,0°", 10000);
});
});
});
describe("Weather Forecast", function() {
let template;
before(function() {
template = fs.readFileSync(path.join(__dirname, "..", "..", "..", "modules", "default", "weather", "forecast.njk"), "utf8");
});
describe("Default configuration", function() {
before(function() {
process.env.MM_CONFIG_FILE = "tests/configs/modules/weather/forecastweather_default.js";
});
it("should render days", async function() {
const weather = generateWeatherForecast();
await setup([weather, template]);
const days = ["Fri", "Sat", "Sun", "Mon", "Tue"];
for (const [index, day] of days.entries()) {
await app.client.waitUntilTextExists(`.weather table.small tr:nth-child(${index + 1}) td:nth-child(1)`, day, 10000);
}
});
it("should render icons", async function() {
const weather = generateWeatherForecast();
await setup([weather, template]);
const icons = ["day-cloudy", "rain", "day-sunny", "day-sunny", "day-sunny"];
for (const [index, icon] of icons.entries()) {
await app.client.waitForExist(`.weather table.small tr:nth-child(${index + 1}) td:nth-child(2) span.wi-${icon}`, 10000);
}
});
it("should render max temperatures", async function() {
const weather = generateWeatherForecast();
await setup([weather, template]);
const temperatures = ["24.4°", "21.0°", "22.9°", "23.4°", "20.6°"];
for (const [index, temp] of temperatures.entries()) {
await app.client.waitUntilTextExists(`.weather table.small tr:nth-child(${index + 1}) td:nth-child(3)`, temp, 10000);
}
});
it("should render min temperatures", async function() {
const weather = generateWeatherForecast();
await setup([weather, template]);
const temperatures = ["15.3°", "13.6°", "13.8°", "13.9°", "10.9°"];
for (const [index, temp] of temperatures.entries()) {
await app.client.waitUntilTextExists(`.weather table.small tr:nth-child(${index + 1}) td:nth-child(4)`, temp, 10000);
}
});
it("should render fading of rows", async function() {
const weather = generateWeatherForecast();
await setup([weather, template]);
const opacities = [1, 1, 0.8, 0.5333333333333333, 0.2666666666666667];
await app.client.waitForExist(".weather table.small", 10000);
for (const [index, opacity] of opacities.entries()) {
const html = await app.client.getHTML(`.weather table.small tr:nth-child(${index + 1})`);
expect(html).to.includes(`<tr style="opacity: ${opacity};">`);
}
});
});
describe("Configuration Options", function() {
before(function() {
process.env.MM_CONFIG_FILE = "tests/configs/modules/weather/forecastweather_options.js";
});
it("should render custom table class", async function() {
const weather = generateWeatherForecast();
await setup([weather, template]);
await app.client.waitForExist(".weather table.myTableClass", 10000);
});
it("should render colored rows", async function() {
const weather = generateWeatherForecast();
await setup([weather, template]);
await app.client.waitForExist(".weather table.myTableClass", 10000);
const rows = await app.client.$$(".weather table.myTableClass tr.colored");
expect(rows.length).to.be.equal(5);
});
});
});
});