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.

weatherforecast_spec.js 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /* eslint no-multi-spaces: 0 */
  2. const moment = require("moment-timezone");
  3. const data = require("../../configs/data/weatherforecast_data.json");
  4. describe("Functions module weatherforecast", function () {
  5. beforeAll(function () {
  6. Module = {};
  7. config = {};
  8. Module.definitions = {};
  9. Module.register = function (name, moduleDefinition) {
  10. Module.definitions[name] = moduleDefinition;
  11. };
  12. require("../../../modules/default/weatherforecast/weatherforecast.js");
  13. Module.definitions.weatherforecast.config = {};
  14. });
  15. describe("roundValue", function () {
  16. describe("this.config.roundTemp is true", function () {
  17. beforeAll(function () {
  18. Module.definitions.weatherforecast.config.roundTemp = true;
  19. });
  20. const values = [
  21. // index 0 value
  22. // index 1 expect
  23. [1, "1"],
  24. [1.0, "1"],
  25. [1.02, "1"],
  26. [10.12, "10"],
  27. [2.0, "2"],
  28. ["2.12", "2"],
  29. [10.1, "10"]
  30. ];
  31. values.forEach((value) => {
  32. it(`for ${value[0]} should be return ${value[1]}`, function () {
  33. expect(Module.definitions.weatherforecast.roundValue(value[0])).toBe(value[1]);
  34. });
  35. });
  36. });
  37. describe("this.config.roundTemp is false", function () {
  38. beforeAll(function () {
  39. Module.definitions.weatherforecast.config.roundTemp = false;
  40. });
  41. const values = [
  42. // index 0 value
  43. // index 1 expect
  44. [1, "1.0"],
  45. [1.0, "1.0"],
  46. [1.02, "1.0"],
  47. [10.12, "10.1"],
  48. [2.0, "2.0"],
  49. ["2.12", "2.1"],
  50. [10.1, "10.1"],
  51. [10.1, "10.1"]
  52. ];
  53. values.forEach((value) => {
  54. it(`for ${value[0]} should be return ${value[1]}`, function () {
  55. expect(Module.definitions.weatherforecast.roundValue(value[0])).toBe(value[1]);
  56. });
  57. });
  58. });
  59. });
  60. describe("forecastIcons", function () {
  61. Log = {
  62. error: function () {}
  63. };
  64. let originalLocale;
  65. let originalTimeZone;
  66. beforeAll(function () {
  67. originalLocale = moment.locale();
  68. originalTimeZone = moment.tz.guess();
  69. moment.locale("hi");
  70. moment.tz.setDefault("Europe/Warsaw");
  71. });
  72. describe("forecastIcons sunset specified", function () {
  73. beforeAll(function () {
  74. Module.definitions.weatherforecast.Log = {};
  75. Module.definitions.weatherforecast.forecast = [];
  76. Module.definitions.weatherforecast.show = Module.definitions.weatherforecast.updateDom = function () {};
  77. Module.definitions.weatherforecast.config = Module.definitions.weatherforecast.defaults;
  78. });
  79. it(`returns correct icons with sunset time`, function () {
  80. Module.definitions.weatherforecast.processWeather(data.withSunset, moment);
  81. let forecastData = Module.definitions.weatherforecast.forecast;
  82. expect(forecastData.length).toBe(4);
  83. expect(forecastData[2].icon).toBe("wi-rain");
  84. });
  85. });
  86. describe("forecastIcons sunset not specified", function () {
  87. beforeAll(function () {
  88. Module.definitions.weatherforecast.forecast = [];
  89. });
  90. it(`returns correct icons with out sunset time`, function () {
  91. Module.definitions.weatherforecast.processWeather(data.withoutSunset, moment);
  92. let forecastData = Module.definitions.weatherforecast.forecast;
  93. expect(forecastData.length).toBe(4);
  94. expect(forecastData[2].icon).toBe("wi-rain");
  95. });
  96. });
  97. afterAll(function () {
  98. moment.locale(originalLocale);
  99. moment.tz.setDefault(originalTimeZone);
  100. });
  101. });
  102. });