user-menu.js 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. import assert from 'assert';
  2. import React from 'react'; // jshint ignore:line
  3. import { UserMenu, UserNav, CompactUserNav } from 'misago/components/user-menu/user-nav'; // jshint ignore:line
  4. import misago from 'misago/index';
  5. import dropdown from 'misago/services/mobile-navbar-dropdown';
  6. import store from 'misago/services/store';
  7. import * as testUtils from 'misago/utils/test-utils';
  8. describe("User Menu", function() {
  9. beforeEach(function() {
  10. testUtils.contextClear(misago);
  11. testUtils.contextAuthenticated(misago);
  12. testUtils.initEmptyStore(store);
  13. testUtils.initDropdown(dropdown);
  14. /* jshint ignore:start */
  15. testUtils.render(<UserMenu user={misago._context.user} />);
  16. /* jshint ignore:end */
  17. });
  18. afterEach(function() {
  19. testUtils.unmountComponents();
  20. });
  21. it('renders', function() {
  22. let element = $('#test-mount .dropdown-menu');
  23. assert.ok(element.length, "component renders");
  24. });
  25. });
  26. describe("User Nav", function() {
  27. beforeEach(function() {
  28. testUtils.contextClear(misago);
  29. testUtils.contextAuthenticated(misago);
  30. testUtils.initEmptyStore(store);
  31. testUtils.initDropdown(dropdown);
  32. /* jshint ignore:start */
  33. testUtils.render(<UserNav user={misago._context.user} />);
  34. /* jshint ignore:end */
  35. });
  36. afterEach(function() {
  37. testUtils.unmountComponents();
  38. });
  39. it('renders', function() {
  40. let element = $('#test-mount .user-dropdown');
  41. assert.ok(element.length, "component renders");
  42. });
  43. });
  44. describe("Compact User Nav", function() {
  45. beforeEach(function() {
  46. testUtils.contextClear(misago);
  47. testUtils.contextAuthenticated(misago);
  48. store.constructor();
  49. store.addReducer('auth', function(state={}, action=null){
  50. if (action) {
  51. return state;
  52. }
  53. }, {
  54. 'isAuthenticated': misago.get('isAuthenticated'),
  55. 'isAnonymous': !misago.get('isAuthenticated'),
  56. 'user': misago.get('user')
  57. });
  58. store.init();
  59. testUtils.initDropdown(dropdown);
  60. /* jshint ignore:start */
  61. testUtils.render(<CompactUserNav user={misago._context.user} />);
  62. /* jshint ignore:end */
  63. });
  64. afterEach(function() {
  65. testUtils.unmountComponents();
  66. });
  67. it('renders', function() {
  68. let element = $('#test-mount img.user-avatar');
  69. assert.ok(element.length, "component renders");
  70. });
  71. it('opens dropdown on click', function() {
  72. testUtils.simulateClick('#test-mount button');
  73. let element = $('#dropdown-mount>.user-dropdown');
  74. assert.ok(element.length, "component opened dropdown");
  75. });
  76. });