2016-08-04 11:49:32 -04:00
|
|
|
/* eslint-env qunit */
|
2015-04-14 13:08:32 -07:00
|
|
|
import MenuButton from '../../src/js/menu/menu-button.js';
|
2019-01-09 03:14:46 +08:00
|
|
|
import MenuItem from '../../src/js/menu/menu-item.js';
|
2015-03-25 21:43:41 -07:00
|
|
|
import TestHelpers from './test-helpers.js';
|
2016-03-25 14:16:56 -04:00
|
|
|
import * as Events from '../../src/js/utils/events.js';
|
2015-03-25 21:43:41 -07:00
|
|
|
|
2016-08-04 11:49:32 -04:00
|
|
|
QUnit.module('MenuButton');
|
2014-03-26 00:40:14 -07:00
|
|
|
|
2016-08-12 13:51:31 -04:00
|
|
|
QUnit.test('should not throw an error when there is no children', function(assert) {
|
|
|
|
assert.expect(0);
|
2016-08-04 11:49:32 -04:00
|
|
|
const player = TestHelpers.makePlayer();
|
2014-03-26 00:40:14 -07:00
|
|
|
|
2016-08-04 11:49:32 -04:00
|
|
|
const menuButton = new MenuButton(player);
|
|
|
|
const el = menuButton.el();
|
2016-03-29 16:09:10 -04:00
|
|
|
|
|
|
|
try {
|
|
|
|
Events.trigger(el, 'click');
|
|
|
|
} catch (error) {
|
2016-08-12 13:51:31 -04:00
|
|
|
assert.ok(!error, 'click should not throw anything');
|
2016-03-29 16:09:10 -04:00
|
|
|
}
|
2014-03-26 00:40:14 -07:00
|
|
|
|
2016-03-29 16:09:10 -04:00
|
|
|
player.dispose();
|
|
|
|
});
|
|
|
|
|
2016-08-12 13:51:31 -04:00
|
|
|
QUnit.test('should place title list item into ul', function(assert) {
|
2016-08-04 11:49:32 -04:00
|
|
|
const player = TestHelpers.makePlayer();
|
2014-03-26 00:40:14 -07:00
|
|
|
|
2016-08-04 11:49:32 -04:00
|
|
|
const menuButton = new MenuButton(player, {
|
|
|
|
title: 'testTitle'
|
2014-03-26 00:40:14 -07:00
|
|
|
});
|
|
|
|
|
2016-08-04 11:49:32 -04:00
|
|
|
const menuContentElement = menuButton.el().getElementsByTagName('UL')[0];
|
|
|
|
const titleElement = menuContentElement.children[0];
|
2014-03-26 00:40:14 -07:00
|
|
|
|
2016-08-12 13:51:31 -04:00
|
|
|
assert.ok(titleElement.innerHTML === 'TestTitle', 'title element placed in ul');
|
2014-03-26 00:40:14 -07:00
|
|
|
|
2018-01-30 13:26:21 -05:00
|
|
|
menuButton.dispose();
|
2014-03-26 00:40:14 -07:00
|
|
|
player.dispose();
|
2016-03-25 14:16:56 -04:00
|
|
|
});
|
|
|
|
|
2016-08-12 13:51:31 -04:00
|
|
|
QUnit.test('clicking should display the menu', function(assert) {
|
|
|
|
assert.expect(6);
|
2016-03-25 14:16:56 -04:00
|
|
|
|
2016-08-04 11:49:32 -04:00
|
|
|
const player = TestHelpers.makePlayer();
|
2016-03-25 14:16:56 -04:00
|
|
|
|
|
|
|
// Make sure there's some content in the menu, even if it's just a title!
|
2016-08-04 11:49:32 -04:00
|
|
|
const menuButton = new MenuButton(player, {
|
|
|
|
title: 'testTitle'
|
2016-03-25 14:16:56 -04:00
|
|
|
});
|
2017-02-07 22:24:30 -08:00
|
|
|
const el = menuButton.menuButton_.el();
|
2016-03-25 14:16:56 -04:00
|
|
|
|
2016-08-12 13:51:31 -04:00
|
|
|
assert.ok(menuButton.menu !== undefined, 'menu is created');
|
2016-03-25 14:16:56 -04:00
|
|
|
|
2016-08-12 13:51:31 -04:00
|
|
|
assert.equal(menuButton.menu.hasClass('vjs-lock-showing'), false, 'menu defaults to hidden');
|
2016-03-25 14:16:56 -04:00
|
|
|
|
|
|
|
Events.trigger(el, 'click');
|
|
|
|
|
2016-08-12 13:51:31 -04:00
|
|
|
assert.equal(menuButton.menu.hasClass('vjs-lock-showing'), true, 'clicking on the menu button shows the menu');
|
2016-03-25 14:16:56 -04:00
|
|
|
|
|
|
|
Events.trigger(el, 'click');
|
|
|
|
|
2016-08-12 13:51:31 -04:00
|
|
|
assert.equal(menuButton.menu.hasClass('vjs-lock-showing'), false, 'clicking again on the menu button hides the menu');
|
2016-03-25 14:16:56 -04:00
|
|
|
|
|
|
|
menuButton.disable();
|
|
|
|
|
|
|
|
Events.trigger(el, 'click');
|
|
|
|
|
2016-08-12 13:51:31 -04:00
|
|
|
assert.equal(menuButton.menu.hasClass('vjs-lock-showing'), false, 'disable() prevents clicking from showing the menu');
|
2016-03-25 14:16:56 -04:00
|
|
|
|
|
|
|
menuButton.enable();
|
|
|
|
|
|
|
|
Events.trigger(el, 'click');
|
|
|
|
|
2016-08-12 13:51:31 -04:00
|
|
|
assert.equal(menuButton.menu.hasClass('vjs-lock-showing'), true, 'enable() allows clicking to show the menu');
|
2016-03-25 14:16:56 -04:00
|
|
|
|
2018-01-30 13:26:21 -05:00
|
|
|
menuButton.dispose();
|
2016-03-25 14:16:56 -04:00
|
|
|
player.dispose();
|
|
|
|
});
|
2019-01-09 03:14:46 +08:00
|
|
|
|
|
|
|
QUnit.test('should keep all the added menu items', function(assert) {
|
|
|
|
const player = TestHelpers.makePlayer();
|
|
|
|
|
|
|
|
const menuItems = [];
|
|
|
|
const menuItem1 = new MenuItem(player, { label: 'menu-item1' });
|
|
|
|
const menuItem2 = new MenuItem(player, { label: 'menu-item2' });
|
|
|
|
|
|
|
|
MenuButton.prototype.createItems = function() {
|
|
|
|
return menuItems;
|
|
|
|
};
|
|
|
|
|
|
|
|
const menuButton = new MenuButton(player, {});
|
|
|
|
|
|
|
|
menuItems.push(menuItem1);
|
|
|
|
menuButton.update();
|
|
|
|
|
|
|
|
assert.strictEqual(menuButton.children()[1].children().length, 1, 'the children number of the menu is 1 ');
|
|
|
|
assert.strictEqual(menuButton.children()[1].children()[0], menuItem1, 'the first child of the menu is `menuItem1`');
|
|
|
|
assert.ok(menuButton.el().contains(menuItem1.el()), 'the menu button contains the DOM element of `menuItem1`');
|
|
|
|
|
|
|
|
menuItems.push(menuItem2);
|
|
|
|
menuButton.update();
|
|
|
|
|
|
|
|
assert.strictEqual(menuButton.children()[1].children().length, 2, 'the children number of the menu is 2 after second update');
|
|
|
|
assert.strictEqual(menuButton.children()[1].children()[0], menuItem1, 'the first child of the menu is `menuItem1` after second update');
|
|
|
|
assert.strictEqual(menuButton.children()[1].children()[1], menuItem2, 'the second child of the menu is `menuItem2` after second update');
|
|
|
|
assert.ok(menuButton.el().contains(menuItem1.el()), 'the menu button contains the DOM element of `menuItem1` after second update');
|
|
|
|
assert.ok(menuButton.el().contains(menuItem2.el()), 'the menu button contains the DOM element of `menuItem2` after second update');
|
|
|
|
});
|