ready.js 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  1. import assert from 'assert';
  2. import moment from 'moment'; // jshint ignore:line
  3. import React from 'react'; // jshint ignore:line
  4. import ListReady from 'misago/components/threads-list/list/ready'; // jshint ignore:line
  5. import * as testUtils from 'misago/utils/test-utils';
  6. /* jshint ignore:start */
  7. const props = {
  8. threads: [
  9. {
  10. id: 123,
  11. category: 3,
  12. title: "Doloremque alias repudiandae magnam facilis eligendi.",
  13. weight: 0,
  14. top_category: 3,
  15. replies: 2,
  16. has_unapproved_posts: false,
  17. started_on: moment("2016-04-17T16:37:42.317994Z"),
  18. last_post: 68707,
  19. last_poster_name: "Amya",
  20. last_poster_url: "/user/amya-1522/",
  21. last_post_on: moment("2016-04-17T16:37:42.364183Z"),
  22. is_read: true,
  23. is_unapproved: false,
  24. is_hidden: false,
  25. is_closed: false,
  26. absolute_url: "/threads/not-implemented-yet-123/",
  27. last_post_url: "/threads/not-implemented-yet-123/last/",
  28. new_post_url: "/threads/not-implemented-yet-123/new/",
  29. subscription: true,
  30. api_url: "/api/threads/123/",
  31. moderation: [],
  32. acl: {
  33. can_edit: true,
  34. can_reply: true,
  35. can_hide: 2,
  36. can_close: 1,
  37. can_report: 1,
  38. can_see_reports: 1,
  39. can_move: 1,
  40. can_pin: 2,
  41. can_approve: 1
  42. }
  43. },
  44. {
  45. id: 42,
  46. category: 4,
  47. title: "Sit facere pariatur consequatur qui voluptatum ducimus.",
  48. weight: 0,
  49. top_category: 3,
  50. replies: 3,
  51. has_unapproved_posts: false,
  52. started_on: moment("2016-04-17T16:37:13.224850Z"),
  53. last_post: 67637,
  54. last_poster_name: "Madora",
  55. last_poster_url: "/user/madora-1530/",
  56. last_post_on: moment("2016-04-17T16:37:13.287355Z"),
  57. is_read: true,
  58. is_unapproved: false,
  59. is_hidden: false,
  60. is_closed: false,
  61. absolute_url: "/threads/not-implemented-yet-42/",
  62. last_post_url: "/threads/not-implemented-yet-42/last/",
  63. new_post_url: "/threads/not-implemented-yet-42/new/",
  64. subscription: null,
  65. api_url: "/api/threads/42/",
  66. moderation: [],
  67. acl: {
  68. can_edit: true,
  69. can_reply: true,
  70. can_hide: 2,
  71. can_close: 1,
  72. can_report: 1,
  73. can_see_reports: 1,
  74. can_move: 1,
  75. can_pin: 2,
  76. can_approve: 1
  77. }
  78. }
  79. ],
  80. categories: {
  81. 2: {
  82. id: 2,
  83. parent: null,
  84. name: "Root",
  85. description: null,
  86. css_class: null,
  87. absolute_url: "/",
  88. api_url: {
  89. read: "/api/threads/read/"
  90. },
  91. special_role: true
  92. },
  93. 3: {
  94. id: 3,
  95. parent: {
  96. id: 2,
  97. name: "Root",
  98. css_class: null,
  99. absolute_url: "/"
  100. },
  101. name: "First category",
  102. description: null,
  103. css_class: "accent",
  104. absolute_url: "/category/first-category-3/",
  105. api_url: {
  106. read: "/api/threads/read/?category=3"
  107. }
  108. },
  109. 4: {
  110. id: 4,
  111. parent: {
  112. id: 3,
  113. name: "First category",
  114. css_class: null,
  115. absolute_url: "/category/first-category-3/"
  116. },
  117. name: "Herma Turnpike",
  118. description: null,
  119. css_class: null,
  120. absolute_url: "/category/herma-turnpike-4/",
  121. api_url: {
  122. read: "/api/threads/read/?category=4"
  123. }
  124. }
  125. },
  126. list: {
  127. type: 'all',
  128. path: '',
  129. name: gettext("All"),
  130. longName: gettext("All threads")
  131. },
  132. diffSize: 0,
  133. applyDiff: null,
  134. showOptions: false,
  135. selection: [],
  136. busyThreads: []
  137. };
  138. /* jshint ignore:end */
  139. describe("Ready Threads List", function() {
  140. afterEach(function() {
  141. testUtils.unmountComponents();
  142. });
  143. it("renders", function(done) {
  144. /* jshint ignore:start */
  145. testUtils.render(<ListReady {...props} />);
  146. /* jshint ignore:end */
  147. testUtils.onElement('#test-mount .threads-list', function(element) {
  148. assert.ok(true, "component renders");
  149. assert.ok(!$(element).find('.thread-busy').length,
  150. "no thread is busy");
  151. assert.ok(!$(element).find('.thread-selected').length,
  152. "no thread is selected");
  153. assert.ok(!$(element).find('.thread-new').length,
  154. "no thread is unread");
  155. assert.ok(!$(element).find('.thread-new-posts').length,
  156. "no thread is unread");
  157. assert.ok(!$(element).find('.thread-pinned-globally').length,
  158. "no thread is pinned globally");
  159. assert.ok(!$(element).find('.thread-pinned-locally').length,
  160. "no thread is pinned locally");
  161. assert.ok(!$(element).find('.thread-unapproved').length,
  162. "no thread is unapproved");
  163. assert.ok(!$(element).find('.thread-unapproved-posts').length,
  164. "no thread has unapproved posts");
  165. assert.ok(!$(element).find('.thread-hidden').length,
  166. "no thread is hidden");
  167. assert.ok(!$(element).find('.thread-closed').length,
  168. "no thread is closed");
  169. assert.ok(!$(element).find('.thread-options').length,
  170. "no thread options are shown");
  171. done();
  172. });
  173. });
  174. it("renders with diff message", function(done) { // jshint ignore:line
  175. /* jshint ignore:start */
  176. const applyDiff = function() {
  177. assert.ok(true, "apply diff message runs callback");
  178. done();
  179. };
  180. const newProps = Object.assign({}, props, {
  181. diffSize: 1,
  182. applyDiff
  183. });
  184. testUtils.render(<ListReady {...newProps} />);
  185. /* jshint ignore:end */
  186. testUtils.onElement('#test-mount .threads-list .btn', function(element) {
  187. assert.ok(true, "component renders");
  188. assert.equal($(element).find('.diff-message').text(),
  189. "There is 1 new or updated thread. Click this message to show it.",
  190. "message about new threads is displayed");
  191. testUtils.simulateClick('.btn');
  192. });
  193. });
  194. it("renders with state flags and options", function(done) {
  195. /* jshint ignore:start */
  196. let newProps = Object.assign({}, props, {
  197. showOptions: true,
  198. selection: [123],
  199. busyThreads: [42]
  200. });
  201. newProps.threads[0] = Object.assign({}, newProps.threads[0], {
  202. weight: 2,
  203. has_unapproved_posts: false,
  204. is_read: false,
  205. is_unapproved: true,
  206. is_hidden: true,
  207. is_closed: true,
  208. moderation: [true]
  209. });
  210. newProps.threads[1] = Object.assign({}, newProps.threads[1], {
  211. weight: 1,
  212. has_unapproved_posts: true,
  213. moderation: [true]
  214. });
  215. testUtils.render(<ListReady {...newProps} />);
  216. /* jshint ignore:end */
  217. testUtils.onElement('#test-mount .threads-list', function(element) {
  218. assert.ok(true, "component renders");
  219. assert.equal($(element).find('.thread-busy').length, 1,
  220. "one thread is busy");
  221. assert.equal($(element).find('.thread-selected').length, 1,
  222. "one thread is selected");
  223. assert.ok($(element).find('.thread-new').length,
  224. "unread threads are shown");
  225. assert.ok($(element).find('.thread-new-posts').length,
  226. "unread threads have state flag");
  227. assert.ok($(element).find('.thread-pinned-globally').length,
  228. "globally pinned thread has state flag");
  229. assert.ok($(element).find('.thread-pinned-locally').length,
  230. "locally pinned thread has state flag");
  231. assert.ok($(element).find('.thread-unapproved').length,
  232. "unapproved thread has state flag");
  233. assert.ok($(element).find('.thread-unapproved-posts').length,
  234. "thread with unapproved posts has state flag");
  235. assert.ok($(element).find('.thread-hidden').length,
  236. "hidden thread has state flag");
  237. assert.ok($(element).find('.thread-closed').length,
  238. "closed thread has state flag");
  239. assert.ok($(element).find('.thread-options').length,
  240. "thread options are shown");
  241. done();
  242. });
  243. });
  244. });