specHelper.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. /**
  2. * SPDX-FileCopyrightText: 2017 Nextcloud GmbH and Nextcloud contributors
  3. * SPDX-FileCopyrightText: 2014 ownCloud Inc.
  4. * SPDX-License-Identifier: AGPL-3.0-or-later
  5. */
  6. /**
  7. * Simulate the variables that are normally set by PHP code
  8. */
  9. // from core/js/config.php
  10. window.TESTING = true;
  11. window.datepickerFormatDate = 'MM d, yy';
  12. window.dayNames = [
  13. 'Sunday',
  14. 'Monday',
  15. 'Tuesday',
  16. 'Wednesday',
  17. 'Thursday',
  18. 'Friday',
  19. 'Saturday'
  20. ];
  21. window.dayNamesShort = [
  22. 'Sun.',
  23. 'Mon.',
  24. 'Tue.',
  25. 'Wed.',
  26. 'Thu.',
  27. 'Fri.',
  28. 'Sat.'
  29. ];
  30. window.dayNamesMin = [
  31. 'Su',
  32. 'Mo',
  33. 'Tu',
  34. 'We',
  35. 'Th',
  36. 'Fr',
  37. 'Sa'
  38. ];
  39. window.monthNames = [
  40. 'January',
  41. 'February',
  42. 'March',
  43. 'April',
  44. 'May',
  45. 'June',
  46. 'July',
  47. 'August',
  48. 'September',
  49. 'October',
  50. 'November',
  51. 'December'
  52. ];
  53. window.monthNamesShort = [
  54. 'Jan.',
  55. 'Feb.',
  56. 'Mar.',
  57. 'Apr.',
  58. 'May.',
  59. 'Jun.',
  60. 'Jul.',
  61. 'Aug.',
  62. 'Sep.',
  63. 'Oct.',
  64. 'Nov.',
  65. 'Dec.'
  66. ];
  67. window.firstDay = 0;
  68. // setup dummy webroots
  69. /* jshint camelcase: false */
  70. window.oc_debug = true;
  71. // Mock @nextcloud/capabilities
  72. window._oc_capabilities = {
  73. files_sharing: {
  74. api_enabled: true
  75. }
  76. }
  77. // FIXME: OC.webroot is supposed to be only the path!!!
  78. window._oc_webroot = location.href + '/';
  79. window._oc_appswebroots = {
  80. "files": window.webroot + '/apps/files/',
  81. "files_sharing": window.webroot + '/apps/files_sharing/'
  82. };
  83. OC.config = {
  84. session_lifetime: 600 * 1000,
  85. session_keepalive: false,
  86. blacklist_files_regex: '\.(part|filepart)$',
  87. };
  88. OC.appConfig = {
  89. core: {}
  90. };
  91. OC.theme = {
  92. docPlaceholderUrl: 'https://docs.example.org/PLACEHOLDER'
  93. };
  94. window.oc_capabilities = {
  95. }
  96. /* jshint camelcase: true */
  97. // mock for Snap.js plugin
  98. window.Snap = function() {};
  99. window.Snap.prototype = {
  100. enable: function() {},
  101. disable: function() {},
  102. close: function() {}
  103. };
  104. window.isPhantom = /phantom/i.test(navigator.userAgent);
  105. document.documentElement.lang = navigator.language;
  106. // global setup for all tests
  107. (function setupTests() {
  108. var fakeServer = null,
  109. $testArea = null,
  110. ajaxErrorStub = null;
  111. /**
  112. * Utility functions for testing
  113. */
  114. var TestUtil = {
  115. /**
  116. * Returns the image URL set on the given element
  117. * @param $el element
  118. * @return {String} image URL
  119. */
  120. getImageUrl: function($el) {
  121. // might be slightly different cross-browser
  122. var url = $el.css('background-image');
  123. var r = url.match(/url\(['"]?([^'")]*)['"]?\)/);
  124. if (!r) {
  125. return url;
  126. }
  127. return r[1];
  128. }
  129. };
  130. beforeEach(function() {
  131. // test area for elements that need absolute selector access or measure widths/heights
  132. // which wouldn't work for detached or hidden elements
  133. $testArea = $('<div id="testArea" style="position: absolute; width: 1280px; height: 800px; top: -3000px; left: -3000px; opacity: 0;"></div>');
  134. $('body').append($testArea);
  135. // enforce fake XHR, tests should not depend on the server and
  136. // must use fake responses for expected calls
  137. fakeServer = sinon.fakeServer.create();
  138. // make it globally available, so that other tests can define
  139. // custom responses
  140. window.fakeServer = fakeServer;
  141. if (!OC.TestUtil) {
  142. OC.TestUtil = TestUtil;
  143. }
  144. moment.locale('en');
  145. // reset plugins
  146. OC.Plugins._plugins = [];
  147. // dummy select2 (which isn't loaded during the tests)
  148. $.fn.select2 = function() { return this; };
  149. ajaxErrorStub = sinon.stub(OC, '_processAjaxError');
  150. });
  151. afterEach(function() {
  152. // uncomment this to log requests
  153. // console.log(window.fakeServer.requests);
  154. fakeServer.restore();
  155. $testArea.remove();
  156. delete($.fn.select2);
  157. ajaxErrorStub.restore();
  158. // reset pop state handlers
  159. OC.Util.History._handlers = [];
  160. });
  161. })();