options.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. import assert from 'assert';
  2. import moment from 'moment'; // jshint ignore:line
  3. import React from 'react'; // jshint ignore:line
  4. import ThreadOptions from 'misago/components/threads-list/thread/options'; // jshint ignore:line
  5. import Store from 'misago/services/store';
  6. import * as testUtils from 'misago/utils/test-utils';
  7. /* jshint ignore:start */
  8. const thread = {
  9. id: 123,
  10. category: 3,
  11. title: "Doloremque alias repudiandae magnam facilis eligendi.",
  12. weight: 0,
  13. top_category: 3,
  14. replies: 2,
  15. has_unapproved_posts: false,
  16. started_on: moment("2016-04-17T16:37:42.317994Z"),
  17. last_post: 68707,
  18. last_poster_name: "Amya",
  19. last_poster_url: "/user/amya-1522/",
  20. last_post_on: moment("2016-04-17T16:37:42.364183Z"),
  21. is_read: true,
  22. is_unapproved: false,
  23. is_hidden: false,
  24. is_closed: false,
  25. absolute_url: "/threads/not-implemented-yet-123/",
  26. last_post_url: "/threads/not-implemented-yet-123/last/",
  27. new_post_url: "/threads/not-implemented-yet-123/new/",
  28. subscription: true,
  29. api_url: "/api/threads/123/",
  30. moderation: [true],
  31. acl: {
  32. can_edit: true,
  33. can_reply: true,
  34. can_hide: 2,
  35. can_close: 1,
  36. can_report: 1,
  37. can_see_reports: 1,
  38. can_move: 1,
  39. can_pin: 2,
  40. can_approve: 1
  41. }
  42. };
  43. /* jshint ignore:end */
  44. describe("Threads List Thread Options", function() {
  45. afterEach(function() {
  46. testUtils.unmountComponents();
  47. });
  48. it("renders", function(done) {
  49. /* jshint ignore:start */
  50. testUtils.render(<ThreadOptions thread={thread} />);
  51. /* jshint ignore:end */
  52. testUtils.onElement('#test-mount .thread-options', function() {
  53. assert.ok(true, "component renders");
  54. done();
  55. });
  56. });
  57. it("hides selection when thread isnt moderable", function() {
  58. /* jshint ignore:start */
  59. const newThread = Object.assign({}, thread, {
  60. moderation: []
  61. })
  62. testUtils.render(<ThreadOptions thread={newThread} />);
  63. /* jshint ignore:end */
  64. assert.ok(!$('#test-mount .btn-checkbox').length,
  65. "thread without moderation options is not selectable");
  66. });
  67. it("selects thread", function(done) {
  68. Store._store = {
  69. dispatch: function(action) {
  70. assert.deepEqual(action, {
  71. type: 'SELECT_ITEM',
  72. item: 123
  73. });
  74. done();
  75. }
  76. };
  77. /* jshint ignore:start */
  78. testUtils.render(<ThreadOptions thread={thread} />);
  79. /* jshint ignore:end */
  80. testUtils.simulateClick('#test-mount .btn-checkbox');
  81. });
  82. it("deselects thread", function(done) {
  83. Store._store = {
  84. dispatch: function(action) {
  85. assert.deepEqual(action, {
  86. type: 'SELECT_ITEM',
  87. item: 123
  88. });
  89. done();
  90. }
  91. };
  92. /* jshint ignore:start */
  93. testUtils.render(<ThreadOptions thread={thread} isSelected={true} />);
  94. /* jshint ignore:end */
  95. testUtils.simulateClick('#test-mount .btn-checkbox');
  96. });
  97. });