Software zum Installieren eines Smart-Mirror Frameworks , zum Nutzen von hochschulrelevanten Informationen, auf einem Raspberry-Pi.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

weather_spec.js 9.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309
  1. const fs = require("fs");
  2. const moment = require("moment");
  3. const path = require("path");
  4. const wdajaxstub = require("webdriverajaxstub");
  5. const helpers = require("../global-setup");
  6. const { generateWeather, generateWeatherForecast } = require("./mocks");
  7. describe("Weather module", function () {
  8. let app;
  9. helpers.setupTimeout(this);
  10. /**
  11. *
  12. * @param {object} responses mocked data to be returned
  13. * @returns {Promise} Resolved once the electron app is started
  14. */
  15. async function setup(responses) {
  16. app = await helpers.startApplication({
  17. args: ["js/electron.js"],
  18. waitTimeout: 100000
  19. });
  20. wdajaxstub.init(app.client, responses);
  21. app.client.setupStub();
  22. }
  23. /**
  24. *
  25. * @param {string} element css selector
  26. * @returns {Promise<Element>} Promise with the element once it is rendered
  27. */
  28. async function getElement(element) {
  29. return await app.client.$(element);
  30. }
  31. /**
  32. * @param {string} element css selector
  33. * @param {string} result Expected text in given selector
  34. * @returns {Promise<boolean>} Promise with True if the text matches
  35. */
  36. async function getText(element, result) {
  37. const elem = await getElement(element);
  38. return await elem.getText(element).then(function (text) {
  39. expect(text.trim()).toBe(result);
  40. });
  41. }
  42. afterEach(function () {
  43. return helpers.stopApplication(app);
  44. });
  45. describe("Current weather", function () {
  46. let template;
  47. beforeAll(function () {
  48. template = fs.readFileSync(path.join(__dirname, "..", "..", "..", "modules", "default", "weather", "current.njk"), "utf8");
  49. });
  50. describe("Default configuration", function () {
  51. beforeAll(function () {
  52. process.env.MM_CONFIG_FILE = "tests/configs/modules/weather/currentweather_default.js";
  53. });
  54. it("should render wind speed and wind direction", async function () {
  55. const weather = generateWeather();
  56. await setup({ template, data: weather });
  57. return getText(".weather .normal.medium span:nth-child(2)", "6 WSW");
  58. });
  59. it("should render sunrise", async function () {
  60. const sunrise = moment().startOf("day").unix();
  61. const sunset = moment().startOf("day").unix();
  62. const weather = generateWeather({ sys: { sunrise, sunset } });
  63. await setup({ template, data: weather });
  64. return getText(".weather .normal.medium span:nth-child(4)", "12:00 am");
  65. });
  66. it("should render sunset", async function () {
  67. const sunrise = moment().startOf("day").unix();
  68. const sunset = moment().endOf("day").unix();
  69. const weather = generateWeather({ sys: { sunrise, sunset } });
  70. await setup({ template, data: weather });
  71. return getText(".weather .normal.medium span:nth-child(4)", "11:59 pm");
  72. });
  73. it("should render temperature with icon", async function () {
  74. const weather = generateWeather();
  75. await setup({ template, data: weather });
  76. return getText(".weather .large.light span.bright", "1.5°");
  77. });
  78. it("should render feels like temperature", async function () {
  79. const weather = generateWeather();
  80. await setup({ template, data: weather });
  81. return getText(".weather .normal.medium.feelslike span.dimmed", "Feels like -5.6°");
  82. });
  83. });
  84. describe("Compliments Integration", function () {
  85. beforeAll(function () {
  86. process.env.MM_CONFIG_FILE = "tests/configs/modules/weather/currentweather_compliments.js";
  87. });
  88. it("should render a compliment based on the current weather", async function () {
  89. const weather = generateWeather();
  90. await setup({ template, data: weather });
  91. return app.client.waitUntilTextExists(".compliments .module-content span", "snow");
  92. });
  93. });
  94. describe("Configuration Options", function () {
  95. beforeAll(function () {
  96. process.env.MM_CONFIG_FILE = "tests/configs/modules/weather/currentweather_options.js";
  97. });
  98. it("should render useBeaufort = false", async function () {
  99. const weather = generateWeather();
  100. await setup({ template, data: weather });
  101. return getText(".weather .normal.medium span:nth-child(2)", "12");
  102. });
  103. it("should render showWindDirectionAsArrow = true", async function () {
  104. const weather = generateWeather();
  105. await setup({ template, data: weather });
  106. const elem = await getElement(".weather .normal.medium sup i.fa-long-arrow-up");
  107. return elem.getHTML(".weather .normal.medium sup i.fa-long-arrow-up").then(function (text) {
  108. expect(text).toContain("transform:rotate(250deg);");
  109. });
  110. });
  111. it("should render showHumidity = true", async function () {
  112. const weather = generateWeather();
  113. await setup({ template, data: weather });
  114. return getText(".weather .normal.medium span:nth-child(3)", "93.7");
  115. });
  116. it("should render degreeLabel = true", async function () {
  117. const weather = generateWeather();
  118. await setup({ template, data: weather });
  119. return (await getText(".weather .large.light span.bright", "1°C")) && (await getText(".weather .normal.medium.feelslike span.dimmed", "Feels like -6°C"));
  120. });
  121. });
  122. describe("Current weather units", function () {
  123. beforeAll(function () {
  124. process.env.MM_CONFIG_FILE = "tests/configs/modules/weather/currentweather_units.js";
  125. });
  126. it("should render imperial units", async function () {
  127. const weather = generateWeather({
  128. main: {
  129. temp: (1.49 * 9) / 5 + 32,
  130. temp_min: (1 * 9) / 5 + 32,
  131. temp_max: (2 * 9) / 5 + 32
  132. },
  133. wind: {
  134. speed: 11.8 * 2.23694
  135. }
  136. });
  137. await setup({ template, data: weather });
  138. return (await getText(".weather .normal.medium span:nth-child(2)", "6 WSW")) && (await getText(".weather .large.light span.bright", "34,7°")) && getText(".weather .normal.medium.feelslike span.dimmed", "Feels like 22,0°");
  139. });
  140. it("should render custom decimalSymbol = ','", async function () {
  141. const weather = generateWeather({
  142. main: {
  143. temp: (1.49 * 9) / 5 + 32,
  144. temp_min: (1 * 9) / 5 + 32,
  145. temp_max: (2 * 9) / 5 + 32
  146. },
  147. wind: {
  148. speed: 11.8 * 2.23694
  149. }
  150. });
  151. await setup({ template, data: weather });
  152. return (await getText(".weather .normal.medium span:nth-child(3)", "93,7")) && (await getText(".weather .large.light span.bright", "34,7°")) && getText(".weather .normal.medium.feelslike span.dimmed", "Feels like 22,0°");
  153. });
  154. });
  155. });
  156. describe("Weather Forecast", function () {
  157. let template;
  158. beforeAll(function () {
  159. template = fs.readFileSync(path.join(__dirname, "..", "..", "..", "modules", "default", "weather", "forecast.njk"), "utf8");
  160. });
  161. describe("Default configuration", function () {
  162. beforeAll(function () {
  163. process.env.MM_CONFIG_FILE = "tests/configs/modules/weather/forecastweather_default.js";
  164. });
  165. it("should render days", async function () {
  166. const weather = generateWeatherForecast();
  167. await setup({ template, data: weather });
  168. const days = ["Today", "Tomorrow", "Sun", "Mon", "Tue"];
  169. for (const [index, day] of days.entries()) {
  170. await getText(`.weather table.small tr:nth-child(${index + 1}) td:nth-child(1)`, day);
  171. }
  172. });
  173. it("should render icons", async function () {
  174. const weather = generateWeatherForecast();
  175. await setup({ template, data: weather });
  176. const icons = ["day-cloudy", "rain", "day-sunny", "day-sunny", "day-sunny"];
  177. for (const [index, icon] of icons.entries()) {
  178. await getElement(`.weather table.small tr:nth-child(${index + 1}) td:nth-child(2) span.wi-${icon}`);
  179. }
  180. });
  181. it("should render max temperatures", async function () {
  182. const weather = generateWeatherForecast();
  183. await setup({ template, data: weather });
  184. const temperatures = ["24.4°", "21.0°", "22.9°", "23.4°", "20.6°"];
  185. for (const [index, temp] of temperatures.entries()) {
  186. await getText(`.weather table.small tr:nth-child(${index + 1}) td:nth-child(3)`, temp);
  187. }
  188. });
  189. it("should render min temperatures", async function () {
  190. const weather = generateWeatherForecast();
  191. await setup({ template, data: weather });
  192. const temperatures = ["15.3°", "13.6°", "13.8°", "13.9°", "10.9°"];
  193. for (const [index, temp] of temperatures.entries()) {
  194. await getText(`.weather table.small tr:nth-child(${index + 1}) td:nth-child(4)`, temp);
  195. }
  196. });
  197. it("should render fading of rows", async function () {
  198. const weather = generateWeatherForecast();
  199. await setup({ template, data: weather });
  200. const opacities = [1, 1, 0.8, 0.5333333333333333, 0.2666666666666667];
  201. const elem = await getElement(".weather table.small");
  202. for (const [index, opacity] of opacities.entries()) {
  203. const html = await elem.getHTML(`.weather table.small tr:nth-child(${index + 1})`);
  204. expect(html).toContain(`<tr style="opacity: ${opacity};">`);
  205. }
  206. });
  207. });
  208. describe("Configuration Options", function () {
  209. beforeAll(function () {
  210. process.env.MM_CONFIG_FILE = "tests/configs/modules/weather/forecastweather_options.js";
  211. });
  212. it("should render custom table class", async function () {
  213. const weather = generateWeatherForecast();
  214. await setup({ template, data: weather });
  215. await getElement(".weather table.myTableClass");
  216. });
  217. it("should render colored rows", async function () {
  218. const weather = generateWeatherForecast();
  219. await setup({ template, data: weather });
  220. const rows = await app.client.$$(".weather table.myTableClass tr.colored");
  221. expect(rows.length).toBe(5);
  222. });
  223. });
  224. describe("Forecast weather units", function () {
  225. beforeAll(function () {
  226. process.env.MM_CONFIG_FILE = "tests/configs/modules/weather/forecastweather_units.js";
  227. });
  228. it("should render custom decimalSymbol = '_'", async function () {
  229. const weather = generateWeatherForecast();
  230. await setup({ template, data: weather });
  231. const temperatures = ["24_4°", "21_0°", "22_9°", "23_4°", "20_6°"];
  232. for (const [index, temp] of temperatures.entries()) {
  233. await getText(`.weather table.small tr:nth-child(${index + 1}) td:nth-child(3)`, temp);
  234. }
  235. });
  236. });
  237. });
  238. });