controls.js 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. import assert from 'assert';
  2. import React from 'react'; // jshint ignore:line
  3. import Controls from 'misago/components/threads/moderation/controls'; // jshint ignore:line
  4. import * as testUtils from 'misago/utils/test-utils';
  5. describe("Threads List Moderation Controls Display", function() {
  6. afterEach(function() {
  7. testUtils.unmountComponents();
  8. });
  9. });
  10. describe("Threads List Moderation Controls Display", function() {
  11. afterEach(function() {
  12. testUtils.unmountComponents();
  13. });
  14. it("shows no buttons", function() {
  15. /* jshint ignore:start */
  16. testUtils.render(
  17. <Controls className="test-controls" moderation={{
  18. can_approve: false,
  19. can_close: false,
  20. can_hide: false,
  21. can_move: false,
  22. can_merge: false,
  23. can_pin: false
  24. }} />
  25. );
  26. /* jshint ignore:end */
  27. const element = $('#test-mount .test-controls');
  28. assert.ok(element.length, "component renders");
  29. assert.equal(element.find('li').length, 0,
  30. "moderation controls are hidden");
  31. });
  32. it("shows pin/unpin buttons", function() {
  33. /* jshint ignore:start */
  34. testUtils.render(
  35. <Controls className="test-controls" moderation={{
  36. can_approve: false,
  37. can_close: false,
  38. can_hide: false,
  39. can_move: false,
  40. can_merge: false,
  41. can_pin: 1
  42. }} />
  43. );
  44. /* jshint ignore:end */
  45. const element = $('#test-mount .test-controls');
  46. assert.ok(element.length, "component renders");
  47. assert.equal(element.find('li').length, 2,
  48. "pin/unpin moderation controls are shown");
  49. });
  50. it("shows pin locally/globally/unpin buttons", function() {
  51. /* jshint ignore:start */
  52. testUtils.render(
  53. <Controls className="test-controls" moderation={{
  54. can_approve: false,
  55. can_close: false,
  56. can_hide: false,
  57. can_move: false,
  58. can_merge: false,
  59. can_pin: 2
  60. }} />
  61. );
  62. /* jshint ignore:end */
  63. const element = $('#test-mount .test-controls');
  64. assert.ok(element.length, "component renders");
  65. assert.equal(element.find('li').length, 3,
  66. "pin locally/globally/unpin moderation controls are shown");
  67. });
  68. it("shows move button", function() {
  69. /* jshint ignore:start */
  70. testUtils.render(
  71. <Controls className="test-controls" moderation={{
  72. can_approve: false,
  73. can_close: false,
  74. can_hide: false,
  75. can_move: true,
  76. can_merge: false,
  77. can_pin: false
  78. }} />
  79. );
  80. /* jshint ignore:end */
  81. const element = $('#test-mount .test-controls');
  82. assert.ok(element.length, "component renders");
  83. assert.equal(element.find('li').length, 1,
  84. "move moderation controls are shown");
  85. });
  86. it("shows merge button", function() {
  87. /* jshint ignore:start */
  88. testUtils.render(
  89. <Controls className="test-controls" moderation={{
  90. can_approve: false,
  91. can_close: false,
  92. can_hide: false,
  93. can_move: false,
  94. can_merge: true,
  95. can_pin: false
  96. }} />
  97. );
  98. /* jshint ignore:end */
  99. const element = $('#test-mount .test-controls');
  100. assert.ok(element.length, "component renders");
  101. assert.equal(element.find('li').length, 1,
  102. "merge moderation controls are shown");
  103. });
  104. it("shows approve button", function() {
  105. /* jshint ignore:start */
  106. testUtils.render(
  107. <Controls className="test-controls" moderation={{
  108. can_approve: true,
  109. can_close: false,
  110. can_hide: false,
  111. can_move: false,
  112. can_merge: false,
  113. can_pin: false
  114. }} />
  115. );
  116. /* jshint ignore:end */
  117. const element = $('#test-mount .test-controls');
  118. assert.ok(element.length, "component renders");
  119. assert.equal(element.find('li').length, 1,
  120. "approve moderation controls are shown");
  121. });
  122. it("shows close/open buttons", function() {
  123. /* jshint ignore:start */
  124. testUtils.render(
  125. <Controls className="test-controls" moderation={{
  126. can_approve: false,
  127. can_close: true,
  128. can_hide: false,
  129. can_move: false,
  130. can_merge: false,
  131. can_pin: false
  132. }} />
  133. );
  134. /* jshint ignore:end */
  135. const element = $('#test-mount .test-controls');
  136. assert.ok(element.length, "component renders");
  137. assert.equal(element.find('li').length, 2,
  138. "close/open moderation controls are shown");
  139. });
  140. it("shows hide/unhide buttons", function() {
  141. /* jshint ignore:start */
  142. testUtils.render(
  143. <Controls className="test-controls" moderation={{
  144. can_approve: false,
  145. can_close: false,
  146. can_hide: true,
  147. can_move: false,
  148. can_merge: false,
  149. can_pin: false
  150. }} />
  151. );
  152. /* jshint ignore:end */
  153. const element = $('#test-mount .test-controls');
  154. assert.ok(element.length, "component renders");
  155. assert.equal(element.find('li').length, 2,
  156. "hide/unhide moderation controls are shown");
  157. });
  158. it("shows hide/delete/unhide buttons", function() {
  159. /* jshint ignore:start */
  160. testUtils.render(
  161. <Controls className="test-controls" moderation={{
  162. can_approve: false,
  163. can_close: false,
  164. can_hide: 2,
  165. can_move: false,
  166. can_merge: false,
  167. can_pin: false
  168. }} />
  169. );
  170. /* jshint ignore:end */
  171. const element = $('#test-mount .test-controls');
  172. assert.ok(element.length, "component renders");
  173. assert.equal(element.find('li').length, 3,
  174. "hide/delete/unhide moderation controls are shown");
  175. });
  176. });