ban-details.js 4.8 KB

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