navs.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. import assert from 'assert';
  2. import React from 'react'; // jshint ignore:line
  3. import { SideNav, CompactNav } from 'misago/components/profile/navs'; // jshint ignore:line
  4. import * as testUtils from 'misago/utils/test-utils';
  5. let pages = [
  6. {
  7. name: 'Followers',
  8. icon: 'heart',
  9. component: 'followers',
  10. meta: {attr: 'test_meta'}
  11. },
  12. {
  13. name: 'Ban details',
  14. icon: 'lock',
  15. component: 'ban-details'
  16. }
  17. ];
  18. let profileMock = {
  19. test_meta: 42,
  20. is_followed: false,
  21. acl: {
  22. can_follow: false,
  23. can_moderate: false
  24. }
  25. };
  26. describe("User Profile Side Nav", function() {
  27. afterEach(function() {
  28. testUtils.unmountComponents();
  29. });
  30. it("renders", function() {
  31. /* jshint ignore:start */
  32. testUtils.render(
  33. <SideNav baseUrl="/profile/"
  34. pages={pages}
  35. profile={profileMock} />
  36. );
  37. /* jshint ignore:end */
  38. let element = $('#test-mount .nav-side');
  39. assert.ok(element.length, "component renders");
  40. pages.forEach(function(page, i) {
  41. let link = $(element.find('a')[i]);
  42. assert.equal(link.find('.material-icon').text(), page.icon,
  43. "page link contains icon");
  44. assert.ok(link.text().indexOf(page.name) > 0,
  45. "page link contains name");
  46. if (page.meta) {
  47. assert.equal(link.find('.badge').text(), profileMock.test_meta,
  48. "page link contains badge");
  49. }
  50. });
  51. });
  52. });
  53. describe("User Profile Compact Nav", function() {
  54. beforeEach(function() {
  55. profileMock.acl = {
  56. can_follow: false,
  57. can_moderate: false
  58. };
  59. });
  60. afterEach(function() {
  61. testUtils.unmountComponents();
  62. });
  63. it("renders", function() {
  64. /* jshint ignore:start */
  65. testUtils.render(
  66. <CompactNav baseUrl="/profile/"
  67. pages={pages}
  68. profile={profileMock} />
  69. );
  70. /* jshint ignore:end */
  71. let element = $('#test-mount .dropdown-menu');
  72. assert.ok(element.length, "component renders");
  73. assert.ok(!element.find('.dropdown-buttons').length,
  74. "component has no special options");
  75. pages.forEach(function(page, i) {
  76. let link = $(element.find('a')[i]);
  77. assert.equal(link.find('.material-icon').text(), page.icon,
  78. "page link contains icon");
  79. assert.ok(link.text().indexOf(page.name) > 0,
  80. "page link contains name");
  81. if (page.meta) {
  82. assert.equal(link.find('.badge').text(), profileMock.test_meta,
  83. "page link contains badge");
  84. }
  85. });
  86. });
  87. it("renders follow button", function() {
  88. /* jshint ignore:start */
  89. profileMock.acl.can_follow = true;
  90. testUtils.render(
  91. <CompactNav baseUrl="/profile/"
  92. pages={pages}
  93. profile={profileMock} />
  94. );
  95. /* jshint ignore:end */
  96. let element = $('#test-mount .dropdown-menu .btn-follow');
  97. assert.ok(element.length, "follow button renders");
  98. });
  99. it("renders moderation button", function(done) { // jshint ignore:line
  100. /* jshint ignore:start */
  101. let toggleModeration = function() {
  102. assert.ok(true, "moderation toggle was clicked");
  103. done();
  104. }
  105. profileMock.acl.can_moderate = true;
  106. testUtils.render(
  107. <CompactNav baseUrl="/profile/"
  108. pages={pages}
  109. profile={profileMock}
  110. toggleModeration={toggleModeration} />
  111. );
  112. /* jshint ignore:end */
  113. testUtils.simulateClick('#test-mount .dropdown-menu .btn-block');
  114. });
  115. });