1
0
mirror of https://github.com/videojs/video.js.git synced 2024-12-23 02:04:34 +02:00
video.js/test/unit/close-button.test.js
mister-ben 35de64ceb0
refactor: Replace keycode dependency with event.key (#8735)
refactor: Replace keycode dependency with event.key
2024-05-23 18:50:23 +02:00

68 lines
1.7 KiB
JavaScript

/* eslint-env qunit */
import CloseButton from '../../src/js/close-button';
import sinon from 'sinon';
import TestHelpers from './test-helpers';
const getMockEscapeEvent = () => ({
key: 'Escape',
which: 27,
preventDefault() {},
stopPropagation() {}
});
QUnit.module('CloseButton', {
beforeEach() {
this.player = TestHelpers.makePlayer();
this.btn = new CloseButton(this.player);
},
afterEach() {
this.player.dispose();
this.btn.dispose();
}
});
QUnit.test('should create the expected element', function(assert) {
const elAssertions = TestHelpers.assertEl(assert, this.btn.el(), {
tagName: 'button',
classes: [
'vjs-button',
'vjs-close-button',
'vjs-control'
]
});
assert.expect(elAssertions.count + 1);
elAssertions();
assert.strictEqual(this.btn.el().querySelector('.vjs-control-text').innerHTML, 'Close');
});
QUnit.test('should allow setting the controlText_ property as an option', function(assert) {
const text = 'OK!';
const btn = new CloseButton(this.player, {controlText: text});
assert.expect(1);
assert.strictEqual(btn.controlText_, text, 'set the controlText_ property');
btn.dispose();
});
QUnit.test('should trigger an event on activation', function(assert) {
const spy = sinon.spy();
this.btn.on('close', spy);
this.btn.trigger('click');
assert.expect(1);
assert.strictEqual(spy.callCount, 1, 'the "close" event was triggered');
});
QUnit.test('pressing ESC triggers close()', function(assert) {
const spy = sinon.spy();
this.btn.on('close', spy);
this.btn.handleKeyDown(getMockEscapeEvent());
assert.expect(1);
assert.strictEqual(spy.callCount, 1, 'ESC closed the modal');
});