import assert from 'assert'; import React from 'react'; // jshint ignore:line import ReactDOM from 'react-dom'; // jshint ignore:line import store from 'misago/services/store'; import { Modal } from 'misago/services/modal'; var modal = null; class TestModalA extends React.Component { render() { /* jshint ignore:start */ return

Modal A

This is first test modal!

; /* jshint ignore:end */ } } class TestModalB extends React.Component { render() { /* jshint ignore:start */ return

Modal B

This is second test modal!

; /* jshint ignore:end */ } } describe("Modal", function() { beforeEach(function() { modal = new Modal(); modal.init(document.getElementById('modal-mount')); window.initEmptyStore(store); }); afterEach(function() { window.emptyTestContainers(); }); it('shows component', function(done) { modal.show(TestModalA); window.setTimeout(function() { let element = $('#modal-mount .modal-a'); assert.ok(element.length, "component was rendered"); done(); }, 400); }); it('shows and cycles component', function(done) { modal.show(TestModalA); window.setTimeout(function() { let element = $('#modal-mount .modal-a'); assert.ok(element.length, "component was rendered"); modal.show(TestModalB); window.setTimeout(function() { let element = $('#modal-mount .modal-b'); assert.ok(element.length, "component was toggled"); done(); }, 200); }, 400); }); it('hides component', function(done) { modal.show(TestModalA); window.setTimeout(function() { let element = $('#modal-mount .modal-a'); assert.ok(element.length, "component was rendered"); modal.hide(); let wait = function() { if($('#modal-mount').children().length === 0) { assert.ok(true, "modal was emptied"); done(); } else { window.setTimeout(wait, 100); } }; wait(); }, 400); }); });