specHelper.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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. /* global OC */
  22. /**
  23. * Simulate the variables that are normally set by PHP code
  24. */
  25. // from core/js/config.php
  26. window.TESTING = true;
  27. window.oc_debug = true;
  28. window.datepickerFormatDate = 'MM d, yy';
  29. window.dayNames = [
  30. 'Sunday',
  31. 'Monday',
  32. 'Tuesday',
  33. 'Wednesday',
  34. 'Thursday',
  35. 'Friday',
  36. 'Saturday'
  37. ];
  38. window.monthNames = [
  39. 'January',
  40. 'February',
  41. 'March',
  42. 'April',
  43. 'May',
  44. 'June',
  45. 'July',
  46. 'August',
  47. 'September',
  48. 'October',
  49. 'November',
  50. 'December'
  51. ];
  52. window.firstDay = 0;
  53. // setup dummy webroots
  54. window.oc_webroot = location.href + '/';
  55. window.oc_appswebroots = {
  56. "files": window.oc_webroot + '/apps/files/'
  57. };
  58. window.oc_config = {
  59. session_lifetime: 600 * 1000,
  60. session_keepalive: false
  61. };
  62. // global setup for all tests
  63. (function setupTests() {
  64. var fakeServer = null,
  65. routesRequestStub;
  66. beforeEach(function() {
  67. // enforce fake XHR, tests should not depend on the server and
  68. // must use fake responses for expected calls
  69. fakeServer = sinon.fakeServer.create();
  70. // return fake translations as they might be requested for many test runs
  71. fakeServer.respondWith(/\/index.php\/core\/ajax\/translations.php$/, [
  72. 200, {
  73. "Content-Type": "application/json"
  74. },
  75. '{"data": [], "plural_form": "nplurals=2; plural=(n != 1);"}'
  76. ]);
  77. // make it globally available, so that other tests can define
  78. // custom responses
  79. window.fakeServer = fakeServer;
  80. OC.Router.routes = [];
  81. OC.Router.routes_request = {
  82. state: sinon.stub().returns('resolved'),
  83. done: sinon.stub()
  84. };
  85. });
  86. afterEach(function() {
  87. OC.Router.routes_request.state.reset();
  88. OC.Router.routes_request.done.reset();
  89. // uncomment this to log requests
  90. // console.log(window.fakeServer.requests);
  91. fakeServer.restore();
  92. });
  93. })();