last-activity.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. import assert from 'assert';
  2. import moment from 'moment';
  3. import React from 'react'; // jshint ignore:line
  4. import LastActivity from 'misago/components/categories/last-activity'; // jshint ignore:line
  5. import * as testUtils from 'misago/utils/test-utils';
  6. describe("Categories List Category Last Activity", function() {
  7. afterEach(function() {
  8. testUtils.unmountComponents();
  9. });
  10. it("renders category protected message", function() {
  11. /* jshint ignore:start */
  12. let category = {
  13. acl: {
  14. can_browse: false
  15. }
  16. };
  17. testUtils.render(<LastActivity category={category} />);
  18. /* jshint ignore:end */
  19. let element = $('#test-mount .category-thread-message');
  20. assert.ok(element.text().indexOf("category is protected") !== 1,
  21. "category is protected message is displayed");
  22. assert.equal(element.find('.material-icon').text(), 'highlight_off',
  23. "proper icon is used");
  24. });
  25. it("renders category private message", function() {
  26. /* jshint ignore:start */
  27. let category = {
  28. acl: {
  29. can_browse: true,
  30. can_see_all_threads: false
  31. }
  32. };
  33. testUtils.render(<LastActivity category={category} />);
  34. /* jshint ignore:end */
  35. let element = $('#test-mount .category-thread-message');
  36. assert.ok(element.text().indexOf("category is private") !== 1,
  37. "category is private message is displayed");
  38. assert.equal(element.find('.material-icon').text(), 'info_outline',
  39. "proper icon is used");
  40. });
  41. it("renders category empty message", function() {
  42. /* jshint ignore:start */
  43. let category = {
  44. last_thread_title: null,
  45. acl: {
  46. can_browse: true,
  47. can_see_all_threads: true
  48. }
  49. };
  50. testUtils.render(<LastActivity category={category} />);
  51. /* jshint ignore:end */
  52. let element = $('#test-mount .category-thread-message');
  53. assert.ok(element.text().indexOf("category is empty") !== 1,
  54. "category is empty message is displayed");
  55. assert.equal(element.find('.material-icon').text(), 'error_outline',
  56. "proper icon is used");
  57. });
  58. it("renders guest-posted thread", function() {
  59. let category = {
  60. last_thread_title: "Misago Test Thread",
  61. last_thread_url: '/test-thread/url-123/',
  62. last_post_url: '/test-thread/url-123/last/',
  63. last_poster_name: 'BobBoberson',
  64. last_poster_url: null,
  65. last_post_on: moment().subtract(3, 'days'),
  66. acl: {
  67. can_browse: true,
  68. can_see_all_threads: true
  69. }
  70. };
  71. /* jshint ignore:start */
  72. testUtils.render(<LastActivity category={category} />);
  73. /* jshint ignore:end */
  74. assert.equal($('#test-mount .thread-title').attr('href'),
  75. category.last_thread_url,
  76. "thread url is displayed");
  77. assert.equal($('#test-mount .thread-title').text(),
  78. category.last_thread_title,
  79. "thread name is displayed");
  80. assert.equal($('#test-mount span.poster-title').text(),
  81. category.last_poster_name,
  82. "non-anchor poster name is displayed");
  83. assert.equal($('#test-mount .last-title').text(),
  84. "3 days ago",
  85. "last post date is displayed");
  86. assert.equal($('#test-mount .last-title').attr('href'),
  87. category.last_post_url,
  88. "last post url is displayed");
  89. });
  90. it("renders thread", function() {
  91. let category = {
  92. last_thread_title: "Misago Test Thread",
  93. last_thread_url: '/test-thread/url-123/',
  94. last_post_url: '/test-thread/url-123/last/',
  95. last_poster_name: 'BobBoberson',
  96. last_poster_url: '/user/bobberson-13213/',
  97. last_post_on: moment().subtract(3, 'days'),
  98. acl: {
  99. can_browse: true,
  100. can_see_all_threads: true
  101. }
  102. };
  103. /* jshint ignore:start */
  104. testUtils.render(<LastActivity category={category} />);
  105. /* jshint ignore:end */
  106. assert.equal($('#test-mount .thread-title').attr('href'),
  107. category.last_thread_url,
  108. "thread url is displayed");
  109. assert.equal($('#test-mount .thread-title').text(),
  110. category.last_thread_title,
  111. "thread name is displayed");
  112. assert.equal($('#test-mount a.poster-title').attr('href'),
  113. category.last_poster_url,
  114. "url to poster's profile is displayed");
  115. assert.equal($('#test-mount a.poster-title').text(),
  116. category.last_poster_name,
  117. "non-anchor poster name is displayed");
  118. assert.equal($('#test-mount .last-title').text(),
  119. "3 days ago",
  120. "last post date is displayed");
  121. assert.equal($('#test-mount .last-title').attr('href'),
  122. category.last_post_url,
  123. "last post url is displayed");
  124. });
  125. });