test-setup.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. var jQuery = require('jQuery'); // jshint ignore:line
  2. global.$ = jQuery;
  3. global.jQuery = jQuery;
  4. require('bootstrap-transition');
  5. require('bootstrap-affix');
  6. require('bootstrap-modal');
  7. require('bootstrap-dropdown');
  8. require('dropzone');
  9. require('cropit');
  10. require('jquery-mockjax')(jQuery, window);
  11. $.mockjaxSettings.logging = false;
  12. $.mockjaxSettings.responseTime = 50;
  13. // polyfill es6 features in phantom.js
  14. require("babel-polyfill");
  15. // Mock base href element
  16. $('head').append('<base href="/test-runner/">');
  17. // Bootstrap's modal (we'll need it anyway for tests);
  18. $('body').append('<div class="modal fade" id="modal-mount" tabindex="-1" role="dialog" aria-labelledby="misago-modal-label"></div>');
  19. $('body').append('<div id="dropdown-mount"></div>');
  20. $('body').append('<div id="page-mount"></div>');
  21. $('body').append('<div id="test-mount"></div>');
  22. // inlined gettext functions form Django
  23. // jshint ignore: start
  24. (function (globals) {
  25. var django = globals.django || (globals.django = {});
  26. django.pluralidx = function (count) { return (count == 1) ? 0 : 1; };
  27. /* gettext identity library */
  28. django.gettext = function (msgid) { return msgid; };
  29. django.ngettext = function (singular, plural, count) { return (count == 1) ? singular : plural; };
  30. django.gettext_noop = function (msgid) { return msgid; };
  31. django.pgettext = function (context, msgid) { return msgid; };
  32. django.npgettext = function (context, singular, plural, count) { return (count == 1) ? singular : plural; };
  33. django.interpolate = function (fmt, obj, named) {
  34. if (named) {
  35. return fmt.replace(/%\(\w+\)s/g, function(match){return String(obj[match.slice(2,-2)])});
  36. } else {
  37. return fmt.replace(/%s/g, function(match){return String(obj.shift())});
  38. }
  39. };
  40. /* formatting library */
  41. django.formats = {
  42. "DATETIME_FORMAT": "N j, Y, P",
  43. "DATETIME_INPUT_FORMATS": [
  44. "%Y-%m-%d %H:%M:%S",
  45. "%Y-%m-%d %H:%M:%S.%f",
  46. "%Y-%m-%d %H:%M",
  47. "%Y-%m-%d",
  48. "%m/%d/%Y %H:%M:%S",
  49. "%m/%d/%Y %H:%M:%S.%f",
  50. "%m/%d/%Y %H:%M",
  51. "%m/%d/%Y",
  52. "%m/%d/%y %H:%M:%S",
  53. "%m/%d/%y %H:%M:%S.%f",
  54. "%m/%d/%y %H:%M",
  55. "%m/%d/%y"
  56. ],
  57. "DATE_FORMAT": "N j, Y",
  58. "DATE_INPUT_FORMATS": [
  59. "%Y-%m-%d",
  60. "%m/%d/%Y",
  61. "%m/%d/%y"
  62. ],
  63. "DECIMAL_SEPARATOR": ".",
  64. "FIRST_DAY_OF_WEEK": "0",
  65. "MONTH_DAY_FORMAT": "F j",
  66. "NUMBER_GROUPING": "3",
  67. "SHORT_DATETIME_FORMAT": "m/d/Y P",
  68. "SHORT_DATE_FORMAT": "m/d/Y",
  69. "THOUSAND_SEPARATOR": ",",
  70. "TIME_FORMAT": "P",
  71. "TIME_INPUT_FORMATS": [
  72. "%H:%M:%S",
  73. "%H:%M:%S.%f",
  74. "%H:%M"
  75. ],
  76. "YEAR_MONTH_FORMAT": "F Y"
  77. };
  78. django.get_format = function (format_type) {
  79. var value = django.formats[format_type];
  80. if (typeof(value) == 'undefined') {
  81. return format_type;
  82. } else {
  83. return value;
  84. }
  85. };
  86. /* add to global namespace */
  87. window.pluralidx = django.pluralidx;
  88. window.gettext = django.gettext;
  89. window.ngettext = django.ngettext;
  90. window.gettext_noop = django.gettext_noop;
  91. window.pgettext = django.pgettext;
  92. window.npgettext = django.npgettext;
  93. window.interpolate = django.interpolate;
  94. window.get_format = django.get_format;
  95. }(global));
  96. // jshint ignore: end