specHelper.js 4.0 KB

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