2016-08-04 17:49:32 +02:00
|
|
|
/* eslint-env qunit */
|
2015-04-14 22:08:32 +02:00
|
|
|
import MenuButton from '../../src/js/menu/menu-button.js';
|
2015-03-26 06:43:41 +02:00
|
|
|
import TestHelpers from './test-helpers.js';
|
2016-03-25 20:16:56 +02:00
|
|
|
import * as Events from '../../src/js/utils/events.js';
|
2015-03-26 06:43:41 +02:00
|
|
|
|
2016-08-04 17:49:32 +02:00
|
|
|
QUnit.module('MenuButton');
|
2014-03-26 10:40:14 +03:00
|
|
|
|
2016-08-12 19:51:31 +02:00
|
|
|
QUnit.test('should not throw an error when there is no children', function(assert) {
|
|
|
|
assert.expect(0);
|
2016-08-04 17:49:32 +02:00
|
|
|
const player = TestHelpers.makePlayer();
|
2014-03-26 10:40:14 +03:00
|
|
|
|
2016-08-04 17:49:32 +02:00
|
|
|
const menuButton = new MenuButton(player);
|
|
|
|
const el = menuButton.el();
|
2016-03-29 22:09:10 +02:00
|
|
|
|
|
|
|
try {
|
|
|
|
Events.trigger(el, 'click');
|
|
|
|
} catch (error) {
|
2016-08-12 19:51:31 +02:00
|
|
|
assert.ok(!error, 'click should not throw anything');
|
2016-03-29 22:09:10 +02:00
|
|
|
}
|
2014-03-26 10:40:14 +03:00
|
|
|
|
2016-03-29 22:09:10 +02:00
|
|
|
player.dispose();
|
|
|
|
});
|
|
|
|
|
2016-08-12 19:51:31 +02:00
|
|
|
QUnit.test('should place title list item into ul', function(assert) {
|
2016-08-04 17:49:32 +02:00
|
|
|
const player = TestHelpers.makePlayer();
|
2014-03-26 10:40:14 +03:00
|
|
|
|
2016-08-04 17:49:32 +02:00
|
|
|
const menuButton = new MenuButton(player, {
|
|
|
|
title: 'testTitle'
|
2014-03-26 10:40:14 +03:00
|
|
|
});
|
|
|
|
|
2016-08-04 17:49:32 +02:00
|
|
|
const menuContentElement = menuButton.el().getElementsByTagName('UL')[0];
|
|
|
|
const titleElement = menuContentElement.children[0];
|
2014-03-26 10:40:14 +03:00
|
|
|
|
2016-08-12 19:51:31 +02:00
|
|
|
assert.ok(titleElement.innerHTML === 'TestTitle', 'title element placed in ul');
|
2014-03-26 10:40:14 +03:00
|
|
|
|
|
|
|
player.dispose();
|
2016-03-25 20:16:56 +02:00
|
|
|
});
|
|
|
|
|
2016-08-12 19:51:31 +02:00
|
|
|
QUnit.test('clicking should display the menu', function(assert) {
|
|
|
|
assert.expect(6);
|
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
|
|
|
|
|
|
|
// Make sure there's some content in the menu, even if it's just a title!
|
2016-08-04 17:49:32 +02:00
|
|
|
const menuButton = new MenuButton(player, {
|
|
|
|
title: 'testTitle'
|
2016-03-25 20:16:56 +02:00
|
|
|
});
|
2016-08-04 17:49:32 +02:00
|
|
|
const el = menuButton.el();
|
2016-03-25 20:16:56 +02:00
|
|
|
|
2016-08-12 19:51:31 +02:00
|
|
|
assert.ok(menuButton.menu !== undefined, 'menu is created');
|
2016-03-25 20:16:56 +02:00
|
|
|
|
2016-08-12 19:51:31 +02:00
|
|
|
assert.equal(menuButton.menu.hasClass('vjs-lock-showing'), false, 'menu defaults to hidden');
|
2016-03-25 20:16:56 +02:00
|
|
|
|
|
|
|
Events.trigger(el, 'click');
|
|
|
|
|
2016-08-12 19:51:31 +02:00
|
|
|
assert.equal(menuButton.menu.hasClass('vjs-lock-showing'), true, 'clicking on the menu button shows the menu');
|
2016-03-25 20:16:56 +02:00
|
|
|
|
|
|
|
Events.trigger(el, 'click');
|
|
|
|
|
2016-08-12 19:51:31 +02:00
|
|
|
assert.equal(menuButton.menu.hasClass('vjs-lock-showing'), false, 'clicking again on the menu button hides the menu');
|
2016-03-25 20:16:56 +02:00
|
|
|
|
|
|
|
menuButton.disable();
|
|
|
|
|
|
|
|
Events.trigger(el, 'click');
|
|
|
|
|
2016-08-12 19:51:31 +02:00
|
|
|
assert.equal(menuButton.menu.hasClass('vjs-lock-showing'), false, 'disable() prevents clicking from showing the menu');
|
2016-03-25 20:16:56 +02:00
|
|
|
|
|
|
|
menuButton.enable();
|
|
|
|
|
|
|
|
Events.trigger(el, 'click');
|
|
|
|
|
2016-08-12 19:51:31 +02:00
|
|
|
assert.equal(menuButton.menu.hasClass('vjs-lock-showing'), true, 'enable() allows clicking to show the menu');
|
2016-03-25 20:16:56 +02:00
|
|
|
|
|
|
|
player.dispose();
|
|
|
|
});
|