specHelper.js 4.1 KB

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