specHelper.js 3.7 KB

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