last-activity.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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 .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 .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 .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_poster_name: 'BobBoberson',
  63. last_poster_url: null,
  64. last_post_on: moment().subtract(3, 'days'),
  65. acl: {
  66. can_browse: true,
  67. can_see_all_threads: true
  68. }
  69. };
  70. /* jshint ignore:start */
  71. testUtils.render(<LastActivity category={category} />);
  72. /* jshint ignore:end */
  73. assert.equal($('#test-mount .thread-title a').attr('href'),
  74. category.last_thread_url,
  75. "thread url is displayed");
  76. assert.equal($('#test-mount .thread-title a').text(),
  77. category.last_thread_title,
  78. "thread name is displayed");
  79. assert.equal($('#test-mount .poster-name span.item-title').text(),
  80. category.last_poster_name,
  81. "non-anchor poster name is displayed");
  82. assert.equal($('#test-mount .thread-date abbr').text(),
  83. "3 days ago",
  84. "last post date is displayed");
  85. });
  86. it("renders thread", function() {
  87. let category = {
  88. last_thread_title: "Misago Test Thread",
  89. last_thread_url: '/test-thread/url-123/',
  90. last_poster_name: 'BobBoberson',
  91. last_poster_url: '/user/bobberson-13213/',
  92. last_post_on: moment().subtract(3, 'days'),
  93. acl: {
  94. can_browse: true,
  95. can_see_all_threads: true
  96. }
  97. };
  98. /* jshint ignore:start */
  99. testUtils.render(<LastActivity category={category} />);
  100. /* jshint ignore:end */
  101. assert.equal($('#test-mount .thread-title a').attr('href'),
  102. category.last_thread_url,
  103. "thread url is displayed");
  104. assert.equal($('#test-mount .thread-title a').text(),
  105. category.last_thread_title,
  106. "thread name is displayed");
  107. assert.equal($('#test-mount .poster-name a.item-title').attr('href'),
  108. category.last_poster_url,
  109. "url to poster's profile is displayed");
  110. assert.equal($('#test-mount .poster-name a.item-title').text(),
  111. category.last_poster_name,
  112. "non-anchor poster name is displayed");
  113. assert.equal($('#test-mount .thread-date abbr').text(),
  114. "3 days ago",
  115. "last post date is displayed");
  116. });
  117. });