Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
mister-ben committed Nov 13, 2024
1 parent 38008a6 commit 43f431a
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion test/unit/menu.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ QUnit.test('should remove old event listeners when the menu item adds to the new

assert.ok(clickListenerSpy.calledOnce, 'click event listener should be called');
assert.strictEqual(clickListenerSpy.getCall(0).args[0].target, menuItem.el(), 'event target should be the `menuItem`');
assert.ok(unpressButtonSpy.calledOnce, '`menuButton`.`unpressButtion` has been called');
assert.ok(unpressButtonSpy.calledOnce, '`menuButton`.`unpressButton` has been called');
assert.ok(focusSpy.calledOnce, '`menuButton`.`focus` has been called');

unpressButtonSpy.restore();
Expand Down Expand Up @@ -265,3 +265,21 @@ QUnit.test('should remove old event listeners when the menu item adds to the new
oldMenu.dispose();
menuButton.dispose();
});

QUnit.test('Escape should close menu', function(assert) {
const player = TestHelpers.makePlayer();
const menuButton = new MenuButton(player, {});
const unpressButtonSpy = sinon.spy(menuButton, 'unpressButton');

menuButton.createItems = () => [new MenuItem(player, {})];
menuButton.update();
menuButton.handleClick(new window.PointerEvent('click'));
menuButton.menu.children()[0].el_.dispatchEvent(new window.KeyboardEvent('keydown', {
key: 'Escape',
bubbles: true,
cancelable: true
}));

assert.ok(unpressButtonSpy.calledOnce, '`menuButton`.`unpressButton` has been called');

});

0 comments on commit 43f431a

Please sign in to comment.