});
describe('open()', function() {
- it('opens the modal', function() {
+ it('opens the modal', function(done) {
$html = $(template).appendTo('body');
plugin = new Foundation.Reveal($html, {});
- plugin.open();
+ $html.on('open.zf.reveal', function() {
+ $html.should.be.visible;
+ done();
+ });
- $html.should.be.visible;
+ plugin.open();
});
- it('opens the overlay', function() {
+ it('opens the overlay', function(done) {
$html = $(template).appendTo('body');
plugin = new Foundation.Reveal($html, {overlay: true});
- plugin.open();
+ $html.on('open.zf.reveal', function() {
+ plugin.$overlay.should.be.visible;
+ done();
+ });
- plugin.$overlay.should.be.visible;
+ plugin.open();
});
- it('toggles ARIA attributes', function() {
+ it('toggles ARIA attributes', function(done) {
$html = $(template).appendTo('body');
plugin = new Foundation.Reveal($html, {});
- plugin.open();
+ $html.on('open.zf.reveal', function() {
+ $html.should.have.attr('aria-hidden', 'false');
+ $html.should.have.attr('tabindex', '-1');
+ done();
+ });
- $html.should.have.attr('aria-hidden', 'false');
- $html.should.have.attr('tabindex', '-1');
+ plugin.open();
});
- it('adds class to body', function() {
+ it('adds class to body', function(done) {
$html = $(template).appendTo('body');
plugin = new Foundation.Reveal($html, {});
- plugin.open();
+ $html.on('open.zf.reveal', function() {
+ $('body').should.have.class('is-reveal-open');
+ done();
+ });
- $('body').should.have.class('is-reveal-open');
+ plugin.open();
});
- it('adds optional overlay classes overlay element', function() {
+ it('adds optional overlay classes overlay element', function(done) {
$html = $(template).appendTo('body');
plugin = new Foundation.Reveal($html, {additionalOverlayClasses: 'default'});
- plugin.open();
+ $html.on('open.zf.reveal', function() {
+ $('.reveal-overlay').should.have.class('default');
+ done();
+ });
- $('.reveal-overlay').should.have.class('default');
+ plugin.open();
});
// TODO: Check if this.$element.trigger('closeme.zf.reveal', this.id) is correctly used.
plugin.open();
});
- it('traps focus if trapFocus option is true', function() {
+ it('traps focus if trapFocus option is true', function(done) {
$html = $(template).appendTo('body');
plugin = new Foundation.Reveal($html, {trapFocus: true});
let spy = sinon.spy(Foundation.Keyboard, 'trapFocus');
- plugin.open();
- sinon.assert.called(spy);
- Foundation.Keyboard.trapFocus.restore();
+ $html.on('open.zf.reveal', function() {
+ sinon.assert.called(spy);
+ Foundation.Keyboard.trapFocus.restore();
+ done();
+ });
+
+ plugin.open();
});
});
describe('close()', function() {
- it('closes the modal', function() {
+ it('closes the modal', function(done) {
$html = $(template).appendTo('body');
plugin = new Foundation.Reveal($html, {});
// Open it first
plugin.open();
- plugin.close();
+ $html.on('closed.zf.reveal', function() {
+ $html.should.be.hidden;
+ done();
+ });
- $html.should.be.hidden;
+ plugin.close();
});
- it('closes the overlay', function() {
+ it('closes the overlay', function(done) {
$html = $(template).appendTo('body');
plugin = new Foundation.Reveal($html, {overlay: true});
// Open it first
plugin.open();
- plugin.close();
+ $html.on('closed.zf.reveal', function() {
+ plugin.$overlay.should.be.hidden;
+ done();
+ });
- plugin.$overlay.should.be.hidden;
+ plugin.close();
});
- it('toggles ARIA attributes', function() {
+ it('toggles ARIA attributes', function(done) {
$html = $(template).appendTo('body');
plugin = new Foundation.Reveal($html, {});
// Open it first
plugin.open();
- plugin.close();
+ $html.on('closed.zf.reveal', function() {
+ $html.should.have.attr('aria-hidden', 'true');
+ done();
+ });
- $html.should.have.attr('aria-hidden', 'true');
+ plugin.close();
});
it('removes class from body', function(done) {
$html = $(template).appendTo('body');
plugin.close();
});
- it('releases focus if trapFocus option is true', function() {
+ it('releases focus if trapFocus option is true', function(done) {
$html = $(template).appendTo('body');
plugin = new Foundation.Reveal($html, {trapFocus: true});
plugin.open();
let spy = sinon.spy(Foundation.Keyboard, 'releaseFocus');
- plugin.close();
- sinon.assert.called(spy);
- Foundation.Keyboard.releaseFocus.restore();
+ $html.on('closed.zf.reveal', function() {
+ sinon.assert.called(spy);
+ Foundation.Keyboard.releaseFocus.restore();
+ done();
+ });
+
+ plugin.close();
});
});
describe('toggle()', function() {
- it('opens a closed modal', function() {
+ it('opens a closed modal', function(done) {
$html = $(template).appendTo('body');
plugin = new Foundation.Reveal($html, {overlay: true});
- plugin.open();
+ $html.on('open.zf.reveal', function() {
+ plugin.$overlay.should.be.visible;
+ done();
+ });
- plugin.$overlay.should.be.visible;
+ plugin.open();
});
- it('closes an open modal', function() {
+ it('closes an open modal', function(done) {
$html = $(template).appendTo('body');
plugin = new Foundation.Reveal($html, {});
// Open it first
plugin.open();
- plugin.close();
+ $html.on('closed.zf.reveal', function() {
+ $html.should.be.hidden;
+ done();
+ });
- $html.should.be.hidden;
+ plugin.close();
});
});
describe('events()', function() {
- it('opens the modal on anchor click', function() {
+ it('opens the modal on anchor click', function(done) {
$html = $(template).appendTo('body');
var $anchor = $('<button data-open="exampleModal1">Open</button>').appendTo('body');
plugin = new Foundation.Reveal($html, {});
- $anchor.trigger('click');
- plugin.$overlay.should.be.visible;
- $anchor.remove();
+ $html.on('open.zf.reveal', function() {
+ plugin.$overlay.should.be.visible;
+ $anchor.remove();
+ done();
+ });
+
+ $anchor.trigger('click');
});
- it('closes a modal on overlay click if closeOnClick option is true', function() {
+ it('closes a modal on overlay click if closeOnClick option is true', function(done) {
$html = $(template).appendTo('body');
plugin = new Foundation.Reveal($html, {overlay: true, closeOnClick: true});
// Open it first
plugin.open();
- plugin.$overlay.trigger('click');
+ $html.on('closed.zf.reveal', function() {
+ $html.should.be.hidden;
+ done();
+ });
- $html.should.be.hidden;
+ plugin.$overlay.trigger('click');
});
- it('not closes a modal on overlay click if closeOnClick option is true', function() {
+ it('not closes a modal on overlay click if closeOnClick option is true', function(done) {
$html = $(template).appendTo('body');
plugin = new Foundation.Reveal($html, {overlay: true, closeOnClick: false});
plugin.$overlay.trigger('click');
- $html.should.be.visible;
+ // Add timeout to make sure it does not close
+ // Timeout is required because closed event will not be fired
+ setTimeout(function() {
+ $html.should.be.visible;
+ done();
+ }, 10);
});
});
});