modal.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. import assert from 'assert';
  2. import React from 'react'; // jshint ignore:line
  3. import store from 'misago/services/store';
  4. import { Modal } from 'misago/services/modal';
  5. import * as testUtils from 'misago/utils/test-utils';
  6. var modal = null;
  7. class TestModalA extends React.Component {
  8. render() {
  9. /* jshint ignore:start */
  10. return <div className="modal-dialog modal-a">
  11. <div className="modal-content">
  12. <div className="modal-header">
  13. <button type="button" className="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
  14. <h4 className="modal-title">Modal A</h4>
  15. </div>
  16. <div className="modal-body">
  17. <p>This is first test modal!</p>
  18. </div>
  19. <div className="modal-footer">
  20. <button type="button" className="btn btn-default" data-dismiss="modal">Close</button>
  21. </div>
  22. </div>
  23. </div>;
  24. /* jshint ignore:end */
  25. }
  26. }
  27. class TestModalB extends React.Component {
  28. render() {
  29. /* jshint ignore:start */
  30. return <div className="modal-dialog modal-b">
  31. <div className="modal-content">
  32. <div className="modal-header">
  33. <button type="button" className="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
  34. <h4 className="modal-title">Modal B</h4>
  35. </div>
  36. <div className="modal-body">
  37. <p>This is second test modal!</p>
  38. </div>
  39. <div className="modal-footer">
  40. <button type="button" className="btn btn-default" data-dismiss="modal">Close</button>
  41. </div>
  42. </div>
  43. </div>;
  44. /* jshint ignore:end */
  45. }
  46. }
  47. describe("Modal", function() {
  48. beforeEach(function() {
  49. modal = new Modal();
  50. modal.init(document.getElementById('modal-mount'));
  51. testUtils.initEmptyStore(store);
  52. });
  53. afterEach(function() {
  54. testUtils.unmountComponents();
  55. });
  56. it('shows component', function(done) {
  57. modal.show(TestModalA);
  58. window.setTimeout(function() {
  59. let element = $('#modal-mount .modal-a');
  60. assert.ok(element.length, "component was rendered");
  61. done();
  62. }, 400);
  63. });
  64. it('shows and cycles component', function(done) {
  65. modal.show(TestModalA);
  66. window.setTimeout(function() {
  67. let element = $('#modal-mount .modal-a');
  68. assert.ok(element.length, "component was rendered");
  69. modal.show(TestModalB);
  70. window.setTimeout(function() {
  71. let element = $('#modal-mount .modal-b');
  72. assert.ok(element.length, "component was toggled");
  73. done();
  74. }, 200);
  75. }, 400);
  76. });
  77. it('hides component', function(done) {
  78. modal.show(TestModalA);
  79. window.setTimeout(function() {
  80. let element = $('#modal-mount .modal-a');
  81. assert.ok(element.length, "component was rendered");
  82. modal.hide();
  83. let wait = function() {
  84. if($('#modal-mount').children().length === 0) {
  85. assert.ok(true, "modal was emptied");
  86. done();
  87. } else {
  88. window.setTimeout(wait, 100);
  89. }
  90. };
  91. wait();
  92. }, 400);
  93. });
  94. });