2016-08-04 17:49:32 +02:00
|
|
|
/* eslint-env qunit */
|
2015-10-28 19:28:15 +02:00
|
|
|
import CloseButton from '../../src/js/close-button';
|
2016-08-04 17:49:32 +02:00
|
|
|
import sinon from 'sinon';
|
2015-10-28 19:28:15 +02:00
|
|
|
import ModalDialog from '../../src/js/modal-dialog';
|
|
|
|
import * as Dom from '../../src/js/utils/dom';
|
|
|
|
import TestHelpers from './test-helpers';
|
|
|
|
|
2019-05-30 17:16:51 +02:00
|
|
|
const getMockEscapeEvent = () => ({
|
2024-05-23 18:50:23 +02:00
|
|
|
key: 'Escape',
|
2019-05-30 17:16:51 +02:00
|
|
|
which: 27,
|
|
|
|
preventDefault() {},
|
|
|
|
stopPropagation() {}
|
|
|
|
});
|
2015-10-28 19:28:15 +02:00
|
|
|
|
2016-08-04 17:49:32 +02:00
|
|
|
QUnit.module('ModalDialog', {
|
2015-10-28 19:28:15 +02:00
|
|
|
|
2016-08-04 17:49:32 +02:00
|
|
|
beforeEach() {
|
2015-10-28 19:28:15 +02:00
|
|
|
this.player = TestHelpers.makePlayer();
|
|
|
|
this.modal = new ModalDialog(this.player, {temporary: false});
|
|
|
|
this.el = this.modal.el();
|
|
|
|
},
|
|
|
|
|
2016-08-04 17:49:32 +02:00
|
|
|
afterEach() {
|
2015-10-28 19:28:15 +02:00
|
|
|
this.player.dispose();
|
|
|
|
this.modal.dispose();
|
|
|
|
this.el = null;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2017-02-09 00:29:05 +02:00
|
|
|
const tabTestHelper = function(assert, player) {
|
2019-04-29 18:01:37 +02:00
|
|
|
return function(fromIndex, toIndex, shift = false) {
|
|
|
|
const oldFocusableEls = ModalDialog.prototype.focusableEls_;
|
|
|
|
const focus = function() {
|
|
|
|
assert.equal(this.i, toIndex, `we should focus back on the ${toIndex} element, we got ${this.i}.`);
|
|
|
|
};
|
|
|
|
const els = [
|
|
|
|
{i: 0, focus},
|
|
|
|
{i: 1, focus},
|
|
|
|
{i: 2, focus},
|
|
|
|
{i: 3, focus}
|
|
|
|
];
|
|
|
|
|
|
|
|
ModalDialog.prototype.focusableEls_ = () => els;
|
|
|
|
|
2017-02-09 00:29:05 +02:00
|
|
|
const modal = new ModalDialog(player, {});
|
2019-04-29 18:01:37 +02:00
|
|
|
const oldEl = modal.el_;
|
2017-02-09 00:29:05 +02:00
|
|
|
|
2019-04-29 18:01:37 +02:00
|
|
|
modal.el_ = {
|
|
|
|
querySelector() {
|
|
|
|
const focusableEls = modal.focusableEls_();
|
|
|
|
|
|
|
|
return focusableEls[fromIndex];
|
|
|
|
}
|
|
|
|
};
|
2017-02-09 00:29:05 +02:00
|
|
|
|
|
|
|
let prevented = false;
|
|
|
|
|
|
|
|
modal.handleKeyDown({
|
|
|
|
which: 9,
|
|
|
|
shiftKey: shift,
|
|
|
|
preventDefault() {
|
|
|
|
prevented = true;
|
2019-05-30 17:16:51 +02:00
|
|
|
},
|
|
|
|
stopPropagation() {
|
2017-02-09 00:29:05 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
if (!prevented) {
|
2019-04-29 18:01:37 +02:00
|
|
|
const newIndex = shift ? fromIndex - 1 : fromIndex + 1;
|
2017-02-09 00:29:05 +02:00
|
|
|
const newEl = modal.focusableEls_()[newIndex];
|
|
|
|
|
|
|
|
if (newEl) {
|
|
|
|
newEl.focus(newEl.i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-29 18:01:37 +02:00
|
|
|
modal.el_ = oldEl;
|
2017-02-09 00:29:05 +02:00
|
|
|
modal.dispose();
|
2019-04-29 18:01:37 +02:00
|
|
|
ModalDialog.prototype.focusableEls_ = oldFocusableEls;
|
2017-02-09 00:29:05 +02:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2016-08-04 17:49:32 +02:00
|
|
|
QUnit.test('should create the expected element', function(assert) {
|
|
|
|
const elAssertions = TestHelpers.assertEl(assert, this.el, {
|
2015-10-28 19:28:15 +02:00
|
|
|
tagName: 'div',
|
|
|
|
classes: [
|
|
|
|
'vjs-modal-dialog',
|
|
|
|
'vjs-hidden'
|
|
|
|
],
|
|
|
|
attrs: {
|
|
|
|
'aria-describedby': this.modal.descEl_.id,
|
|
|
|
'aria-hidden': 'true',
|
|
|
|
'aria-label': this.modal.label(),
|
|
|
|
'role': 'dialog'
|
|
|
|
},
|
|
|
|
props: {
|
|
|
|
tabIndex: -1
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
assert.expect(elAssertions.count);
|
|
|
|
elAssertions();
|
|
|
|
});
|
|
|
|
|
2016-08-04 17:49:32 +02:00
|
|
|
QUnit.test('should create the expected description element', function(assert) {
|
|
|
|
const elAssertions = TestHelpers.assertEl(assert, this.modal.descEl_, {
|
2015-10-28 19:28:15 +02:00
|
|
|
tagName: 'p',
|
|
|
|
innerHTML: this.modal.description(),
|
|
|
|
classes: [
|
|
|
|
'vjs-modal-dialog-description',
|
2017-02-21 22:58:04 +02:00
|
|
|
'vjs-control-text'
|
2015-10-28 19:28:15 +02:00
|
|
|
],
|
|
|
|
attrs: {
|
|
|
|
id: this.el.getAttribute('aria-describedby')
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
assert.expect(elAssertions.count);
|
|
|
|
elAssertions();
|
|
|
|
});
|
|
|
|
|
2016-08-04 17:49:32 +02:00
|
|
|
QUnit.test('should create the expected contentEl', function(assert) {
|
|
|
|
const elAssertions = TestHelpers.assertEl(assert, this.modal.contentEl(), {
|
2015-10-28 19:28:15 +02:00
|
|
|
tagName: 'div',
|
|
|
|
classes: [
|
|
|
|
'vjs-modal-dialog-content'
|
|
|
|
],
|
|
|
|
props: {
|
|
|
|
parentNode: this.el
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
assert.expect(elAssertions.count);
|
|
|
|
elAssertions();
|
|
|
|
});
|
|
|
|
|
2016-08-04 17:49:32 +02:00
|
|
|
QUnit.test('should create a close button by default', function(assert) {
|
|
|
|
const btn = this.modal.getChild('closeButton');
|
2015-10-28 19:28:15 +02:00
|
|
|
|
|
|
|
// We only check the aspects of the button that relate to the modal. Other
|
|
|
|
// aspects of the button (classes, etc) are tested in their appropriate test
|
|
|
|
// module.
|
|
|
|
assert.expect(2);
|
|
|
|
assert.ok(btn instanceof CloseButton, 'close button is a CloseButton');
|
|
|
|
assert.strictEqual(btn.el().parentNode, this.el, 'close button is a child of el');
|
|
|
|
});
|
|
|
|
|
2016-08-04 17:49:32 +02:00
|
|
|
QUnit.test('open() triggers events', function(assert) {
|
|
|
|
const modal = this.modal;
|
|
|
|
const beforeModalOpenSpy = sinon.spy(function() {
|
2015-10-28 19:28:15 +02:00
|
|
|
assert.notOk(modal.opened(), 'modal is not opened before opening event');
|
|
|
|
});
|
|
|
|
|
2016-08-04 17:49:32 +02:00
|
|
|
const modalOpenSpy = sinon.spy(function() {
|
2015-10-28 19:28:15 +02:00
|
|
|
assert.ok(modal.opened(), 'modal is opened on opening event');
|
|
|
|
});
|
|
|
|
|
|
|
|
assert.expect(4);
|
|
|
|
|
2017-01-18 08:50:22 +02:00
|
|
|
modal.on('beforemodalopen', beforeModalOpenSpy);
|
|
|
|
modal.on('modalopen', modalOpenSpy);
|
|
|
|
modal.open();
|
2015-10-28 19:28:15 +02:00
|
|
|
|
|
|
|
assert.strictEqual(beforeModalOpenSpy.callCount, 1, 'beforemodalopen spy was called');
|
|
|
|
assert.strictEqual(modalOpenSpy.callCount, 1, 'modalopen spy was called');
|
|
|
|
});
|
|
|
|
|
2016-08-04 17:49:32 +02:00
|
|
|
QUnit.test('open() removes "vjs-hidden" class', function(assert) {
|
2015-10-28 19:28:15 +02:00
|
|
|
assert.expect(2);
|
|
|
|
assert.ok(this.modal.hasClass('vjs-hidden'), 'modal starts hidden');
|
|
|
|
this.modal.open();
|
|
|
|
assert.notOk(this.modal.hasClass('vjs-hidden'), 'modal is not hidden after opening');
|
|
|
|
});
|
|
|
|
|
2016-08-04 17:49:32 +02:00
|
|
|
QUnit.test('open() cannot be called on an opened modal', function(assert) {
|
|
|
|
const spy = sinon.spy();
|
2015-10-28 19:28:15 +02:00
|
|
|
|
2017-01-18 08:50:22 +02:00
|
|
|
this.modal.on('modalopen', spy);
|
|
|
|
this.modal.open();
|
|
|
|
this.modal.open();
|
2015-10-28 19:28:15 +02:00
|
|
|
|
|
|
|
assert.expect(1);
|
|
|
|
assert.strictEqual(spy.callCount, 1, 'modal was only opened once');
|
|
|
|
});
|
|
|
|
|
2016-08-04 17:49:32 +02:00
|
|
|
QUnit.test('close() triggers events', function(assert) {
|
|
|
|
const modal = this.modal;
|
|
|
|
const beforeModalCloseSpy = sinon.spy(function() {
|
2015-10-28 19:28:15 +02:00
|
|
|
assert.ok(modal.opened(), 'modal is not closed before closing event');
|
|
|
|
});
|
|
|
|
|
2016-08-04 17:49:32 +02:00
|
|
|
const modalCloseSpy = sinon.spy(function() {
|
2015-10-28 19:28:15 +02:00
|
|
|
assert.notOk(modal.opened(), 'modal is closed on closing event');
|
|
|
|
});
|
|
|
|
|
|
|
|
assert.expect(4);
|
|
|
|
|
2017-01-18 08:50:22 +02:00
|
|
|
modal.on('beforemodalclose', beforeModalCloseSpy);
|
|
|
|
modal.on('modalclose', modalCloseSpy);
|
|
|
|
modal.open();
|
|
|
|
modal.close();
|
2015-10-28 19:28:15 +02:00
|
|
|
|
|
|
|
assert.strictEqual(beforeModalCloseSpy.callCount, 1, 'beforemodalclose spy was called');
|
|
|
|
assert.strictEqual(modalCloseSpy.callCount, 1, 'modalclose spy was called');
|
|
|
|
});
|
|
|
|
|
2016-08-04 17:49:32 +02:00
|
|
|
QUnit.test('close() adds the "vjs-hidden" class', function(assert) {
|
2015-10-28 19:28:15 +02:00
|
|
|
assert.expect(1);
|
2017-01-18 08:50:22 +02:00
|
|
|
this.modal.open();
|
|
|
|
this.modal.close();
|
2015-10-28 19:28:15 +02:00
|
|
|
assert.ok(this.modal.hasClass('vjs-hidden'), 'modal is hidden upon close');
|
|
|
|
});
|
|
|
|
|
2016-08-04 17:49:32 +02:00
|
|
|
QUnit.test('pressing ESC triggers close(), but only when the modal is opened', function(assert) {
|
|
|
|
const spy = sinon.spy();
|
2015-10-28 19:28:15 +02:00
|
|
|
|
2017-01-18 08:50:22 +02:00
|
|
|
this.modal.on('modalclose', spy);
|
2019-05-30 17:16:51 +02:00
|
|
|
this.modal.handleKeyDown(getMockEscapeEvent());
|
2015-10-28 19:28:15 +02:00
|
|
|
assert.expect(2);
|
|
|
|
assert.strictEqual(spy.callCount, 0, 'ESC did not close the closed modal');
|
|
|
|
|
2017-01-18 08:50:22 +02:00
|
|
|
this.modal.open();
|
2019-05-30 17:16:51 +02:00
|
|
|
this.modal.handleKeyDown(getMockEscapeEvent());
|
2015-10-28 19:28:15 +02:00
|
|
|
assert.strictEqual(spy.callCount, 1, 'ESC closed the now-opened modal');
|
|
|
|
});
|
|
|
|
|
2016-08-04 17:49:32 +02:00
|
|
|
QUnit.test('close() cannot be called on a closed modal', function(assert) {
|
|
|
|
const spy = sinon.spy();
|
2015-10-28 19:28:15 +02:00
|
|
|
|
|
|
|
this.modal.on('modalclose', spy);
|
2017-01-18 08:50:22 +02:00
|
|
|
this.modal.open();
|
|
|
|
this.modal.close();
|
|
|
|
this.modal.close();
|
2015-10-28 19:28:15 +02:00
|
|
|
|
|
|
|
assert.expect(1);
|
|
|
|
assert.strictEqual(spy.callCount, 1, 'modal was only closed once');
|
|
|
|
});
|
|
|
|
|
2016-08-04 17:49:32 +02:00
|
|
|
QUnit.test('open() pauses playback, close() resumes', function(assert) {
|
|
|
|
const playSpy = sinon.spy();
|
|
|
|
const pauseSpy = sinon.spy();
|
2015-10-28 19:28:15 +02:00
|
|
|
|
|
|
|
// Quick and dirty; make it looks like the player is playing.
|
|
|
|
this.player.paused = function() {
|
|
|
|
return false;
|
|
|
|
};
|
|
|
|
|
|
|
|
this.player.play = function() {
|
|
|
|
playSpy();
|
|
|
|
};
|
|
|
|
|
|
|
|
this.player.pause = function() {
|
|
|
|
pauseSpy();
|
|
|
|
};
|
|
|
|
|
|
|
|
this.modal.open();
|
|
|
|
|
|
|
|
assert.expect(2);
|
|
|
|
assert.strictEqual(pauseSpy.callCount, 1, 'player is paused when the modal opens');
|
|
|
|
|
|
|
|
this.modal.close();
|
|
|
|
assert.strictEqual(playSpy.callCount, 1, 'player is resumed when the modal closes');
|
|
|
|
});
|
|
|
|
|
2017-03-13 17:26:33 +02:00
|
|
|
QUnit.test('open() does not pause, close() does not play() with pauseOnOpen set to false', function(assert) {
|
|
|
|
const playSpy = sinon.spy();
|
|
|
|
const pauseSpy = sinon.spy();
|
|
|
|
|
|
|
|
// don't pause the video on modal open
|
|
|
|
this.modal.options_.pauseOnOpen = false;
|
|
|
|
|
|
|
|
// Quick and dirty; make it looks like the player is playing.
|
|
|
|
this.player.paused = function() {
|
|
|
|
return false;
|
|
|
|
};
|
|
|
|
|
|
|
|
this.player.play = function() {
|
|
|
|
playSpy();
|
|
|
|
};
|
|
|
|
|
|
|
|
this.player.pause = function() {
|
|
|
|
pauseSpy();
|
|
|
|
};
|
|
|
|
|
|
|
|
this.modal.open();
|
|
|
|
|
|
|
|
assert.expect(2);
|
|
|
|
assert.strictEqual(pauseSpy.callCount, 0, 'player remains playing when the modal opens');
|
|
|
|
|
|
|
|
this.modal.close();
|
|
|
|
assert.strictEqual(playSpy.callCount, 0, 'player is resumed when the modal closes');
|
|
|
|
});
|
|
|
|
|
2016-08-04 17:49:32 +02:00
|
|
|
QUnit.test('open() hides controls, close() shows controls', function(assert) {
|
2017-10-31 17:35:01 +02:00
|
|
|
this.player.controls(true);
|
2015-10-28 19:28:15 +02:00
|
|
|
this.modal.open();
|
|
|
|
|
|
|
|
assert.expect(2);
|
|
|
|
assert.notOk(this.player.controls_, 'controls are hidden');
|
|
|
|
|
|
|
|
this.modal.close();
|
|
|
|
assert.ok(this.player.controls_, 'controls are no longer hidden');
|
|
|
|
});
|
|
|
|
|
2017-10-31 17:35:01 +02:00
|
|
|
QUnit.test('open() hides controls, close() does not show controls if previously hidden', function(assert) {
|
|
|
|
this.player.controls(false);
|
|
|
|
this.modal.open();
|
|
|
|
|
|
|
|
assert.expect(2);
|
|
|
|
assert.notOk(this.player.controls_, 'controls are hidden');
|
|
|
|
|
|
|
|
this.modal.close();
|
|
|
|
assert.notOk(this.player.controls_, 'controls are still hidden');
|
|
|
|
});
|
|
|
|
|
2016-08-04 17:49:32 +02:00
|
|
|
QUnit.test('opened()', function(assert) {
|
|
|
|
const openSpy = sinon.spy();
|
|
|
|
const closeSpy = sinon.spy();
|
2015-10-28 19:28:15 +02:00
|
|
|
|
|
|
|
assert.expect(4);
|
|
|
|
assert.strictEqual(this.modal.opened(), false, 'the modal is closed');
|
|
|
|
this.modal.open();
|
|
|
|
assert.strictEqual(this.modal.opened(), true, 'the modal is open');
|
|
|
|
|
2017-01-18 08:50:22 +02:00
|
|
|
this.modal.close();
|
|
|
|
this.modal.on('modalopen', openSpy);
|
|
|
|
this.modal.on('modalclose', closeSpy);
|
|
|
|
this.modal.opened(true);
|
2015-10-28 19:28:15 +02:00
|
|
|
|
|
|
|
this.modal.opened(true);
|
|
|
|
this.modal.opened(false);
|
|
|
|
assert.strictEqual(openSpy.callCount, 1, 'modal was opened only once');
|
|
|
|
assert.strictEqual(closeSpy.callCount, 1, 'modal was closed only once');
|
|
|
|
});
|
|
|
|
|
2016-08-04 17:49:32 +02:00
|
|
|
QUnit.test('content()', function(assert) {
|
2015-10-28 19:28:15 +02:00
|
|
|
assert.expect(3);
|
|
|
|
assert.strictEqual(typeof this.modal.content(), 'undefined', 'no content by default');
|
|
|
|
|
2016-08-04 17:49:32 +02:00
|
|
|
const content = this.modal.content(Dom.createEl());
|
|
|
|
|
2015-10-28 19:28:15 +02:00
|
|
|
assert.ok(Dom.isEl(content), 'content was set from a single DOM element');
|
|
|
|
|
|
|
|
assert.strictEqual(this.modal.content(null), null, 'content was nullified');
|
|
|
|
});
|
|
|
|
|
2016-08-04 17:49:32 +02:00
|
|
|
QUnit.test('fillWith()', function(assert) {
|
|
|
|
const contentEl = this.modal.contentEl();
|
|
|
|
const children = [Dom.createEl(), Dom.createEl(), Dom.createEl()];
|
|
|
|
const beforeFillSpy = sinon.spy();
|
|
|
|
const fillSpy = sinon.spy();
|
2015-10-28 19:28:15 +02:00
|
|
|
|
|
|
|
children.forEach(function(el) {
|
|
|
|
contentEl.appendChild(el);
|
|
|
|
});
|
|
|
|
|
2017-01-18 08:50:22 +02:00
|
|
|
this.modal.on('beforemodalfill', beforeFillSpy);
|
|
|
|
this.modal.on('modalfill', fillSpy);
|
|
|
|
this.modal.fillWith(children);
|
2015-10-28 19:28:15 +02:00
|
|
|
|
|
|
|
assert.expect(5 + children.length);
|
|
|
|
assert.strictEqual(contentEl.children.length, children.length, 'has the right number of children');
|
|
|
|
|
|
|
|
children.forEach(function(el) {
|
|
|
|
assert.strictEqual(el.parentNode, contentEl, 'new child appended');
|
|
|
|
});
|
|
|
|
|
|
|
|
assert.strictEqual(beforeFillSpy.callCount, 1, 'the "beforemodalfill" callback was called');
|
|
|
|
assert.strictEqual(beforeFillSpy.getCall(0).thisValue, this.modal, 'the value of "this" is the modal');
|
|
|
|
assert.strictEqual(fillSpy.callCount, 1, 'the "modalfill" callback was called');
|
|
|
|
assert.strictEqual(fillSpy.getCall(0).thisValue, this.modal, 'the value of "this" is the modal');
|
|
|
|
});
|
|
|
|
|
2016-08-04 17:49:32 +02:00
|
|
|
QUnit.test('empty()', function(assert) {
|
|
|
|
const beforeEmptySpy = sinon.spy();
|
|
|
|
const emptySpy = sinon.spy();
|
2015-10-28 19:28:15 +02:00
|
|
|
|
2017-01-18 08:50:22 +02:00
|
|
|
this.modal.fillWith([Dom.createEl(), Dom.createEl()]);
|
|
|
|
this.modal.on('beforemodalempty', beforeEmptySpy);
|
|
|
|
this.modal.on('modalempty', emptySpy);
|
|
|
|
this.modal.empty();
|
2015-10-28 19:28:15 +02:00
|
|
|
|
|
|
|
assert.expect(5);
|
|
|
|
assert.strictEqual(this.modal.contentEl().children.length, 0, 'removed all `contentEl()` children');
|
|
|
|
assert.strictEqual(beforeEmptySpy.callCount, 1, 'the "beforemodalempty" callback was called');
|
|
|
|
assert.strictEqual(beforeEmptySpy.getCall(0).thisValue, this.modal, 'the value of "this" is the modal');
|
|
|
|
assert.strictEqual(emptySpy.callCount, 1, 'the "modalempty" callback was called');
|
|
|
|
assert.strictEqual(emptySpy.getCall(0).thisValue, this.modal, 'the value of "this" is the modal');
|
|
|
|
});
|
|
|
|
|
2016-08-04 17:49:32 +02:00
|
|
|
QUnit.test('closeable()', function(assert) {
|
|
|
|
const initialCloseButton = this.modal.getChild('closeButton');
|
2015-10-28 19:28:15 +02:00
|
|
|
|
|
|
|
assert.expect(8);
|
|
|
|
assert.strictEqual(this.modal.closeable(), true, 'the modal is closed');
|
|
|
|
|
2017-01-18 08:50:22 +02:00
|
|
|
this.modal.open();
|
|
|
|
this.modal.closeable(false);
|
2015-10-28 19:28:15 +02:00
|
|
|
assert.notOk(this.modal.getChild('closeButton'), 'the close button is no longer a child of the modal');
|
|
|
|
assert.notOk(initialCloseButton.el(), 'the initial close button was disposed');
|
|
|
|
|
2019-05-30 17:16:51 +02:00
|
|
|
this.modal.handleKeyDown(getMockEscapeEvent());
|
2015-10-28 19:28:15 +02:00
|
|
|
assert.ok(this.modal.opened(), 'the modal was not closed by the ESC key');
|
|
|
|
|
|
|
|
this.modal.close();
|
|
|
|
assert.notOk(this.modal.opened(), 'the modal was closed programmatically');
|
|
|
|
|
2017-01-18 08:50:22 +02:00
|
|
|
this.modal.open();
|
|
|
|
this.modal.closeable(true);
|
2015-10-28 19:28:15 +02:00
|
|
|
assert.ok(this.modal.getChild('closeButton'), 'a new close button was created');
|
|
|
|
|
|
|
|
this.modal.getChild('closeButton').trigger('click');
|
|
|
|
assert.notOk(this.modal.opened(), 'the modal was closed by the new close button');
|
|
|
|
|
2017-01-18 08:50:22 +02:00
|
|
|
this.modal.open();
|
2019-05-30 17:16:51 +02:00
|
|
|
this.modal.handleKeyDown(getMockEscapeEvent());
|
2015-10-28 19:28:15 +02:00
|
|
|
assert.notOk(this.modal.opened(), 'the modal was closed by the ESC key');
|
|
|
|
});
|
|
|
|
|
2016-08-04 17:49:32 +02:00
|
|
|
QUnit.test('"content" option (fills on first open() invocation)', function(assert) {
|
|
|
|
const modal = new ModalDialog(this.player, {
|
2015-10-28 19:28:15 +02:00
|
|
|
content: Dom.createEl(),
|
|
|
|
temporary: false
|
|
|
|
});
|
|
|
|
|
2016-08-04 17:49:32 +02:00
|
|
|
const spy = sinon.spy();
|
2015-10-28 19:28:15 +02:00
|
|
|
|
|
|
|
modal.on('modalfill', spy);
|
2017-01-18 08:50:22 +02:00
|
|
|
modal.open();
|
|
|
|
modal.close();
|
|
|
|
modal.open();
|
2015-10-28 19:28:15 +02:00
|
|
|
|
|
|
|
assert.expect(3);
|
|
|
|
assert.strictEqual(modal.content(), modal.options_.content, 'has the expected content');
|
|
|
|
assert.strictEqual(spy.callCount, 1, 'auto-fills only once');
|
|
|
|
assert.strictEqual(modal.contentEl().firstChild, modal.options_.content, 'has the expected content in the DOM');
|
2019-03-18 21:49:48 +02:00
|
|
|
modal.dispose();
|
2015-10-28 19:28:15 +02:00
|
|
|
});
|
|
|
|
|
2016-08-04 17:49:32 +02:00
|
|
|
QUnit.test('"temporary" option', function(assert) {
|
|
|
|
const temp = new ModalDialog(this.player, {temporary: true});
|
|
|
|
const tempSpy = sinon.spy();
|
|
|
|
const perm = new ModalDialog(this.player, {temporary: false});
|
|
|
|
const permSpy = sinon.spy();
|
2015-10-28 19:28:15 +02:00
|
|
|
|
|
|
|
temp.on('dispose', tempSpy);
|
|
|
|
perm.on('dispose', permSpy);
|
2017-01-18 08:50:22 +02:00
|
|
|
temp.open();
|
|
|
|
temp.close();
|
|
|
|
perm.open();
|
|
|
|
perm.close();
|
2015-10-28 19:28:15 +02:00
|
|
|
|
|
|
|
assert.expect(2);
|
|
|
|
assert.strictEqual(tempSpy.callCount, 1, 'temporary modals are disposed');
|
|
|
|
assert.strictEqual(permSpy.callCount, 0, 'permanent modals are not disposed');
|
2019-03-18 21:49:48 +02:00
|
|
|
|
|
|
|
temp.dispose();
|
|
|
|
perm.dispose();
|
2015-10-28 19:28:15 +02:00
|
|
|
});
|
|
|
|
|
2016-08-04 17:49:32 +02:00
|
|
|
QUnit.test('"fillAlways" option', function(assert) {
|
|
|
|
const modal = new ModalDialog(this.player, {
|
2015-10-28 19:28:15 +02:00
|
|
|
content: 'foo',
|
|
|
|
fillAlways: true,
|
|
|
|
temporary: false
|
|
|
|
});
|
|
|
|
|
2016-08-04 17:49:32 +02:00
|
|
|
const spy = sinon.spy();
|
2015-10-28 19:28:15 +02:00
|
|
|
|
|
|
|
modal.on('modalfill', spy);
|
2017-01-18 08:50:22 +02:00
|
|
|
modal.open();
|
|
|
|
modal.close();
|
|
|
|
modal.open();
|
2015-10-28 19:28:15 +02:00
|
|
|
|
|
|
|
assert.expect(1);
|
|
|
|
assert.strictEqual(spy.callCount, 2, 'the modal was filled on each open call');
|
2019-03-18 21:49:48 +02:00
|
|
|
modal.dispose();
|
2015-10-28 19:28:15 +02:00
|
|
|
});
|
|
|
|
|
2016-08-04 17:49:32 +02:00
|
|
|
QUnit.test('"label" option', function(assert) {
|
|
|
|
const label = 'foo';
|
|
|
|
const modal = new ModalDialog(this.player, {label});
|
2015-10-28 19:28:15 +02:00
|
|
|
|
|
|
|
assert.expect(1);
|
|
|
|
assert.strictEqual(modal.el().getAttribute('aria-label'), label, 'uses the label as the aria-label');
|
2019-03-18 21:49:48 +02:00
|
|
|
modal.dispose();
|
2015-10-28 19:28:15 +02:00
|
|
|
});
|
|
|
|
|
2016-08-04 17:49:32 +02:00
|
|
|
QUnit.test('"uncloseable" option', function(assert) {
|
|
|
|
const modal = new ModalDialog(this.player, {
|
2015-10-28 19:28:15 +02:00
|
|
|
temporary: false,
|
|
|
|
uncloseable: true
|
|
|
|
});
|
|
|
|
|
2016-08-04 17:49:32 +02:00
|
|
|
const spy = sinon.spy();
|
2015-10-28 19:28:15 +02:00
|
|
|
|
|
|
|
modal.on('modalclose', spy);
|
|
|
|
|
|
|
|
assert.expect(3);
|
|
|
|
assert.strictEqual(modal.closeable(), false, 'the modal is uncloseable');
|
|
|
|
assert.notOk(modal.getChild('closeButton'), 'the close button is not present');
|
|
|
|
|
2017-01-18 08:50:22 +02:00
|
|
|
modal.open();
|
2019-05-30 17:16:51 +02:00
|
|
|
modal.handleKeyDown(getMockEscapeEvent());
|
2015-10-28 19:28:15 +02:00
|
|
|
assert.strictEqual(spy.callCount, 0, 'ESC did not close the modal');
|
2019-03-18 21:49:48 +02:00
|
|
|
modal.dispose();
|
2015-10-28 19:28:15 +02:00
|
|
|
});
|
2017-02-09 00:29:05 +02:00
|
|
|
|
|
|
|
QUnit.test('handleKeyDown traps tab focus', function(assert) {
|
|
|
|
const tabTester = tabTestHelper(assert, this.player);
|
|
|
|
|
|
|
|
// tabbing forward from first element to last and cycling back to first
|
|
|
|
tabTester(0, 1, false);
|
|
|
|
tabTester(1, 2, false);
|
|
|
|
tabTester(2, 3, false);
|
|
|
|
tabTester(3, 0, false);
|
|
|
|
|
|
|
|
// tabbing backwards from last element to first and cycling back to last
|
|
|
|
tabTester(3, 2, true);
|
|
|
|
tabTester(2, 1, true);
|
|
|
|
tabTester(1, 0, true);
|
|
|
|
tabTester(0, 3, true);
|
|
|
|
});
|