test-setup.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. var jQuery = require("jQuery")
  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(
  19. '<div class="modal fade" id="modal-mount" tabindex="-1" role="dialog" aria-labelledby="misago-modal-label"></div>'
  20. )
  21. $("body").append('<div id="dropdown-mount"></div>')
  22. $("body").append('<div id="page-mount"></div>')
  23. $("body").append('<div id="test-mount"></div>')
  24. // inlined gettext functions form Django
  25. ;(function(globals) {
  26. var django = globals.django || (globals.django = {})
  27. django.pluralidx = function(count) {
  28. return count == 1 ? 0 : 1
  29. }
  30. /* gettext identity library */
  31. django.gettext = function(msgid) {
  32. return msgid
  33. }
  34. django.ngettext = function(singular, plural, count) {
  35. return count == 1 ? singular : plural
  36. }
  37. django.gettext_noop = function(msgid) {
  38. return msgid
  39. }
  40. django.pgettext = function(context, msgid) {
  41. return msgid
  42. }
  43. django.npgettext = function(context, singular, plural, count) {
  44. return count == 1 ? singular : plural
  45. }
  46. django.interpolate = function(fmt, obj, named) {
  47. if (named) {
  48. return fmt.replace(/%\(\w+\)s/g, function(match) {
  49. return String(obj[match.slice(2, -2)])
  50. })
  51. } else {
  52. return fmt.replace(/%s/g, function(match) {
  53. return String(obj.shift())
  54. })
  55. }
  56. }
  57. /* formatting library */
  58. django.formats = {
  59. DATETIME_FORMAT: "N j, Y, P",
  60. DATETIME_INPUT_FORMATS: [
  61. "%Y-%m-%d %H:%M:%S",
  62. "%Y-%m-%d %H:%M:%S.%f",
  63. "%Y-%m-%d %H:%M",
  64. "%Y-%m-%d",
  65. "%m/%d/%Y %H:%M:%S",
  66. "%m/%d/%Y %H:%M:%S.%f",
  67. "%m/%d/%Y %H:%M",
  68. "%m/%d/%Y",
  69. "%m/%d/%y %H:%M:%S",
  70. "%m/%d/%y %H:%M:%S.%f",
  71. "%m/%d/%y %H:%M",
  72. "%m/%d/%y"
  73. ],
  74. DATE_FORMAT: "N j, Y",
  75. DATE_INPUT_FORMATS: ["%Y-%m-%d", "%m/%d/%Y", "%m/%d/%y"],
  76. DECIMAL_SEPARATOR: ".",
  77. FIRST_DAY_OF_WEEK: "0",
  78. MONTH_DAY_FORMAT: "F j",
  79. NUMBER_GROUPING: "3",
  80. SHORT_DATETIME_FORMAT: "m/d/Y P",
  81. SHORT_DATE_FORMAT: "m/d/Y",
  82. THOUSAND_SEPARATOR: ",",
  83. TIME_FORMAT: "P",
  84. TIME_INPUT_FORMATS: ["%H:%M:%S", "%H:%M:%S.%f", "%H:%M"],
  85. YEAR_MONTH_FORMAT: "F Y"
  86. }
  87. django.get_format = function(format_type) {
  88. var value = django.formats[format_type]
  89. if (typeof value == "undefined") {
  90. return format_type
  91. } else {
  92. return value
  93. }
  94. }
  95. /* add to global namespace */
  96. window.pluralidx = django.pluralidx
  97. window.gettext = django.gettext
  98. window.ngettext = django.ngettext
  99. window.gettext_noop = django.gettext_noop
  100. window.pgettext = django.pgettext
  101. window.npgettext = django.npgettext
  102. window.interpolate = django.interpolate
  103. window.get_format = django.get_format
  104. })(global)