|
1 | 1 | /* eslint-env qunit */
|
2 | 2 | import MenuButton from '../../src/js/menu/menu-button.js';
|
| 3 | +import MenuItem from '../../src/js/menu/menu-item.js'; |
3 | 4 | import TestHelpers from './test-helpers.js';
|
4 | 5 | import * as Events from '../../src/js/utils/events.js';
|
5 | 6 |
|
@@ -75,3 +76,33 @@ QUnit.test('clicking should display the menu', function(assert) {
|
75 | 76 | menuButton.dispose();
|
76 | 77 | player.dispose();
|
77 | 78 | });
|
| 79 | + |
| 80 | +QUnit.test('should keep all the added menu items', function(assert) { |
| 81 | + const player = TestHelpers.makePlayer(); |
| 82 | + |
| 83 | + const menuItems = []; |
| 84 | + const menuItem1 = new MenuItem(player, { label: 'menu-item1' }); |
| 85 | + const menuItem2 = new MenuItem(player, { label: 'menu-item2' }); |
| 86 | + |
| 87 | + MenuButton.prototype.createItems = function() { |
| 88 | + return menuItems; |
| 89 | + }; |
| 90 | + |
| 91 | + const menuButton = new MenuButton(player, {}); |
| 92 | + |
| 93 | + menuItems.push(menuItem1); |
| 94 | + menuButton.update(); |
| 95 | + |
| 96 | + assert.strictEqual(menuButton.children()[1].children().length, 1, 'the children number of the menu is 1 '); |
| 97 | + assert.strictEqual(menuButton.children()[1].children()[0], menuItem1, 'the first child of the menu is `menuItem1`'); |
| 98 | + assert.ok(menuButton.el().contains(menuItem1.el()), 'the menu button contains the DOM element of `menuItem1`'); |
| 99 | + |
| 100 | + menuItems.push(menuItem2); |
| 101 | + menuButton.update(); |
| 102 | + |
| 103 | + assert.strictEqual(menuButton.children()[1].children().length, 2, 'the children number of the menu is 2 after second update'); |
| 104 | + assert.strictEqual(menuButton.children()[1].children()[0], menuItem1, 'the first child of the menu is `menuItem1` after second update'); |
| 105 | + assert.strictEqual(menuButton.children()[1].children()[1], menuItem2, 'the second child of the menu is `menuItem2` after second update'); |
| 106 | + assert.ok(menuButton.el().contains(menuItem1.el()), 'the menu button contains the DOM element of `menuItem1` after second update'); |
| 107 | + assert.ok(menuButton.el().contains(menuItem2.el()), 'the menu button contains the DOM element of `menuItem2` after second update'); |
| 108 | +}); |
0 commit comments