2016-08-04 17:49:32 +02:00
|
|
|
/* eslint-env qunit */
|
2016-01-26 01:30:12 +02:00
|
|
|
import ClickableComponent from '../../src/js/clickable-component.js';
|
|
|
|
import TestHelpers from './test-helpers.js';
|
2016-11-03 21:43:15 +02:00
|
|
|
import * as Events from '../../src/js/utils/events.js';
|
2016-01-26 01:30:12 +02:00
|
|
|
|
2016-08-04 17:49:32 +02:00
|
|
|
QUnit.module('ClickableComponent');
|
2016-01-26 01:30:12 +02:00
|
|
|
|
2016-08-12 19:51:31 +02:00
|
|
|
QUnit.test('should create a div with role="button"', function(assert) {
|
|
|
|
assert.expect(2);
|
2016-01-26 01:30:12 +02:00
|
|
|
|
2016-08-04 17:49:32 +02:00
|
|
|
const player = TestHelpers.makePlayer({});
|
2016-01-26 01:30:12 +02:00
|
|
|
|
2016-08-04 17:49:32 +02:00
|
|
|
const testClickableComponent = new ClickableComponent(player);
|
|
|
|
const el = testClickableComponent.createEl();
|
2016-01-26 01:30:12 +02:00
|
|
|
|
2016-08-12 19:51:31 +02:00
|
|
|
assert.equal(el.nodeName.toLowerCase(), 'div', 'the name of the element is "div"');
|
|
|
|
assert.equal(el.getAttribute('role').toLowerCase(), 'button', 'the role of the element is "button"');
|
2016-03-25 20:16:56 +02:00
|
|
|
|
|
|
|
testClickableComponent.dispose();
|
|
|
|
player.dispose();
|
|
|
|
});
|
|
|
|
|
2016-08-12 19:51:31 +02:00
|
|
|
QUnit.test('should be enabled/disabled', function(assert) {
|
|
|
|
assert.expect(3);
|
2016-03-25 20:16:56 +02:00
|
|
|
|
2016-08-04 17:49:32 +02:00
|
|
|
const player = TestHelpers.makePlayer({});
|
2016-03-25 20:16:56 +02:00
|
|
|
|
2016-08-04 17:49:32 +02:00
|
|
|
const testClickableComponent = new ClickableComponent(player);
|
2016-03-25 20:16:56 +02:00
|
|
|
|
2016-08-12 19:51:31 +02:00
|
|
|
assert.equal(testClickableComponent.hasClass('vjs-disabled'), false, 'ClickableComponent defaults to enabled');
|
2016-03-25 20:16:56 +02:00
|
|
|
|
|
|
|
testClickableComponent.disable();
|
|
|
|
|
2016-08-12 19:51:31 +02:00
|
|
|
assert.equal(testClickableComponent.hasClass('vjs-disabled'), true, 'ClickableComponent is disabled');
|
2016-03-25 20:16:56 +02:00
|
|
|
|
|
|
|
testClickableComponent.enable();
|
|
|
|
|
2016-08-12 19:51:31 +02:00
|
|
|
assert.equal(testClickableComponent.hasClass('vjs-disabled'), false, 'ClickableComponent is enabled');
|
2016-03-25 20:16:56 +02:00
|
|
|
|
|
|
|
testClickableComponent.dispose();
|
|
|
|
player.dispose();
|
2016-01-26 01:30:12 +02:00
|
|
|
});
|
2016-11-03 21:43:15 +02:00
|
|
|
|
2017-11-17 01:12:09 +02:00
|
|
|
QUnit.test('handleClick should not be triggered when disabled', function(assert) {
|
2016-11-03 21:43:15 +02:00
|
|
|
let clicks = 0;
|
|
|
|
|
|
|
|
class TestClickableComponent extends ClickableComponent {
|
|
|
|
handleClick() {
|
|
|
|
clicks++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const player = TestHelpers.makePlayer({});
|
|
|
|
const testClickableComponent = new TestClickableComponent(player);
|
|
|
|
const el = testClickableComponent.el();
|
|
|
|
|
|
|
|
// 1st click
|
|
|
|
Events.trigger(el, 'click');
|
2017-11-17 01:12:09 +02:00
|
|
|
assert.equal(clicks, 1, 'click on enabled ClickableComponent is handled');
|
2016-11-03 21:43:15 +02:00
|
|
|
|
|
|
|
testClickableComponent.disable();
|
|
|
|
// No click should happen.
|
|
|
|
Events.trigger(el, 'click');
|
2017-11-17 01:12:09 +02:00
|
|
|
assert.equal(clicks, 1, 'click on disabled ClickableComponent is not handled');
|
2016-11-03 21:43:15 +02:00
|
|
|
|
|
|
|
testClickableComponent.enable();
|
|
|
|
// 2nd Click
|
|
|
|
Events.trigger(el, 'click');
|
2017-11-17 01:12:09 +02:00
|
|
|
assert.equal(clicks, 2, 'click on re-enabled ClickableComponent is handled');
|
2016-11-03 21:43:15 +02:00
|
|
|
|
|
|
|
testClickableComponent.dispose();
|
|
|
|
player.dispose();
|
|
|
|
});
|
2017-05-11 23:32:20 +02:00
|
|
|
|
2017-11-17 01:12:09 +02:00
|
|
|
QUnit.test('handleClick should not be triggered more than once when enabled', function(assert) {
|
2017-05-11 23:32:20 +02:00
|
|
|
let clicks = 0;
|
|
|
|
|
|
|
|
class TestClickableComponent extends ClickableComponent {
|
|
|
|
handleClick() {
|
|
|
|
clicks++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const player = TestHelpers.makePlayer({});
|
|
|
|
const testClickableComponent = new TestClickableComponent(player);
|
|
|
|
const el = testClickableComponent.el();
|
|
|
|
|
|
|
|
testClickableComponent.enable();
|
|
|
|
// Click should still be handled just once
|
|
|
|
Events.trigger(el, 'click');
|
2017-11-17 01:12:09 +02:00
|
|
|
assert.equal(clicks, 1, 'no additional click handler when already enabled ClickableComponent has been enabled again');
|
2017-05-11 23:32:20 +02:00
|
|
|
|
|
|
|
testClickableComponent.dispose();
|
|
|
|
player.dispose();
|
|
|
|
});
|
2019-08-29 22:46:49 +02:00
|
|
|
|
|
|
|
QUnit.test('handleClick should use handler from options', function(assert) {
|
|
|
|
let clicks = 0;
|
|
|
|
|
|
|
|
const player = TestHelpers.makePlayer({});
|
|
|
|
const testClickableComponent = new ClickableComponent(player, {
|
|
|
|
clickHandler() {
|
|
|
|
clicks++;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
const el = testClickableComponent.el();
|
|
|
|
|
|
|
|
Events.trigger(el, 'click');
|
|
|
|
assert.equal(clicks, 1, 'options handler was called');
|
|
|
|
|
|
|
|
testClickableComponent.dispose();
|
|
|
|
player.dispose();
|
|
|
|
});
|
2020-11-11 01:09:37 +02:00
|
|
|
|
|
|
|
QUnit.test('language change should localize its text', function(assert) {
|
|
|
|
assert.expect(2);
|
|
|
|
|
|
|
|
const player = TestHelpers.makePlayer({
|
|
|
|
languages: {
|
|
|
|
es: {
|
|
|
|
Play: 'Juego'
|
|
|
|
},
|
|
|
|
en: {
|
|
|
|
Play: 'Play'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
const testClickableComponent = new ClickableComponent(player);
|
|
|
|
|
|
|
|
testClickableComponent.controlText_ = 'Play';
|
|
|
|
const el = testClickableComponent.createEl();
|
|
|
|
|
|
|
|
player.language('en');
|
|
|
|
assert.equal(el.querySelector('.vjs-control-text').textContent, 'Play', 'text localized');
|
|
|
|
|
|
|
|
player.language('es');
|
|
|
|
assert.equal(el.querySelector('.vjs-control-text').textContent, 'Juego', 'text localized');
|
|
|
|
|
|
|
|
testClickableComponent.dispose();
|
|
|
|
player.dispose();
|
|
|
|
});
|
2022-03-21 18:21:26 +02:00
|
|
|
|
|
|
|
QUnit.test('class and text should be settable from options', function(assert) {
|
|
|
|
const player = TestHelpers.makePlayer({});
|
|
|
|
const testClickableComponent = new ClickableComponent(player, {
|
|
|
|
className: 'class1',
|
|
|
|
controlText: 'some text'
|
|
|
|
});
|
|
|
|
|
|
|
|
assert.equal(testClickableComponent.controlText(), 'some text', 'text was set');
|
|
|
|
assert.ok(testClickableComponent.hasClass('class1'), 'class was set');
|
|
|
|
|
|
|
|
testClickableComponent.dispose();
|
|
|
|
player.dispose();
|
|
|
|
});
|