ban-details.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. import assert from 'assert';
  2. import moment from 'moment';
  3. import React from 'react'; // jshint ignore:line
  4. import BanDetails from 'misago/components/profile/ban-details'; // jshint ignore:line
  5. import ajax from 'misago/services/ajax';
  6. import polls from 'misago/services/polls';
  7. import * as testUtils from 'misago/utils/test-utils';
  8. let profileMock = {
  9. username: 'BobBoberson',
  10. api_url: {
  11. ban: '/test-api/users/123/just-ban/'
  12. }
  13. };
  14. let expires_on = moment().add('days', 5);
  15. describe("User Profile Ban Details", function() {
  16. beforeEach(function() {
  17. polls.init(ajax, null);
  18. });
  19. afterEach(function() {
  20. testUtils.unmountComponents();
  21. $.mockjax.clear();
  22. polls.stop('ban-details');
  23. });
  24. it("loads", function(done) {
  25. $.mockjax({
  26. url: profileMock.api_url.ban,
  27. status: 200,
  28. responseText: {
  29. user_message: null,
  30. staff_message: null,
  31. expires_on: null
  32. }
  33. });
  34. /* jshint ignore:start */
  35. testUtils.render(<BanDetails profile={profileMock} />);
  36. /* jshint ignore:end */
  37. testUtils.onElement('#test-mount .ban-expires p.lead', function(element) {
  38. assert.equal(element.text(), "BobBoberson's ban is permanent.",
  39. "expiration message is displayed");
  40. assert.ok(!$('#test-mount .ban-user-message').length,
  41. "user message is hidden");
  42. assert.ok(!$('#test-mount .ban-staff-message').length,
  43. "staff message is hidden");
  44. done();
  45. });
  46. });
  47. it("loads kitchensink", function(done) {
  48. $.mockjax({
  49. url: profileMock.api_url.ban,
  50. status: 200,
  51. responseText: {
  52. user_message: {
  53. plain: "Test user message.",
  54. html: "<p>Test user message.</p>"
  55. },
  56. staff_message: {
  57. plain: "Test staff message.",
  58. html: "<p>Test staff message.</p>"
  59. },
  60. expires_on: expires_on.format()
  61. }
  62. });
  63. /* jshint ignore:start */
  64. testUtils.render(<BanDetails profile={profileMock} />);
  65. /* jshint ignore:end */
  66. testUtils.onElement('#test-mount .ban-expires p.lead', function(element) {
  67. assert.equal(element.text(), "This ban expires in 5 days.",
  68. "expiration message is displayed");
  69. assert.equal($('#test-mount .ban-user-message p').text(),
  70. "Test user message.",
  71. "user message is displayed");
  72. assert.equal($('#test-mount .ban-staff-message p').text(),
  73. "Test staff message.",
  74. "staff message is displayed");
  75. done();
  76. });
  77. });
  78. it("loads no ban", function(done) {
  79. $.mockjax({
  80. url: profileMock.api_url.ban,
  81. status: 200,
  82. responseText: {}
  83. });
  84. /* jshint ignore:start */
  85. testUtils.render(<BanDetails profile={profileMock} />);
  86. /* jshint ignore:end */
  87. testUtils.onElement('#test-mount .panel-message-body', function(element) {
  88. assert.equal(element.find('p').text(), "No ban is active at the moment.",
  89. "no ban message is displayed");
  90. done();
  91. });
  92. });
  93. it("handles backend error", function(done) {
  94. $.mockjax({
  95. url: profileMock.api_url.ban,
  96. status: 500
  97. });
  98. /* jshint ignore:start */
  99. testUtils.render(<BanDetails profile={profileMock} />);
  100. /* jshint ignore:end */
  101. testUtils.onElement('#test-mount .panel-message-body', function(element) {
  102. assert.equal(element.find('p').text(), "Unknown error has occured.",
  103. "rejection message is displayed");
  104. done();
  105. });
  106. });
  107. it("handles backend rejection", function(done) {
  108. $.mockjax({
  109. url: profileMock.api_url.ban,
  110. status: 403,
  111. responseText: {
  112. detail: "You can't into user bans!"
  113. }
  114. });
  115. /* jshint ignore:start */
  116. testUtils.render(<BanDetails profile={profileMock} />);
  117. /* jshint ignore:end */
  118. testUtils.onElement('#test-mount .panel-message-body', function(element) {
  119. assert.equal(element.find('p').text(), "You can't into user bans!",
  120. "rejection message is displayed");
  121. done();
  122. });
  123. });
  124. });