mirror of
https://github.com/videojs/video.js.git
synced 2025-04-17 12:06:22 +02:00
@pagarwal123 updated some test code to pass linter
This commit is contained in:
parent
272d5eed83
commit
945711855a
@ -1,27 +1,27 @@
|
|||||||
|
/* eslint-env qunit */
|
||||||
import Button from '../../src/js/button.js';
|
import Button from '../../src/js/button.js';
|
||||||
import TestHelpers from './test-helpers.js';
|
import TestHelpers from './test-helpers.js';
|
||||||
|
|
||||||
q.module('Button');
|
QUnit.module('Button');
|
||||||
|
|
||||||
test('should localize its text', function(){
|
QUnit.test('should localize its text', function() {
|
||||||
expect(3);
|
QUnit.expect(3);
|
||||||
|
|
||||||
var player, testButton, el;
|
const player = TestHelpers.makePlayer({
|
||||||
|
language: 'es',
|
||||||
player = TestHelpers.makePlayer({
|
languages: {
|
||||||
'language': 'es',
|
es: {
|
||||||
'languages': {
|
Play: 'Juego'
|
||||||
'es': {
|
|
||||||
'Play': 'Juego'
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
testButton = new Button(player);
|
const testButton = new Button(player);
|
||||||
testButton.controlText_ = 'Play';
|
|
||||||
el = testButton.createEl();
|
|
||||||
|
|
||||||
ok(el.nodeName.toLowerCase().match('button'));
|
testButton.controlText_ = 'Play';
|
||||||
ok(el.innerHTML.match(/vjs-control-text"?>Juego/));
|
const el = testButton.createEl();
|
||||||
equal(el.getAttribute('title'), 'Juego');
|
|
||||||
|
QUnit.ok(el.nodeName.toLowerCase().match('button'));
|
||||||
|
QUnit.ok(el.innerHTML.match(/vjs-control-text"?>Juego/));
|
||||||
|
QUnit.equal(el.getAttribute('title'), 'Juego');
|
||||||
});
|
});
|
||||||
|
@ -1,39 +1,40 @@
|
|||||||
|
/* eslint-env qunit */
|
||||||
import ClickableComponent from '../../src/js/clickable-component.js';
|
import ClickableComponent from '../../src/js/clickable-component.js';
|
||||||
import TestHelpers from './test-helpers.js';
|
import TestHelpers from './test-helpers.js';
|
||||||
|
|
||||||
q.module('ClickableComponent');
|
QUnit.module('ClickableComponent');
|
||||||
|
|
||||||
q.test('should create a div with role="button"', function(){
|
QUnit.test('should create a div with role="button"', function() {
|
||||||
expect(2);
|
QUnit.expect(2);
|
||||||
|
|
||||||
let player = TestHelpers.makePlayer({});
|
const player = TestHelpers.makePlayer({});
|
||||||
|
|
||||||
let testClickableComponent = new ClickableComponent(player);
|
const testClickableComponent = new ClickableComponent(player);
|
||||||
let el = testClickableComponent.createEl();
|
const el = testClickableComponent.createEl();
|
||||||
|
|
||||||
equal(el.nodeName.toLowerCase(), 'div', 'the name of the element is "div"');
|
QUnit.equal(el.nodeName.toLowerCase(), 'div', 'the name of the element is "div"');
|
||||||
equal(el.getAttribute('role').toLowerCase(), 'button', 'the role of the element is "button"');
|
QUnit.equal(el.getAttribute('role').toLowerCase(), 'button', 'the role of the element is "button"');
|
||||||
|
|
||||||
testClickableComponent.dispose();
|
testClickableComponent.dispose();
|
||||||
player.dispose();
|
player.dispose();
|
||||||
});
|
});
|
||||||
|
|
||||||
q.test('should be enabled/disabled', function(){
|
QUnit.test('should be enabled/disabled', function() {
|
||||||
expect(3);
|
QUnit.expect(3);
|
||||||
|
|
||||||
let player = TestHelpers.makePlayer({});
|
const player = TestHelpers.makePlayer({});
|
||||||
|
|
||||||
let testClickableComponent = new ClickableComponent(player);
|
const testClickableComponent = new ClickableComponent(player);
|
||||||
|
|
||||||
equal(testClickableComponent.hasClass('vjs-disabled'), false, 'ClickableComponent defaults to enabled');
|
QUnit.equal(testClickableComponent.hasClass('vjs-disabled'), false, 'ClickableComponent defaults to enabled');
|
||||||
|
|
||||||
testClickableComponent.disable();
|
testClickableComponent.disable();
|
||||||
|
|
||||||
equal(testClickableComponent.hasClass('vjs-disabled'), true, 'ClickableComponent is disabled');
|
QUnit.equal(testClickableComponent.hasClass('vjs-disabled'), true, 'ClickableComponent is disabled');
|
||||||
|
|
||||||
testClickableComponent.enable();
|
testClickableComponent.enable();
|
||||||
|
|
||||||
equal(testClickableComponent.hasClass('vjs-disabled'), false, 'ClickableComponent is enabled');
|
QUnit.equal(testClickableComponent.hasClass('vjs-disabled'), false, 'ClickableComponent is enabled');
|
||||||
|
|
||||||
testClickableComponent.dispose();
|
testClickableComponent.dispose();
|
||||||
player.dispose();
|
player.dispose();
|
||||||
|
@ -1,21 +1,23 @@
|
|||||||
|
/* eslint-env qunit */
|
||||||
import CloseButton from '../../src/js/close-button';
|
import CloseButton from '../../src/js/close-button';
|
||||||
|
import sinon from 'sinon';
|
||||||
import TestHelpers from './test-helpers';
|
import TestHelpers from './test-helpers';
|
||||||
|
|
||||||
q.module('CloseButton', {
|
QUnit.module('CloseButton', {
|
||||||
|
|
||||||
beforeEach: function() {
|
beforeEach() {
|
||||||
this.player = TestHelpers.makePlayer();
|
this.player = TestHelpers.makePlayer();
|
||||||
this.btn = new CloseButton(this.player);
|
this.btn = new CloseButton(this.player);
|
||||||
},
|
},
|
||||||
|
|
||||||
afterEach: function() {
|
afterEach() {
|
||||||
this.player.dispose();
|
this.player.dispose();
|
||||||
this.btn.dispose();
|
this.btn.dispose();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
q.test('should create the expected element', function(assert) {
|
QUnit.test('should create the expected element', function(assert) {
|
||||||
let elAssertions = TestHelpers.assertEl(assert, this.btn.el(), {
|
const elAssertions = TestHelpers.assertEl(assert, this.btn.el(), {
|
||||||
tagName: 'button',
|
tagName: 'button',
|
||||||
classes: [
|
classes: [
|
||||||
'vjs-button',
|
'vjs-button',
|
||||||
@ -29,16 +31,16 @@ q.test('should create the expected element', function(assert) {
|
|||||||
assert.strictEqual(this.btn.el().querySelector('.vjs-control-text').innerHTML, 'Close');
|
assert.strictEqual(this.btn.el().querySelector('.vjs-control-text').innerHTML, 'Close');
|
||||||
});
|
});
|
||||||
|
|
||||||
q.test('should allow setting the controlText_ property as an option', function(assert) {
|
QUnit.test('should allow setting the controlText_ property as an option', function(assert) {
|
||||||
var text = 'OK!';
|
const text = 'OK!';
|
||||||
var btn = new CloseButton(this.player, {controlText: text});
|
const btn = new CloseButton(this.player, {controlText: text});
|
||||||
|
|
||||||
assert.expect(1);
|
assert.expect(1);
|
||||||
assert.strictEqual(btn.controlText_, text, 'set the controlText_ property');
|
assert.strictEqual(btn.controlText_, text, 'set the controlText_ property');
|
||||||
});
|
});
|
||||||
|
|
||||||
q.test('should trigger an event on activation', function(assert) {
|
QUnit.test('should trigger an event on activation', function(assert) {
|
||||||
var spy = sinon.spy();
|
const spy = sinon.spy();
|
||||||
|
|
||||||
this.btn.on('close', spy);
|
this.btn.on('close', spy);
|
||||||
this.btn.trigger('click');
|
this.btn.trigger('click');
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -1,3 +1,4 @@
|
|||||||
|
/* eslint-env qunit */
|
||||||
import VolumeControl from '../../src/js/control-bar/volume-control/volume-control.js';
|
import VolumeControl from '../../src/js/control-bar/volume-control/volume-control.js';
|
||||||
import MuteToggle from '../../src/js/control-bar/mute-toggle.js';
|
import MuteToggle from '../../src/js/control-bar/mute-toggle.js';
|
||||||
import PlaybackRateMenuButton from '../../src/js/control-bar/playback-rate-menu/playback-rate-menu-button.js';
|
import PlaybackRateMenuButton from '../../src/js/control-bar/playback-rate-menu/playback-rate-menu-button.js';
|
||||||
@ -5,110 +6,107 @@ import Slider from '../../src/js/slider/slider.js';
|
|||||||
import TestHelpers from './test-helpers.js';
|
import TestHelpers from './test-helpers.js';
|
||||||
import document from 'global/document';
|
import document from 'global/document';
|
||||||
|
|
||||||
q.module('Controls');
|
QUnit.module('Controls');
|
||||||
|
|
||||||
test('should hide volume control if it\'s not supported', function(){
|
QUnit.test('should hide volume control if it\'s not supported', function() {
|
||||||
expect(2);
|
QUnit.expect(2);
|
||||||
|
const noop = function() {};
|
||||||
var noop, player, volumeControl, muteToggle;
|
const player = {
|
||||||
noop = function(){};
|
|
||||||
player = {
|
|
||||||
id: noop,
|
id: noop,
|
||||||
on: noop,
|
on: noop,
|
||||||
ready: noop,
|
ready: noop,
|
||||||
tech_: {
|
tech_: {
|
||||||
'featuresVolumeControl': false
|
featuresVolumeControl: false
|
||||||
},
|
},
|
||||||
volume: function(){},
|
volume() {},
|
||||||
muted: function(){},
|
muted() {},
|
||||||
reportUserActivity: function(){}
|
reportUserActivity() {}
|
||||||
};
|
};
|
||||||
|
|
||||||
volumeControl = new VolumeControl(player);
|
const volumeControl = new VolumeControl(player);
|
||||||
muteToggle = new MuteToggle(player);
|
const muteToggle = new MuteToggle(player);
|
||||||
|
|
||||||
ok(volumeControl.el().className.indexOf('vjs-hidden') >= 0, 'volumeControl is not hidden');
|
QUnit.ok(volumeControl.el().className.indexOf('vjs-hidden') >= 0, 'volumeControl is not hidden');
|
||||||
ok(muteToggle.el().className.indexOf('vjs-hidden') >= 0, 'muteToggle is not hidden');
|
QUnit.ok(muteToggle.el().className.indexOf('vjs-hidden') >= 0, 'muteToggle is not hidden');
|
||||||
});
|
});
|
||||||
|
|
||||||
test('should test and toggle volume control on `loadstart`', function(){
|
QUnit.test('should test and toggle volume control on `loadstart`', function() {
|
||||||
var noop, listeners, player, volumeControl, muteToggle, i;
|
const noop = function() {};
|
||||||
noop = function(){};
|
const listeners = [];
|
||||||
listeners = [];
|
const player = {
|
||||||
player = {
|
|
||||||
id: noop,
|
id: noop,
|
||||||
on: function(event, callback){
|
on(event, callback) {
|
||||||
// don't fire dispose listeners
|
// don't fire dispose listeners
|
||||||
if (event !== 'dispose') {
|
if (event !== 'dispose') {
|
||||||
listeners.push(callback);
|
listeners.push(callback);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
ready: noop,
|
ready: noop,
|
||||||
volume: function(){
|
volume() {
|
||||||
return 1;
|
return 1;
|
||||||
},
|
},
|
||||||
muted: function(){
|
muted() {
|
||||||
return false;
|
return false;
|
||||||
},
|
},
|
||||||
tech_: {
|
tech_: {
|
||||||
'featuresVolumeControl': true
|
featuresVolumeControl: true
|
||||||
},
|
},
|
||||||
reportUserActivity: function(){}
|
reportUserActivity() {}
|
||||||
};
|
};
|
||||||
|
|
||||||
volumeControl = new VolumeControl(player);
|
const volumeControl = new VolumeControl(player);
|
||||||
muteToggle = new MuteToggle(player);
|
const muteToggle = new MuteToggle(player);
|
||||||
|
|
||||||
equal(volumeControl.hasClass('vjs-hidden'), false, 'volumeControl is hidden initially');
|
QUnit.equal(volumeControl.hasClass('vjs-hidden'), false, 'volumeControl is hidden initially');
|
||||||
equal(muteToggle.hasClass('vjs-hidden'), false, 'muteToggle is hidden initially');
|
QUnit.equal(muteToggle.hasClass('vjs-hidden'), false, 'muteToggle is hidden initially');
|
||||||
|
|
||||||
player.tech_['featuresVolumeControl'] = false;
|
player.tech_.featuresVolumeControl = false;
|
||||||
for (i = 0; i < listeners.length; i++) {
|
for (let i = 0; i < listeners.length; i++) {
|
||||||
listeners[i]();
|
listeners[i]();
|
||||||
}
|
}
|
||||||
|
|
||||||
equal(volumeControl.hasClass('vjs-hidden'), true, 'volumeControl does not hide itself');
|
QUnit.equal(volumeControl.hasClass('vjs-hidden'), true, 'volumeControl does not hide itself');
|
||||||
equal(muteToggle.hasClass('vjs-hidden'), true, 'muteToggle does not hide itself');
|
QUnit.equal(muteToggle.hasClass('vjs-hidden'), true, 'muteToggle does not hide itself');
|
||||||
|
|
||||||
player.tech_['featuresVolumeControl'] = true;
|
player.tech_.featuresVolumeControl = true;
|
||||||
for (i = 0; i < listeners.length; i++) {
|
for (let i = 0; i < listeners.length; i++) {
|
||||||
listeners[i]();
|
listeners[i]();
|
||||||
}
|
}
|
||||||
|
|
||||||
equal(volumeControl.hasClass('vjs-hidden'), false, 'volumeControl does not show itself');
|
QUnit.equal(volumeControl.hasClass('vjs-hidden'), false, 'volumeControl does not show itself');
|
||||||
equal(muteToggle.hasClass('vjs-hidden'), false, 'muteToggle does not show itself');
|
QUnit.equal(muteToggle.hasClass('vjs-hidden'), false, 'muteToggle does not show itself');
|
||||||
});
|
});
|
||||||
|
|
||||||
test('calculateDistance should use changedTouches, if available', function() {
|
QUnit.test('calculateDistance should use changedTouches, if available', function() {
|
||||||
var noop, player, slider, event;
|
const noop = function() {};
|
||||||
noop = function(){};
|
const player = {
|
||||||
player = {
|
|
||||||
id: noop,
|
id: noop,
|
||||||
on: noop,
|
on: noop,
|
||||||
ready: noop,
|
ready: noop,
|
||||||
reportUserActivity: noop
|
reportUserActivity: noop
|
||||||
};
|
};
|
||||||
slider = new Slider(player);
|
const slider = new Slider(player);
|
||||||
|
|
||||||
document.body.appendChild(slider.el_);
|
document.body.appendChild(slider.el_);
|
||||||
slider.el_.style.position = 'absolute';
|
slider.el_.style.position = 'absolute';
|
||||||
slider.el_.style.width = '200px';
|
slider.el_.style.width = '200px';
|
||||||
slider.el_.style.left = '0px';
|
slider.el_.style.left = '0px';
|
||||||
|
|
||||||
event = {
|
const event = {
|
||||||
pageX: 10,
|
pageX: 10,
|
||||||
changedTouches: [{
|
changedTouches: [{
|
||||||
pageX: 100
|
pageX: 100
|
||||||
}]
|
}]
|
||||||
};
|
};
|
||||||
|
|
||||||
equal(slider.calculateDistance(event), 0.5, 'we should have touched exactly in the center, so, the ratio should be half');
|
QUnit.equal(slider.calculateDistance(event), 0.5, 'we should have touched exactly in the center, so, the ratio should be half');
|
||||||
});
|
});
|
||||||
|
|
||||||
test('should hide playback rate control if it\'s not supported', function(){
|
QUnit.test('should hide playback rate control if it\'s not supported', function() {
|
||||||
expect(1);
|
QUnit.expect(1);
|
||||||
|
|
||||||
var player = TestHelpers.makePlayer();
|
const player = TestHelpers.makePlayer();
|
||||||
var playbackRate = new PlaybackRateMenuButton(player);
|
const playbackRate = new PlaybackRateMenuButton(player);
|
||||||
|
|
||||||
ok(playbackRate.el().className.indexOf('vjs-hidden') >= 0, 'playbackRate is not hidden');
|
QUnit.ok(playbackRate.el().className.indexOf('vjs-hidden') >= 0, 'playbackRate is not hidden');
|
||||||
});
|
});
|
||||||
|
@ -1,28 +1,31 @@
|
|||||||
|
/* eslint-env qunit */
|
||||||
import * as Events from '../../src/js/utils/events.js';
|
import * as Events from '../../src/js/utils/events.js';
|
||||||
import document from 'global/document';
|
import document from 'global/document';
|
||||||
|
|
||||||
q.module('Events');
|
QUnit.module('Events');
|
||||||
|
|
||||||
test('should add and remove an event listener to an element', function(){
|
QUnit.test('should add and remove an event listener to an element', function() {
|
||||||
expect(1);
|
QUnit.expect(1);
|
||||||
|
|
||||||
var el = document.createElement('div');
|
const el = document.createElement('div');
|
||||||
var listener = function(){
|
const listener = function() {
|
||||||
ok(true, 'Click Triggered');
|
QUnit.ok(true, 'Click Triggered');
|
||||||
};
|
};
|
||||||
|
|
||||||
Events.on(el, 'click', listener);
|
Events.on(el, 'click', listener);
|
||||||
Events.trigger(el, 'click'); // 1 click
|
// 1 click
|
||||||
|
Events.trigger(el, 'click');
|
||||||
Events.off(el, 'click', listener);
|
Events.off(el, 'click', listener);
|
||||||
Events.trigger(el, 'click'); // No click should happen.
|
// No click should happen.
|
||||||
|
Events.trigger(el, 'click');
|
||||||
});
|
});
|
||||||
|
|
||||||
test('should add and remove multiple event listeners to an element with a single call', function(){
|
QUnit.test('should add and remove multiple event listeners to an element with a single call', function() {
|
||||||
expect(6);
|
QUnit.expect(6);
|
||||||
|
|
||||||
var el = document.createElement('div');
|
const el = document.createElement('div');
|
||||||
var listener = function(){
|
const listener = function() {
|
||||||
ok(true, 'Callback triggered');
|
QUnit.ok(true, 'Callback triggered');
|
||||||
};
|
};
|
||||||
|
|
||||||
Events.on(el, ['click', 'event1', 'event2'], listener);
|
Events.on(el, ['click', 'event1', 'event2'], listener);
|
||||||
@ -30,92 +33,101 @@ test('should add and remove multiple event listeners to an element with a single
|
|||||||
Events.trigger(el, 'click');
|
Events.trigger(el, 'click');
|
||||||
Events.trigger(el, 'click');
|
Events.trigger(el, 'click');
|
||||||
Events.off(el, 'click', listener);
|
Events.off(el, 'click', listener);
|
||||||
Events.trigger(el, 'click'); // No click should happen.
|
// No click should happen.
|
||||||
|
Events.trigger(el, 'click');
|
||||||
|
|
||||||
Events.trigger(el, 'event1');
|
Events.trigger(el, 'event1');
|
||||||
Events.trigger(el, 'event1');
|
Events.trigger(el, 'event1');
|
||||||
Events.off(el, 'event1', listener);
|
Events.off(el, 'event1', listener);
|
||||||
Events.trigger(el, 'event1'); // No event1 should happen.
|
// No event1 should happen.
|
||||||
|
Events.trigger(el, 'event1');
|
||||||
|
|
||||||
Events.trigger(el, 'event2');
|
Events.trigger(el, 'event2');
|
||||||
Events.trigger(el, 'event2');
|
Events.trigger(el, 'event2');
|
||||||
Events.off(el, 'event2', listener);
|
Events.off(el, 'event2', listener);
|
||||||
Events.trigger(el, 'event2'); // No event2 should happen.
|
// No event2 should happen.
|
||||||
|
Events.trigger(el, 'event2');
|
||||||
});
|
});
|
||||||
|
|
||||||
test('should be possible to pass data when you trigger an event', function () {
|
QUnit.test('should be possible to pass data when you trigger an event', function() {
|
||||||
expect(6);
|
QUnit.expect(6);
|
||||||
var el = document.createElement('div');
|
const el = document.createElement('div');
|
||||||
var fakeData1 = 'Fake Data 1';
|
const fakeData1 = 'Fake Data 1';
|
||||||
var fakeData2 = {txt: 'Fake Data 2'};
|
const fakeData2 = {txt: 'Fake Data 2'};
|
||||||
|
|
||||||
var listener = function(evt, hash){
|
const listener = function(evt, hash) {
|
||||||
ok(true, 'Callback triggered');
|
QUnit.ok(true, 'Callback triggered');
|
||||||
deepEqual(fakeData1, hash.d1, 'Shoulbe be passed to the handler');
|
deepEqual(fakeData1, hash.d1, 'Shoulbe be passed to the handler');
|
||||||
deepEqual(fakeData2, hash.d2, 'Shoulbe be passed to the handler');
|
deepEqual(fakeData2, hash.d2, 'Shoulbe be passed to the handler');
|
||||||
};
|
};
|
||||||
|
|
||||||
Events.on(el, ['event1', 'event2'], listener);
|
Events.on(el, ['event1', 'event2'], listener);
|
||||||
Events.trigger(el, 'event1', { d1: fakeData1, d2:fakeData2});
|
Events.trigger(el, 'event1', { d1: fakeData1, d2: fakeData2});
|
||||||
Events.trigger(el, 'event2', { d1: fakeData1, d2:fakeData2});
|
Events.trigger(el, 'event2', { d1: fakeData1, d2: fakeData2});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
test('should remove all listeners of a type', function(){
|
QUnit.test('should remove all listeners of a type', function() {
|
||||||
var el = document.createElement('div');
|
const el = document.createElement('div');
|
||||||
var clicks = 0;
|
let clicks = 0;
|
||||||
var listener = function(){
|
const listener = function() {
|
||||||
clicks++;
|
clicks++;
|
||||||
};
|
};
|
||||||
var listener2 = function(){
|
const listener2 = function() {
|
||||||
clicks++;
|
clicks++;
|
||||||
};
|
};
|
||||||
|
|
||||||
Events.on(el, 'click', listener);
|
Events.on(el, 'click', listener);
|
||||||
Events.on(el, 'click', listener2);
|
Events.on(el, 'click', listener2);
|
||||||
Events.trigger(el, 'click'); // 2 clicks
|
// 2 clicks
|
||||||
|
Events.trigger(el, 'click');
|
||||||
|
|
||||||
ok(clicks === 2, 'both click listeners fired');
|
QUnit.ok(clicks === 2, 'both click listeners fired');
|
||||||
|
|
||||||
Events.off(el, 'click');
|
Events.off(el, 'click');
|
||||||
Events.trigger(el, 'click'); // No click should happen.
|
// No click should happen.
|
||||||
|
Events.trigger(el, 'click');
|
||||||
|
|
||||||
ok(clicks === 2, 'no click listeners fired');
|
QUnit.ok(clicks === 2, 'no click listeners fired');
|
||||||
});
|
});
|
||||||
|
|
||||||
test('should remove all listeners of an array of types', function(){
|
QUnit.test('should remove all listeners of an array of types', function() {
|
||||||
var el = document.createElement('div');
|
const el = document.createElement('div');
|
||||||
var calls = 0;
|
let calls = 0;
|
||||||
var listener = function(){
|
const listener = function() {
|
||||||
calls++;
|
calls++;
|
||||||
};
|
};
|
||||||
var listener2 = function(){
|
const listener2 = function() {
|
||||||
calls++;
|
calls++;
|
||||||
};
|
};
|
||||||
|
|
||||||
Events.on(el, ['click', 'event1'], listener);
|
Events.on(el, ['click', 'event1'], listener);
|
||||||
Events.on(el, ['click', 'event1'], listener2);
|
Events.on(el, ['click', 'event1'], listener2);
|
||||||
Events.trigger(el, 'click'); // 2 calls
|
// 2 calls
|
||||||
Events.trigger(el, 'event1'); // 2 calls
|
Events.trigger(el, 'click');
|
||||||
|
// 2 calls
|
||||||
|
Events.trigger(el, 'event1');
|
||||||
|
|
||||||
ok(calls === 4, 'both click listeners fired');
|
QUnit.ok(calls === 4, 'both click listeners fired');
|
||||||
|
|
||||||
Events.off(el, ['click', 'event1']);
|
Events.off(el, ['click', 'event1']);
|
||||||
Events.trigger(el, 'click'); // No click should happen.
|
// No click should happen.
|
||||||
Events.trigger(el, 'event1'); // No event1 should happen.
|
Events.trigger(el, 'click');
|
||||||
|
// No event1 should happen.
|
||||||
|
Events.trigger(el, 'event1');
|
||||||
|
|
||||||
ok(calls === 4, 'no event listeners fired');
|
QUnit.ok(calls === 4, 'no event listeners fired');
|
||||||
});
|
});
|
||||||
|
|
||||||
test('should remove all listeners from an element', function(){
|
QUnit.test('should remove all listeners from an element', function() {
|
||||||
expect(2);
|
QUnit.expect(2);
|
||||||
|
|
||||||
var el = document.createElement('div');
|
const el = document.createElement('div');
|
||||||
var listener = function(){
|
const listener = function() {
|
||||||
ok(true, 'Fake1 Triggered');
|
QUnit.ok(true, 'Fake1 Triggered');
|
||||||
};
|
};
|
||||||
var listener2 = function(){
|
const listener2 = function() {
|
||||||
ok(true, 'Fake2 Triggered');
|
QUnit.ok(true, 'Fake2 Triggered');
|
||||||
};
|
};
|
||||||
|
|
||||||
Events.on(el, 'fake1', listener);
|
Events.on(el, 'fake1', listener);
|
||||||
@ -131,111 +143,119 @@ test('should remove all listeners from an element', function(){
|
|||||||
Events.trigger(el, 'fake2');
|
Events.trigger(el, 'fake2');
|
||||||
});
|
});
|
||||||
|
|
||||||
test('should listen only once', function(){
|
QUnit.test('should listen only once', function() {
|
||||||
expect(1);
|
QUnit.expect(1);
|
||||||
|
|
||||||
var el = document.createElement('div');
|
const el = document.createElement('div');
|
||||||
var listener = function(){
|
const listener = function() {
|
||||||
ok(true, 'Click Triggered');
|
QUnit.ok(true, 'Click Triggered');
|
||||||
};
|
};
|
||||||
|
|
||||||
Events.one(el, 'click', listener);
|
Events.one(el, 'click', listener);
|
||||||
Events.trigger(el, 'click'); // 1 click
|
// 1 click
|
||||||
Events.trigger(el, 'click'); // No click should happen.
|
Events.trigger(el, 'click');
|
||||||
|
// No click should happen.
|
||||||
|
Events.trigger(el, 'click');
|
||||||
});
|
});
|
||||||
|
|
||||||
test( 'should listen only once in multiple events from a single call', function(){
|
QUnit.test('should listen only once in multiple events from a single call', function() {
|
||||||
expect(3);
|
QUnit.expect(3);
|
||||||
|
|
||||||
var el = document.createElement('div');
|
const el = document.createElement('div');
|
||||||
var listener = function(){
|
const listener = function() {
|
||||||
ok(true, 'Callback Triggered');
|
QUnit.ok(true, 'Callback Triggered');
|
||||||
};
|
};
|
||||||
|
|
||||||
Events.one(el, ['click', 'event1', 'event2'], listener);
|
Events.one(el, ['click', 'event1', 'event2'], listener);
|
||||||
Events.trigger(el, 'click'); // 1 click
|
// 1 click
|
||||||
Events.trigger(el, 'click'); // No click should happen.
|
Events.trigger(el, 'click');
|
||||||
Events.trigger(el, 'event1'); // event1 must be handled.
|
// No click should happen.
|
||||||
Events.trigger(el, 'event1'); // No event1 should be handled.
|
Events.trigger(el, 'click');
|
||||||
Events.trigger(el, 'event2'); // event2 must be handled.
|
// event1 must be handled.
|
||||||
Events.trigger(el, 'event2'); // No event2 should be handled.
|
Events.trigger(el, 'event1');
|
||||||
|
// No event1 should be handled.
|
||||||
|
Events.trigger(el, 'event1');
|
||||||
|
// event2 must be handled.
|
||||||
|
Events.trigger(el, 'event2');
|
||||||
|
// No event2 should be handled.
|
||||||
|
Events.trigger(el, 'event2');
|
||||||
});
|
});
|
||||||
|
|
||||||
test('should stop immediate propagtion', function(){
|
QUnit.test('should stop immediate propagtion', function() {
|
||||||
expect(1);
|
QUnit.expect(1);
|
||||||
|
|
||||||
var el = document.createElement('div');
|
const el = document.createElement('div');
|
||||||
|
|
||||||
Events.on(el, 'test', function(e){
|
Events.on(el, 'test', function(e) {
|
||||||
ok(true, 'First listener fired');
|
QUnit.ok(true, 'First listener fired');
|
||||||
e.stopImmediatePropagation();
|
e.stopImmediatePropagation();
|
||||||
});
|
});
|
||||||
|
|
||||||
Events.on(el, 'test', function(e){
|
Events.on(el, 'test', function(e) {
|
||||||
ok(false, 'Second listener fired');
|
QUnit.ok(false, 'Second listener fired');
|
||||||
});
|
});
|
||||||
|
|
||||||
Events.trigger(el, 'test');
|
Events.trigger(el, 'test');
|
||||||
});
|
});
|
||||||
|
|
||||||
test('should bubble up DOM unless bubbles == false', function(){
|
QUnit.test('should bubble up DOM unless bubbles == false', function() {
|
||||||
expect(3);
|
QUnit.expect(3);
|
||||||
|
|
||||||
var outer = document.createElement('div');
|
const outer = document.createElement('div');
|
||||||
var inner = outer.appendChild(document.createElement('div'));
|
const inner = outer.appendChild(document.createElement('div'));
|
||||||
|
|
||||||
// Verify that if bubbles === true, event bubbles up dom.
|
// Verify that if bubbles === true, event bubbles up dom.
|
||||||
Events.on(inner, 'bubbles', function(e){
|
Events.on(inner, 'bubbles', function(e) {
|
||||||
ok(true, 'Inner listener fired');
|
QUnit.ok(true, 'Inner listener fired');
|
||||||
});
|
});
|
||||||
Events.on(outer, 'bubbles', function(e){
|
Events.on(outer, 'bubbles', function(e) {
|
||||||
ok(true, 'Outer listener fired');
|
QUnit.ok(true, 'Outer listener fired');
|
||||||
});
|
});
|
||||||
Events.trigger(inner, { type:'bubbles', target:inner, bubbles:true });
|
Events.trigger(inner, { type: 'bubbles', target: inner, bubbles: true });
|
||||||
|
|
||||||
// Only change 'bubbles' to false, and verify only inner handler is called.
|
// Only change 'bubbles' to false, and verify only inner handler is called.
|
||||||
Events.on(inner, 'nobub', function(e){
|
Events.on(inner, 'nobub', function(e) {
|
||||||
ok(true, 'Inner listener fired');
|
QUnit.ok(true, 'Inner listener fired');
|
||||||
});
|
});
|
||||||
Events.on(outer, 'nobub', function(e){
|
Events.on(outer, 'nobub', function(e) {
|
||||||
ok(false, 'Outer listener fired');
|
QUnit.ok(false, 'Outer listener fired');
|
||||||
});
|
});
|
||||||
Events.trigger(inner, { type:'nobub', target:inner, bubbles:false });
|
Events.trigger(inner, { type: 'nobub', target: inner, bubbles: false });
|
||||||
});
|
});
|
||||||
|
|
||||||
test('should have a defaultPrevented property on an event that was prevent from doing default action', function() {
|
QUnit.test('should have a defaultPrevented property on an event that was prevent from doing default action', function() {
|
||||||
expect(2);
|
QUnit.expect(2);
|
||||||
|
|
||||||
var el = document.createElement('div');
|
const el = document.createElement('div');
|
||||||
|
|
||||||
Events.on(el, 'test', function(e){
|
Events.on(el, 'test', function(e) {
|
||||||
ok(true, 'First listener fired');
|
QUnit.ok(true, 'First listener fired');
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
});
|
});
|
||||||
|
|
||||||
Events.on(el, 'test', function(e){
|
Events.on(el, 'test', function(e) {
|
||||||
ok(e.defaultPrevented, 'Should have `defaultPrevented` to signify preventDefault being called');
|
QUnit.ok(e.defaultPrevented, 'Should have `defaultPrevented` to signify preventDefault being called');
|
||||||
});
|
});
|
||||||
|
|
||||||
Events.trigger(el, 'test');
|
Events.trigger(el, 'test');
|
||||||
});
|
});
|
||||||
|
|
||||||
test('should have relatedTarget correctly set on the event', function() {
|
QUnit.test('should have relatedTarget correctly set on the event', function() {
|
||||||
expect(2);
|
QUnit.expect(2);
|
||||||
|
|
||||||
var el1 = document.createElement('div'),
|
const el1 = document.createElement('div');
|
||||||
el2 = document.createElement('div'),
|
const el2 = document.createElement('div');
|
||||||
relatedEl = document.createElement('div');
|
const relatedEl = document.createElement('div');
|
||||||
|
|
||||||
Events.on(el1, 'click', function(e){
|
Events.on(el1, 'click', function(e) {
|
||||||
equal(e.relatedTarget, relatedEl, 'relatedTarget is set for all browsers when related element is set on the event');
|
QUnit.equal(e.relatedTarget, relatedEl, 'relatedTarget is set for all browsers when related element is set on the event');
|
||||||
});
|
});
|
||||||
|
|
||||||
Events.trigger(el1, { type:'click', relatedTarget:relatedEl });
|
Events.trigger(el1, { type: 'click', relatedTarget: relatedEl });
|
||||||
|
|
||||||
Events.on(el2, 'click', function(e) {
|
Events.on(el2, 'click', function(e) {
|
||||||
equal(e.relatedTarget, null, 'relatedTarget is null when none is provided');
|
QUnit.equal(e.relatedTarget, null, 'relatedTarget is null when none is provided');
|
||||||
});
|
});
|
||||||
|
|
||||||
Events.trigger(el2, { type:'click', relatedTarget:undefined });
|
Events.trigger(el2, { type: 'click', relatedTarget: undefined });
|
||||||
});
|
});
|
||||||
|
@ -1,16 +1,18 @@
|
|||||||
|
/* eslint-env qunit */
|
||||||
import extendFn from '../../src/js/extend.js';
|
import extendFn from '../../src/js/extend.js';
|
||||||
|
|
||||||
q.module('extend.js');
|
QUnit.module('extend.js');
|
||||||
|
|
||||||
test('should add implicit parent constructor call', function(){
|
QUnit.test('should add implicit parent constructor call', function() {
|
||||||
var superCalled = false;
|
let superCalled = false;
|
||||||
var Parent = function() {
|
const Parent = function() {
|
||||||
superCalled = true;
|
superCalled = true;
|
||||||
};
|
};
|
||||||
var Child = extendFn(Parent, {
|
const Child = extendFn(Parent, {
|
||||||
foo: 'bar'
|
foo: 'bar'
|
||||||
});
|
});
|
||||||
var child = new Child();
|
const child = new Child();
|
||||||
ok(superCalled, 'super constructor called');
|
|
||||||
ok(child.foo, 'child properties set');
|
QUnit.ok(superCalled, 'super constructor called');
|
||||||
|
QUnit.ok(child.foo, 'child properties set');
|
||||||
});
|
});
|
||||||
|
@ -1,75 +1,75 @@
|
|||||||
|
/* eslint-env qunit */
|
||||||
import MenuButton from '../../src/js/menu/menu-button.js';
|
import MenuButton from '../../src/js/menu/menu-button.js';
|
||||||
import TestHelpers from './test-helpers.js';
|
import TestHelpers from './test-helpers.js';
|
||||||
import * as Events from '../../src/js/utils/events.js';
|
import * as Events from '../../src/js/utils/events.js';
|
||||||
|
|
||||||
q.module('MenuButton');
|
QUnit.module('MenuButton');
|
||||||
|
|
||||||
q.test('should not throw an error when there is no children', function() {
|
QUnit.test('should not throw an error when there is no children', function() {
|
||||||
expect(0);
|
QUnit.expect(0);
|
||||||
let player = TestHelpers.makePlayer();
|
const player = TestHelpers.makePlayer();
|
||||||
|
|
||||||
let menuButton = new MenuButton(player);
|
const menuButton = new MenuButton(player);
|
||||||
let el = menuButton.el();
|
const el = menuButton.el();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Events.trigger(el, 'click');
|
Events.trigger(el, 'click');
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
ok(!error, 'click should not throw anything');
|
QUnit.ok(!error, 'click should not throw anything');
|
||||||
}
|
}
|
||||||
|
|
||||||
player.dispose();
|
player.dispose();
|
||||||
});
|
});
|
||||||
|
|
||||||
q.test('should place title list item into ul', function() {
|
QUnit.test('should place title list item into ul', function() {
|
||||||
var player, menuButton;
|
const player = TestHelpers.makePlayer();
|
||||||
player = TestHelpers.makePlayer();
|
|
||||||
|
|
||||||
menuButton = new MenuButton(player, {
|
const menuButton = new MenuButton(player, {
|
||||||
'title': 'testTitle'
|
title: 'testTitle'
|
||||||
});
|
});
|
||||||
|
|
||||||
let menuContentElement = menuButton.el().getElementsByTagName('UL')[0];
|
const menuContentElement = menuButton.el().getElementsByTagName('UL')[0];
|
||||||
let titleElement = menuContentElement.children[0];
|
const titleElement = menuContentElement.children[0];
|
||||||
|
|
||||||
ok(titleElement.innerHTML === 'TestTitle', 'title element placed in ul');
|
QUnit.ok(titleElement.innerHTML === 'TestTitle', 'title element placed in ul');
|
||||||
|
|
||||||
player.dispose();
|
player.dispose();
|
||||||
});
|
});
|
||||||
|
|
||||||
q.test('clicking should display the menu', function() {
|
QUnit.test('clicking should display the menu', function() {
|
||||||
expect(6);
|
QUnit.expect(6);
|
||||||
|
|
||||||
let player = TestHelpers.makePlayer();
|
const player = TestHelpers.makePlayer();
|
||||||
|
|
||||||
// Make sure there's some content in the menu, even if it's just a title!
|
// Make sure there's some content in the menu, even if it's just a title!
|
||||||
let menuButton = new MenuButton(player, {
|
const menuButton = new MenuButton(player, {
|
||||||
'title': 'testTitle'
|
title: 'testTitle'
|
||||||
});
|
});
|
||||||
let el = menuButton.el();
|
const el = menuButton.el();
|
||||||
|
|
||||||
ok(menuButton.menu !== undefined, 'menu is created');
|
QUnit.ok(menuButton.menu !== undefined, 'menu is created');
|
||||||
|
|
||||||
equal(menuButton.menu.hasClass('vjs-lock-showing'), false, 'menu defaults to hidden');
|
QUnit.equal(menuButton.menu.hasClass('vjs-lock-showing'), false, 'menu defaults to hidden');
|
||||||
|
|
||||||
Events.trigger(el, 'click');
|
Events.trigger(el, 'click');
|
||||||
|
|
||||||
equal(menuButton.menu.hasClass('vjs-lock-showing'), true, 'clicking on the menu button shows the menu');
|
QUnit.equal(menuButton.menu.hasClass('vjs-lock-showing'), true, 'clicking on the menu button shows the menu');
|
||||||
|
|
||||||
Events.trigger(el, 'click');
|
Events.trigger(el, 'click');
|
||||||
|
|
||||||
equal(menuButton.menu.hasClass('vjs-lock-showing'), false, 'clicking again on the menu button hides the menu');
|
QUnit.equal(menuButton.menu.hasClass('vjs-lock-showing'), false, 'clicking again on the menu button hides the menu');
|
||||||
|
|
||||||
menuButton.disable();
|
menuButton.disable();
|
||||||
|
|
||||||
Events.trigger(el, 'click');
|
Events.trigger(el, 'click');
|
||||||
|
|
||||||
equal(menuButton.menu.hasClass('vjs-lock-showing'), false, 'disable() prevents clicking from showing the menu');
|
QUnit.equal(menuButton.menu.hasClass('vjs-lock-showing'), false, 'disable() prevents clicking from showing the menu');
|
||||||
|
|
||||||
menuButton.enable();
|
menuButton.enable();
|
||||||
|
|
||||||
Events.trigger(el, 'click');
|
Events.trigger(el, 'click');
|
||||||
|
|
||||||
equal(menuButton.menu.hasClass('vjs-lock-showing'), true, 'enable() allows clicking to show the menu');
|
QUnit.equal(menuButton.menu.hasClass('vjs-lock-showing'), true, 'enable() allows clicking to show the menu');
|
||||||
|
|
||||||
player.dispose();
|
player.dispose();
|
||||||
});
|
});
|
||||||
|
@ -1,28 +1,29 @@
|
|||||||
|
/* eslint-env qunit */
|
||||||
import CloseButton from '../../src/js/close-button';
|
import CloseButton from '../../src/js/close-button';
|
||||||
|
import sinon from 'sinon';
|
||||||
import ModalDialog from '../../src/js/modal-dialog';
|
import ModalDialog from '../../src/js/modal-dialog';
|
||||||
import * as Dom from '../../src/js/utils/dom';
|
import * as Dom from '../../src/js/utils/dom';
|
||||||
import * as Fn from '../../src/js/utils/fn';
|
|
||||||
import TestHelpers from './test-helpers';
|
import TestHelpers from './test-helpers';
|
||||||
|
|
||||||
var ESC = 27;
|
const ESC = 27;
|
||||||
|
|
||||||
q.module('ModalDialog', {
|
QUnit.module('ModalDialog', {
|
||||||
|
|
||||||
beforeEach: function() {
|
beforeEach() {
|
||||||
this.player = TestHelpers.makePlayer();
|
this.player = TestHelpers.makePlayer();
|
||||||
this.modal = new ModalDialog(this.player, {temporary: false});
|
this.modal = new ModalDialog(this.player, {temporary: false});
|
||||||
this.el = this.modal.el();
|
this.el = this.modal.el();
|
||||||
},
|
},
|
||||||
|
|
||||||
afterEach: function() {
|
afterEach() {
|
||||||
this.player.dispose();
|
this.player.dispose();
|
||||||
this.modal.dispose();
|
this.modal.dispose();
|
||||||
this.el = null;
|
this.el = null;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
q.test('should create the expected element', function(assert) {
|
QUnit.test('should create the expected element', function(assert) {
|
||||||
let elAssertions = TestHelpers.assertEl(assert, this.el, {
|
const elAssertions = TestHelpers.assertEl(assert, this.el, {
|
||||||
tagName: 'div',
|
tagName: 'div',
|
||||||
classes: [
|
classes: [
|
||||||
'vjs-modal-dialog',
|
'vjs-modal-dialog',
|
||||||
@ -43,8 +44,8 @@ q.test('should create the expected element', function(assert) {
|
|||||||
elAssertions();
|
elAssertions();
|
||||||
});
|
});
|
||||||
|
|
||||||
q.test('should create the expected description element', function(assert) {
|
QUnit.test('should create the expected description element', function(assert) {
|
||||||
let elAssertions = TestHelpers.assertEl(assert, this.modal.descEl_, {
|
const elAssertions = TestHelpers.assertEl(assert, this.modal.descEl_, {
|
||||||
tagName: 'p',
|
tagName: 'p',
|
||||||
innerHTML: this.modal.description(),
|
innerHTML: this.modal.description(),
|
||||||
classes: [
|
classes: [
|
||||||
@ -60,8 +61,8 @@ q.test('should create the expected description element', function(assert) {
|
|||||||
elAssertions();
|
elAssertions();
|
||||||
});
|
});
|
||||||
|
|
||||||
q.test('should create the expected contentEl', function(assert) {
|
QUnit.test('should create the expected contentEl', function(assert) {
|
||||||
let elAssertions = TestHelpers.assertEl(assert, this.modal.contentEl(), {
|
const elAssertions = TestHelpers.assertEl(assert, this.modal.contentEl(), {
|
||||||
tagName: 'div',
|
tagName: 'div',
|
||||||
classes: [
|
classes: [
|
||||||
'vjs-modal-dialog-content'
|
'vjs-modal-dialog-content'
|
||||||
@ -75,8 +76,8 @@ q.test('should create the expected contentEl', function(assert) {
|
|||||||
elAssertions();
|
elAssertions();
|
||||||
});
|
});
|
||||||
|
|
||||||
q.test('should create a close button by default', function(assert) {
|
QUnit.test('should create a close button by default', function(assert) {
|
||||||
var btn = this.modal.getChild('closeButton');
|
const btn = this.modal.getChild('closeButton');
|
||||||
|
|
||||||
// We only check the aspects of the button that relate to the modal. Other
|
// 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
|
// aspects of the button (classes, etc) are tested in their appropriate test
|
||||||
@ -86,8 +87,8 @@ q.test('should create a close button by default', function(assert) {
|
|||||||
assert.strictEqual(btn.el().parentNode, this.el, 'close button is a child of el');
|
assert.strictEqual(btn.el().parentNode, this.el, 'close button is a child of el');
|
||||||
});
|
});
|
||||||
|
|
||||||
q.test('returns `this` for expected methods', function(assert) {
|
QUnit.test('returns `this` for expected methods', function(assert) {
|
||||||
var methods = ['close', 'empty', 'fill', 'fillWith', 'open'];
|
const methods = ['close', 'empty', 'fill', 'fillWith', 'open'];
|
||||||
|
|
||||||
assert.expect(methods.length);
|
assert.expect(methods.length);
|
||||||
methods.forEach(function(method) {
|
methods.forEach(function(method) {
|
||||||
@ -95,13 +96,13 @@ q.test('returns `this` for expected methods', function(assert) {
|
|||||||
}, this.modal);
|
}, this.modal);
|
||||||
});
|
});
|
||||||
|
|
||||||
q.test('open() triggers events', function(assert) {
|
QUnit.test('open() triggers events', function(assert) {
|
||||||
var modal = this.modal;
|
const modal = this.modal;
|
||||||
var beforeModalOpenSpy = sinon.spy(function() {
|
const beforeModalOpenSpy = sinon.spy(function() {
|
||||||
assert.notOk(modal.opened(), 'modal is not opened before opening event');
|
assert.notOk(modal.opened(), 'modal is not opened before opening event');
|
||||||
});
|
});
|
||||||
|
|
||||||
var modalOpenSpy = sinon.spy(function() {
|
const modalOpenSpy = sinon.spy(function() {
|
||||||
assert.ok(modal.opened(), 'modal is opened on opening event');
|
assert.ok(modal.opened(), 'modal is opened on opening event');
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -116,15 +117,15 @@ q.test('open() triggers events', function(assert) {
|
|||||||
assert.strictEqual(modalOpenSpy.callCount, 1, 'modalopen spy was called');
|
assert.strictEqual(modalOpenSpy.callCount, 1, 'modalopen spy was called');
|
||||||
});
|
});
|
||||||
|
|
||||||
q.test('open() removes "vjs-hidden" class', function(assert) {
|
QUnit.test('open() removes "vjs-hidden" class', function(assert) {
|
||||||
assert.expect(2);
|
assert.expect(2);
|
||||||
assert.ok(this.modal.hasClass('vjs-hidden'), 'modal starts hidden');
|
assert.ok(this.modal.hasClass('vjs-hidden'), 'modal starts hidden');
|
||||||
this.modal.open();
|
this.modal.open();
|
||||||
assert.notOk(this.modal.hasClass('vjs-hidden'), 'modal is not hidden after opening');
|
assert.notOk(this.modal.hasClass('vjs-hidden'), 'modal is not hidden after opening');
|
||||||
});
|
});
|
||||||
|
|
||||||
q.test('open() cannot be called on an opened modal', function(assert) {
|
QUnit.test('open() cannot be called on an opened modal', function(assert) {
|
||||||
var spy = sinon.spy();
|
const spy = sinon.spy();
|
||||||
|
|
||||||
this.modal.on('modalopen', spy).open().open();
|
this.modal.on('modalopen', spy).open().open();
|
||||||
|
|
||||||
@ -132,13 +133,13 @@ q.test('open() cannot be called on an opened modal', function(assert) {
|
|||||||
assert.strictEqual(spy.callCount, 1, 'modal was only opened once');
|
assert.strictEqual(spy.callCount, 1, 'modal was only opened once');
|
||||||
});
|
});
|
||||||
|
|
||||||
q.test('close() triggers events', function(assert) {
|
QUnit.test('close() triggers events', function(assert) {
|
||||||
var modal = this.modal;
|
const modal = this.modal;
|
||||||
var beforeModalCloseSpy = sinon.spy(function() {
|
const beforeModalCloseSpy = sinon.spy(function() {
|
||||||
assert.ok(modal.opened(), 'modal is not closed before closing event');
|
assert.ok(modal.opened(), 'modal is not closed before closing event');
|
||||||
});
|
});
|
||||||
|
|
||||||
var modalCloseSpy = sinon.spy(function() {
|
const modalCloseSpy = sinon.spy(function() {
|
||||||
assert.notOk(modal.opened(), 'modal is closed on closing event');
|
assert.notOk(modal.opened(), 'modal is closed on closing event');
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -154,14 +155,14 @@ q.test('close() triggers events', function(assert) {
|
|||||||
assert.strictEqual(modalCloseSpy.callCount, 1, 'modalclose spy was called');
|
assert.strictEqual(modalCloseSpy.callCount, 1, 'modalclose spy was called');
|
||||||
});
|
});
|
||||||
|
|
||||||
q.test('close() adds the "vjs-hidden" class', function(assert) {
|
QUnit.test('close() adds the "vjs-hidden" class', function(assert) {
|
||||||
assert.expect(1);
|
assert.expect(1);
|
||||||
this.modal.open().close();
|
this.modal.open().close();
|
||||||
assert.ok(this.modal.hasClass('vjs-hidden'), 'modal is hidden upon close');
|
assert.ok(this.modal.hasClass('vjs-hidden'), 'modal is hidden upon close');
|
||||||
});
|
});
|
||||||
|
|
||||||
q.test('pressing ESC triggers close(), but only when the modal is opened', function(assert) {
|
QUnit.test('pressing ESC triggers close(), but only when the modal is opened', function(assert) {
|
||||||
var spy = sinon.spy();
|
const spy = sinon.spy();
|
||||||
|
|
||||||
this.modal.on('modalclose', spy).handleKeyPress({which: ESC});
|
this.modal.on('modalclose', spy).handleKeyPress({which: ESC});
|
||||||
assert.expect(2);
|
assert.expect(2);
|
||||||
@ -171,8 +172,8 @@ q.test('pressing ESC triggers close(), but only when the modal is opened', funct
|
|||||||
assert.strictEqual(spy.callCount, 1, 'ESC closed the now-opened modal');
|
assert.strictEqual(spy.callCount, 1, 'ESC closed the now-opened modal');
|
||||||
});
|
});
|
||||||
|
|
||||||
q.test('close() cannot be called on a closed modal', function(assert) {
|
QUnit.test('close() cannot be called on a closed modal', function(assert) {
|
||||||
var spy = sinon.spy();
|
const spy = sinon.spy();
|
||||||
|
|
||||||
this.modal.on('modalclose', spy);
|
this.modal.on('modalclose', spy);
|
||||||
this.modal.open().close().close();
|
this.modal.open().close().close();
|
||||||
@ -181,9 +182,9 @@ q.test('close() cannot be called on a closed modal', function(assert) {
|
|||||||
assert.strictEqual(spy.callCount, 1, 'modal was only closed once');
|
assert.strictEqual(spy.callCount, 1, 'modal was only closed once');
|
||||||
});
|
});
|
||||||
|
|
||||||
q.test('open() pauses playback, close() resumes', function(assert) {
|
QUnit.test('open() pauses playback, close() resumes', function(assert) {
|
||||||
var playSpy = sinon.spy();
|
const playSpy = sinon.spy();
|
||||||
var pauseSpy = sinon.spy();
|
const pauseSpy = sinon.spy();
|
||||||
|
|
||||||
// Quick and dirty; make it looks like the player is playing.
|
// Quick and dirty; make it looks like the player is playing.
|
||||||
this.player.paused = function() {
|
this.player.paused = function() {
|
||||||
@ -207,7 +208,7 @@ q.test('open() pauses playback, close() resumes', function(assert) {
|
|||||||
assert.strictEqual(playSpy.callCount, 1, 'player is resumed when the modal closes');
|
assert.strictEqual(playSpy.callCount, 1, 'player is resumed when the modal closes');
|
||||||
});
|
});
|
||||||
|
|
||||||
q.test('open() hides controls, close() shows controls', function(assert) {
|
QUnit.test('open() hides controls, close() shows controls', function(assert) {
|
||||||
this.modal.open();
|
this.modal.open();
|
||||||
|
|
||||||
assert.expect(2);
|
assert.expect(2);
|
||||||
@ -217,9 +218,9 @@ q.test('open() hides controls, close() shows controls', function(assert) {
|
|||||||
assert.ok(this.player.controls_, 'controls are no longer hidden');
|
assert.ok(this.player.controls_, 'controls are no longer hidden');
|
||||||
});
|
});
|
||||||
|
|
||||||
q.test('opened()', function(assert) {
|
QUnit.test('opened()', function(assert) {
|
||||||
var openSpy = sinon.spy();
|
const openSpy = sinon.spy();
|
||||||
var closeSpy = sinon.spy();
|
const closeSpy = sinon.spy();
|
||||||
|
|
||||||
assert.expect(4);
|
assert.expect(4);
|
||||||
assert.strictEqual(this.modal.opened(), false, 'the modal is closed');
|
assert.strictEqual(this.modal.opened(), false, 'the modal is closed');
|
||||||
@ -238,23 +239,22 @@ q.test('opened()', function(assert) {
|
|||||||
assert.strictEqual(closeSpy.callCount, 1, 'modal was closed only once');
|
assert.strictEqual(closeSpy.callCount, 1, 'modal was closed only once');
|
||||||
});
|
});
|
||||||
|
|
||||||
q.test('content()', function(assert) {
|
QUnit.test('content()', function(assert) {
|
||||||
var content;
|
|
||||||
|
|
||||||
assert.expect(3);
|
assert.expect(3);
|
||||||
assert.strictEqual(typeof this.modal.content(), 'undefined', 'no content by default');
|
assert.strictEqual(typeof this.modal.content(), 'undefined', 'no content by default');
|
||||||
|
|
||||||
content = this.modal.content(Dom.createEl());
|
const content = this.modal.content(Dom.createEl());
|
||||||
|
|
||||||
assert.ok(Dom.isEl(content), 'content was set from a single DOM element');
|
assert.ok(Dom.isEl(content), 'content was set from a single DOM element');
|
||||||
|
|
||||||
assert.strictEqual(this.modal.content(null), null, 'content was nullified');
|
assert.strictEqual(this.modal.content(null), null, 'content was nullified');
|
||||||
});
|
});
|
||||||
|
|
||||||
q.test('fillWith()', function(assert) {
|
QUnit.test('fillWith()', function(assert) {
|
||||||
var contentEl = this.modal.contentEl();
|
const contentEl = this.modal.contentEl();
|
||||||
var children = [Dom.createEl(), Dom.createEl(), Dom.createEl()];
|
const children = [Dom.createEl(), Dom.createEl(), Dom.createEl()];
|
||||||
var beforeFillSpy = sinon.spy();
|
const beforeFillSpy = sinon.spy();
|
||||||
var fillSpy = sinon.spy();
|
const fillSpy = sinon.spy();
|
||||||
|
|
||||||
children.forEach(function(el) {
|
children.forEach(function(el) {
|
||||||
contentEl.appendChild(el);
|
contentEl.appendChild(el);
|
||||||
@ -278,9 +278,9 @@ q.test('fillWith()', function(assert) {
|
|||||||
assert.strictEqual(fillSpy.getCall(0).thisValue, this.modal, 'the value of "this" is the modal');
|
assert.strictEqual(fillSpy.getCall(0).thisValue, this.modal, 'the value of "this" is the modal');
|
||||||
});
|
});
|
||||||
|
|
||||||
q.test('empty()', function(assert) {
|
QUnit.test('empty()', function(assert) {
|
||||||
var beforeEmptySpy = sinon.spy();
|
const beforeEmptySpy = sinon.spy();
|
||||||
var emptySpy = sinon.spy();
|
const emptySpy = sinon.spy();
|
||||||
|
|
||||||
this.modal.
|
this.modal.
|
||||||
fillWith([Dom.createEl(), Dom.createEl()]).
|
fillWith([Dom.createEl(), Dom.createEl()]).
|
||||||
@ -296,8 +296,8 @@ q.test('empty()', function(assert) {
|
|||||||
assert.strictEqual(emptySpy.getCall(0).thisValue, this.modal, 'the value of "this" is the modal');
|
assert.strictEqual(emptySpy.getCall(0).thisValue, this.modal, 'the value of "this" is the modal');
|
||||||
});
|
});
|
||||||
|
|
||||||
q.test('closeable()', function(assert) {
|
QUnit.test('closeable()', function(assert) {
|
||||||
let initialCloseButton = this.modal.getChild('closeButton');
|
const initialCloseButton = this.modal.getChild('closeButton');
|
||||||
|
|
||||||
assert.expect(8);
|
assert.expect(8);
|
||||||
assert.strictEqual(this.modal.closeable(), true, 'the modal is closed');
|
assert.strictEqual(this.modal.closeable(), true, 'the modal is closed');
|
||||||
@ -322,13 +322,13 @@ q.test('closeable()', function(assert) {
|
|||||||
assert.notOk(this.modal.opened(), 'the modal was closed by the ESC key');
|
assert.notOk(this.modal.opened(), 'the modal was closed by the ESC key');
|
||||||
});
|
});
|
||||||
|
|
||||||
q.test('"content" option (fills on first open() invocation)', function(assert) {
|
QUnit.test('"content" option (fills on first open() invocation)', function(assert) {
|
||||||
var modal = new ModalDialog(this.player, {
|
const modal = new ModalDialog(this.player, {
|
||||||
content: Dom.createEl(),
|
content: Dom.createEl(),
|
||||||
temporary: false
|
temporary: false
|
||||||
});
|
});
|
||||||
|
|
||||||
var spy = sinon.spy();
|
const spy = sinon.spy();
|
||||||
|
|
||||||
modal.on('modalfill', spy);
|
modal.on('modalfill', spy);
|
||||||
modal.open().close().open();
|
modal.open().close().open();
|
||||||
@ -339,11 +339,11 @@ q.test('"content" option (fills on first open() invocation)', function(assert) {
|
|||||||
assert.strictEqual(modal.contentEl().firstChild, modal.options_.content, 'has the expected content in the DOM');
|
assert.strictEqual(modal.contentEl().firstChild, modal.options_.content, 'has the expected content in the DOM');
|
||||||
});
|
});
|
||||||
|
|
||||||
q.test('"temporary" option', function(assert) {
|
QUnit.test('"temporary" option', function(assert) {
|
||||||
var temp = new ModalDialog(this.player, {temporary: true});
|
const temp = new ModalDialog(this.player, {temporary: true});
|
||||||
var tempSpy = sinon.spy();
|
const tempSpy = sinon.spy();
|
||||||
var perm = new ModalDialog(this.player, {temporary: false});
|
const perm = new ModalDialog(this.player, {temporary: false});
|
||||||
var permSpy = sinon.spy();
|
const permSpy = sinon.spy();
|
||||||
|
|
||||||
temp.on('dispose', tempSpy);
|
temp.on('dispose', tempSpy);
|
||||||
perm.on('dispose', permSpy);
|
perm.on('dispose', permSpy);
|
||||||
@ -355,14 +355,14 @@ q.test('"temporary" option', function(assert) {
|
|||||||
assert.strictEqual(permSpy.callCount, 0, 'permanent modals are not disposed');
|
assert.strictEqual(permSpy.callCount, 0, 'permanent modals are not disposed');
|
||||||
});
|
});
|
||||||
|
|
||||||
q.test('"fillAlways" option', function(assert) {
|
QUnit.test('"fillAlways" option', function(assert) {
|
||||||
var modal = new ModalDialog(this.player, {
|
const modal = new ModalDialog(this.player, {
|
||||||
content: 'foo',
|
content: 'foo',
|
||||||
fillAlways: true,
|
fillAlways: true,
|
||||||
temporary: false
|
temporary: false
|
||||||
});
|
});
|
||||||
|
|
||||||
var spy = sinon.spy();
|
const spy = sinon.spy();
|
||||||
|
|
||||||
modal.on('modalfill', spy);
|
modal.on('modalfill', spy);
|
||||||
modal.open().close().open();
|
modal.open().close().open();
|
||||||
@ -371,21 +371,21 @@ q.test('"fillAlways" option', function(assert) {
|
|||||||
assert.strictEqual(spy.callCount, 2, 'the modal was filled on each open call');
|
assert.strictEqual(spy.callCount, 2, 'the modal was filled on each open call');
|
||||||
});
|
});
|
||||||
|
|
||||||
q.test('"label" option', function(assert) {
|
QUnit.test('"label" option', function(assert) {
|
||||||
var label = 'foo';
|
const label = 'foo';
|
||||||
var modal = new ModalDialog(this.player, {label: label});
|
const modal = new ModalDialog(this.player, {label});
|
||||||
|
|
||||||
assert.expect(1);
|
assert.expect(1);
|
||||||
assert.strictEqual(modal.el().getAttribute('aria-label'), label, 'uses the label as the aria-label');
|
assert.strictEqual(modal.el().getAttribute('aria-label'), label, 'uses the label as the aria-label');
|
||||||
});
|
});
|
||||||
|
|
||||||
q.test('"uncloseable" option', function(assert) {
|
QUnit.test('"uncloseable" option', function(assert) {
|
||||||
var modal = new ModalDialog(this.player, {
|
const modal = new ModalDialog(this.player, {
|
||||||
temporary: false,
|
temporary: false,
|
||||||
uncloseable: true
|
uncloseable: true
|
||||||
});
|
});
|
||||||
|
|
||||||
var spy = sinon.spy();
|
const spy = sinon.spy();
|
||||||
|
|
||||||
modal.on('modalclose', spy);
|
modal.on('modalclose', spy);
|
||||||
|
|
||||||
|
File diff suppressed because it is too large
Load Diff
Loading…
x
Reference in New Issue
Block a user