specHelper.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  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. window.oc_isadmin = false;
  87. // FIXME: oc_webroot is supposed to be only the path!!!
  88. window.oc_webroot = location.href + '/';
  89. window.oc_appswebroots = {
  90. "files": window.oc_webroot + '/apps/files/'
  91. };
  92. window.oc_config = {
  93. session_lifetime: 600 * 1000,
  94. session_keepalive: false,
  95. blacklist_files_regex: '\.(part|filepart)$',
  96. };
  97. window.oc_appconfig = {
  98. core: {}
  99. };
  100. window.oc_defaults = {
  101. docPlaceholderUrl: 'https://docs.example.org/PLACEHOLDER'
  102. };
  103. window.oc_capabilities = {
  104. }
  105. /* jshint camelcase: true */
  106. // mock for Snap.js plugin
  107. window.Snap = function() {};
  108. window.Snap.prototype = {
  109. enable: function() {},
  110. disable: function() {},
  111. close: function() {}
  112. };
  113. window.isPhantom = /phantom/i.test(navigator.userAgent);
  114. // global setup for all tests
  115. (function setupTests() {
  116. var fakeServer = null,
  117. $testArea = null,
  118. ajaxErrorStub = null;
  119. /**
  120. * Utility functions for testing
  121. */
  122. var TestUtil = {
  123. /**
  124. * Returns the image URL set on the given element
  125. * @param $el element
  126. * @return {String} image URL
  127. */
  128. getImageUrl: function($el) {
  129. // might be slightly different cross-browser
  130. var url = $el.css('background-image');
  131. var r = url.match(/url\(['"]?([^'")]*)['"]?\)/);
  132. if (!r) {
  133. return url;
  134. }
  135. return r[1];
  136. }
  137. };
  138. beforeEach(function() {
  139. // test area for elements that need absolute selector access or measure widths/heights
  140. // which wouldn't work for detached or hidden elements
  141. $testArea = $('<div id="testArea" style="position: absolute; width: 1280px; height: 800px; top: -3000px; left: -3000px; opacity: 0;"></div>');
  142. $('body').append($testArea);
  143. // enforce fake XHR, tests should not depend on the server and
  144. // must use fake responses for expected calls
  145. fakeServer = sinon.fakeServer.create();
  146. // make it globally available, so that other tests can define
  147. // custom responses
  148. window.fakeServer = fakeServer;
  149. if (!OC.TestUtil) {
  150. OC.TestUtil = TestUtil;
  151. }
  152. moment.locale('en');
  153. // reset plugins
  154. OC.Plugins._plugins = [];
  155. // dummy select2 (which isn't loaded during the tests)
  156. $.fn.select2 = function() { return this; };
  157. ajaxErrorStub = sinon.stub(OC, '_processAjaxError');
  158. });
  159. afterEach(function() {
  160. // uncomment this to log requests
  161. // console.log(window.fakeServer.requests);
  162. fakeServer.restore();
  163. $testArea.remove();
  164. delete($.fn.select2);
  165. ajaxErrorStub.restore();
  166. // reset pop state handlers
  167. OC.Util.History._handlers = [];
  168. });
  169. })();