navbar-dropdown.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. import assert from 'assert';
  2. import React from 'react'; // jshint ignore:line
  3. import store from 'misago/services/store';
  4. import { MobileNavbarDropdown } from 'misago/services/mobile-navbar-dropdown';
  5. import * as testUtils from 'misago/utils/test-utils';
  6. var dropdown = null;
  7. class TestComponentA extends React.Component {
  8. render() {
  9. /* jshint ignore:start */
  10. return <div className="dropdown-a">
  11. <p>This is first test dropdown!</p>
  12. </div>;
  13. /* jshint ignore:end */
  14. }
  15. }
  16. class TestComponentB extends React.Component {
  17. render() {
  18. /* jshint ignore:start */
  19. return <div className="dropdown-b">
  20. <p>This is second test dropdown!</p>
  21. </div>;
  22. /* jshint ignore:end */
  23. }
  24. }
  25. describe("Dropdown", function() {
  26. beforeEach(function() {
  27. dropdown = new MobileNavbarDropdown();
  28. dropdown.init(document.getElementById('dropdown-mount'));
  29. store.constructor();
  30. store.addReducer('test', function(state={}, action=null) { return {}; }, {}); // jshint ignore:line
  31. store.init();
  32. });
  33. afterEach(function() {
  34. testUtils.unmountComponents();
  35. });
  36. it('shows component', function(done) {
  37. dropdown.show(TestComponentA);
  38. window.setTimeout(function() {
  39. let element = $('#dropdown-mount .dropdown-a');
  40. assert.ok(element.length, "component was rendered");
  41. done();
  42. }, 100);
  43. });
  44. it('shows and cycles component', function(done) {
  45. dropdown.show(TestComponentA);
  46. window.setTimeout(function() {
  47. let element = $('#dropdown-mount .dropdown-a');
  48. assert.ok(element.length, "component was rendered");
  49. dropdown.show(TestComponentB);
  50. }, 100);
  51. window.setTimeout(function() {
  52. let element = $('#dropdown-mount .dropdown-b');
  53. assert.ok(element.length, "component was toggled");
  54. done();
  55. }, 300);
  56. });
  57. });