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.

calendar_spec.js 5.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. global.moment = require("moment");
  2. describe("Functions into modules/default/calendar/calendar.js", function () {
  3. // Fake for use by calendar.js
  4. Module = {};
  5. Module.definitions = {};
  6. Module.register = function (name, moduleDefinition) {
  7. Module.definitions[name] = moduleDefinition;
  8. };
  9. beforeAll(function () {
  10. // load calendar.js
  11. require("../../../modules/default/calendar/calendar.js");
  12. });
  13. describe("capFirst", function () {
  14. const words = {
  15. rodrigo: "Rodrigo",
  16. "123m": "123m",
  17. "magic mirror": "Magic mirror",
  18. ",a": ",a",
  19. ñandú: "Ñandú"
  20. };
  21. Object.keys(words).forEach((word) => {
  22. it(`for '${word}' should return '${words[word]}'`, function () {
  23. expect(Module.definitions.calendar.capFirst(word)).toBe(words[word]);
  24. });
  25. });
  26. });
  27. describe("getLocaleSpecification", function () {
  28. it("should return a valid moment.LocaleSpecification for a 12-hour format", function () {
  29. expect(Module.definitions.calendar.getLocaleSpecification(12)).toEqual({ longDateFormat: { LT: "h:mm A" } });
  30. });
  31. it("should return a valid moment.LocaleSpecification for a 24-hour format", function () {
  32. expect(Module.definitions.calendar.getLocaleSpecification(24)).toEqual({ longDateFormat: { LT: "HH:mm" } });
  33. });
  34. it("should return the current system locale when called without timeFormat number", function () {
  35. expect(Module.definitions.calendar.getLocaleSpecification()).toEqual({ longDateFormat: { LT: moment.localeData().longDateFormat("LT") } });
  36. });
  37. it("should return a 12-hour longDateFormat when using the 'en' locale", function () {
  38. const localeBackup = moment.locale();
  39. moment.locale("en");
  40. expect(Module.definitions.calendar.getLocaleSpecification()).toEqual({ longDateFormat: { LT: "h:mm A" } });
  41. moment.locale(localeBackup);
  42. });
  43. it("should return a 12-hour longDateFormat when using the 'au' locale", function () {
  44. const localeBackup = moment.locale();
  45. moment.locale("au");
  46. expect(Module.definitions.calendar.getLocaleSpecification()).toEqual({ longDateFormat: { LT: "h:mm A" } });
  47. moment.locale(localeBackup);
  48. });
  49. it("should return a 12-hour longDateFormat when using the 'eg' locale", function () {
  50. const localeBackup = moment.locale();
  51. moment.locale("eg");
  52. expect(Module.definitions.calendar.getLocaleSpecification()).toEqual({ longDateFormat: { LT: "h:mm A" } });
  53. moment.locale(localeBackup);
  54. });
  55. it("should return a 24-hour longDateFormat when using the 'nl' locale", function () {
  56. const localeBackup = moment.locale();
  57. moment.locale("nl");
  58. expect(Module.definitions.calendar.getLocaleSpecification()).toEqual({ longDateFormat: { LT: "HH:mm" } });
  59. moment.locale(localeBackup);
  60. });
  61. it("should return a 24-hour longDateFormat when using the 'fr' locale", function () {
  62. const localeBackup = moment.locale();
  63. moment.locale("fr");
  64. expect(Module.definitions.calendar.getLocaleSpecification()).toEqual({ longDateFormat: { LT: "HH:mm" } });
  65. moment.locale(localeBackup);
  66. });
  67. it("should return a 24-hour longDateFormat when using the 'uk' locale", function () {
  68. const localeBackup = moment.locale();
  69. moment.locale("uk");
  70. expect(Module.definitions.calendar.getLocaleSpecification()).toEqual({ longDateFormat: { LT: "HH:mm" } });
  71. moment.locale(localeBackup);
  72. });
  73. });
  74. describe("shorten", function () {
  75. const strings = {
  76. " String with whitespace at the beginning that needs trimming": { length: 16, return: "String with whit…" },
  77. "long string that needs shortening": { length: 16, return: "long string that…" },
  78. "short string": { length: 16, return: "short string" },
  79. "long string with no maxLength defined": { return: "long string with no maxLength defined" }
  80. };
  81. Object.keys(strings).forEach((string) => {
  82. it(`for '${string}' should return '${strings[string].return}'`, function () {
  83. expect(Module.definitions.calendar.shorten(string, strings[string].length)).toBe(strings[string].return);
  84. });
  85. });
  86. it("should return an empty string if shorten is called with a non-string", function () {
  87. expect(Module.definitions.calendar.shorten(100)).toBe("");
  88. });
  89. it("should not shorten the string if shorten is called with a non-number maxLength", function () {
  90. expect(Module.definitions.calendar.shorten("This is a test string", "This is not a number")).toBe("This is a test string");
  91. });
  92. it("should wrap the string instead of shorten it if shorten is called with wrapEvents = true (with maxLength defined as 20)", function () {
  93. expect(Module.definitions.calendar.shorten("This is a wrapEvent test. Should wrap the string instead of shorten it if called with wrapEvent = true", 20, true)).toBe(
  94. "This is a <br>wrapEvent test. Should wrap <br>the string instead of <br>shorten it if called with <br>wrapEvent = true"
  95. );
  96. });
  97. it("should wrap the string instead of shorten it if shorten is called with wrapEvents = true (without maxLength defined, default 25)", function () {
  98. expect(Module.definitions.calendar.shorten("This is a wrapEvent test. Should wrap the string instead of shorten it if called with wrapEvent = true", undefined, true)).toBe(
  99. "This is a wrapEvent <br>test. Should wrap the string <br>instead of shorten it if called <br>with wrapEvent = true"
  100. );
  101. });
  102. it("should wrap and shorten the string in the second line if called with wrapEvents = true and maxTitleLines = 2", function () {
  103. expect(Module.definitions.calendar.shorten("This is a wrapEvent and maxTitleLines test. Should wrap and shorten the string in the second line if called with wrapEvents = true and maxTitleLines = 2", undefined, true, 2)).toBe(
  104. "This is a wrapEvent and <br>maxTitleLines test. Should wrap and &hellip;"
  105. );
  106. });
  107. });
  108. });