specHelper.js 3.9 KB

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