2018-10-10 21:30:20 +02:00
|
|
|
/* eslint-env qunit */
|
|
|
|
import sinon from 'sinon';
|
|
|
|
import TestHelpers from './test-helpers';
|
|
|
|
import {assign} from '../../src/js/utils/obj';
|
|
|
|
|
|
|
|
const getExpectedBreakpoints = (o) => assign({}, {
|
|
|
|
tiny: 210,
|
|
|
|
xsmall: 320,
|
|
|
|
small: 425,
|
|
|
|
medium: 768,
|
|
|
|
large: 1440,
|
|
|
|
xlarge: 2560,
|
|
|
|
huge: Infinity
|
|
|
|
}, o);
|
|
|
|
|
|
|
|
QUnit.module('Player: Breakpoints', {
|
|
|
|
|
|
|
|
beforeEach() {
|
|
|
|
this.clock = sinon.useFakeTimers();
|
|
|
|
this.player = TestHelpers.makePlayer({});
|
|
|
|
},
|
|
|
|
|
|
|
|
afterEach() {
|
|
|
|
this.player.dispose();
|
|
|
|
this.clock.restore();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
QUnit.test('breakpoints are disabled by default', function(assert) {
|
2018-10-11 23:03:33 +02:00
|
|
|
assert.deepEqual(this.player.breakpoints(), getExpectedBreakpoints(), 'default breakpoints defined');
|
|
|
|
assert.notOk(this.player.responsive(), 'player is not responsive');
|
|
|
|
assert.strictEqual(this.player.currentBreakpoint(), '', 'no current breakpoint set');
|
|
|
|
assert.strictEqual(this.player.currentBreakpointClass(), '', 'no current breakpoint set');
|
2018-10-10 21:30:20 +02:00
|
|
|
});
|
|
|
|
|
2018-10-11 23:03:33 +02:00
|
|
|
QUnit.test('enabling responsive mode', function(assert) {
|
|
|
|
this.player.responsive(true);
|
|
|
|
|
|
|
|
assert.ok(this.player.responsive(), 'player is responsive');
|
2018-10-10 21:30:20 +02:00
|
|
|
|
|
|
|
// Player should be 300x150 by default.
|
|
|
|
assert.strictEqual(this.player.currentBreakpoint(), 'xsmall', 'current breakpoint set');
|
2018-10-11 23:03:33 +02:00
|
|
|
assert.strictEqual(this.player.currentBreakpointClass(), 'vjs-layout-x-small', 'current breakpoint set');
|
2018-10-10 21:30:20 +02:00
|
|
|
});
|
|
|
|
|
2018-10-11 23:03:33 +02:00
|
|
|
QUnit.test('setting custom breakpoints and enabling responsive mode', function(assert) {
|
|
|
|
this.player.breakpoints({tiny: 300});
|
|
|
|
this.player.responsive(true);
|
|
|
|
|
|
|
|
assert.deepEqual(this.player.breakpoints(), getExpectedBreakpoints({tiny: 300}), 'breakpoints defined');
|
2018-10-10 21:30:20 +02:00
|
|
|
|
|
|
|
// Player should be 300x150 by default.
|
|
|
|
assert.strictEqual(this.player.currentBreakpoint(), 'tiny', 'current breakpoint set');
|
2018-10-11 23:03:33 +02:00
|
|
|
assert.strictEqual(this.player.currentBreakpointClass(), 'vjs-layout-tiny', 'current breakpoint set');
|
2018-10-10 21:30:20 +02:00
|
|
|
});
|
|
|
|
|
2018-10-11 23:03:33 +02:00
|
|
|
QUnit.test('setting breakpoints/responsive via option', function(assert) {
|
|
|
|
const player = TestHelpers.makePlayer({breakpoints: {tiny: 300}, responsive: true});
|
2018-10-10 21:30:20 +02:00
|
|
|
|
2018-10-11 23:03:33 +02:00
|
|
|
assert.deepEqual(player.breakpoints(), getExpectedBreakpoints({tiny: 300}), 'breakpoints defined');
|
2018-10-10 21:30:20 +02:00
|
|
|
|
|
|
|
// Player should be 300x150 by default.
|
|
|
|
assert.strictEqual(player.currentBreakpoint(), 'tiny', 'current breakpoint set');
|
2018-10-11 23:03:33 +02:00
|
|
|
assert.strictEqual(player.currentBreakpointClass(), 'vjs-layout-tiny', 'current breakpoint set');
|
2019-03-18 21:49:48 +02:00
|
|
|
player.dispose();
|
2018-10-10 21:30:20 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
QUnit.test('changing the player size triggers breakpoints', function(assert) {
|
|
|
|
let currentWidth;
|
|
|
|
|
2018-10-11 23:03:33 +02:00
|
|
|
this.player.responsive(true);
|
2018-10-10 21:30:20 +02:00
|
|
|
this.player.currentWidth = () => currentWidth;
|
|
|
|
|
|
|
|
currentWidth = 200;
|
|
|
|
this.player.trigger('playerresize');
|
|
|
|
assert.strictEqual(this.player.currentBreakpoint(), 'tiny', 'current breakpoint is correct');
|
2018-10-11 23:03:33 +02:00
|
|
|
assert.strictEqual(this.player.currentBreakpointClass(), 'vjs-layout-tiny', 'current breakpoint set');
|
2018-10-10 21:30:20 +02:00
|
|
|
|
|
|
|
currentWidth = 300;
|
|
|
|
this.player.trigger('playerresize');
|
|
|
|
assert.strictEqual(this.player.currentBreakpoint(), 'xsmall', 'current breakpoint is correct');
|
2018-10-11 23:03:33 +02:00
|
|
|
assert.strictEqual(this.player.currentBreakpointClass(), 'vjs-layout-x-small', 'current breakpoint set');
|
2018-10-10 21:30:20 +02:00
|
|
|
|
|
|
|
currentWidth = 400;
|
|
|
|
this.player.trigger('playerresize');
|
|
|
|
assert.strictEqual(this.player.currentBreakpoint(), 'small', 'current breakpoint is correct');
|
2018-10-11 23:03:33 +02:00
|
|
|
assert.strictEqual(this.player.currentBreakpointClass(), 'vjs-layout-small', 'current breakpoint set');
|
2018-10-10 21:30:20 +02:00
|
|
|
|
|
|
|
currentWidth = 600;
|
|
|
|
this.player.trigger('playerresize');
|
|
|
|
assert.strictEqual(this.player.currentBreakpoint(), 'medium', 'current breakpoint is correct');
|
2018-10-11 23:03:33 +02:00
|
|
|
assert.strictEqual(this.player.currentBreakpointClass(), 'vjs-layout-medium', 'current breakpoint set');
|
2018-10-10 21:30:20 +02:00
|
|
|
|
|
|
|
currentWidth = 900;
|
|
|
|
this.player.trigger('playerresize');
|
|
|
|
assert.strictEqual(this.player.currentBreakpoint(), 'large', 'current breakpoint is correct');
|
2018-10-11 23:03:33 +02:00
|
|
|
assert.strictEqual(this.player.currentBreakpointClass(), 'vjs-layout-large', 'current breakpoint set');
|
2018-10-10 21:30:20 +02:00
|
|
|
|
|
|
|
currentWidth = 1600;
|
|
|
|
this.player.trigger('playerresize');
|
|
|
|
assert.strictEqual(this.player.currentBreakpoint(), 'xlarge', 'current breakpoint is correct');
|
2018-10-11 23:03:33 +02:00
|
|
|
assert.strictEqual(this.player.currentBreakpointClass(), 'vjs-layout-x-large', 'current breakpoint set');
|
2018-10-10 21:30:20 +02:00
|
|
|
|
|
|
|
currentWidth = 3000;
|
|
|
|
this.player.trigger('playerresize');
|
|
|
|
assert.strictEqual(this.player.currentBreakpoint(), 'huge', 'current breakpoint is correct');
|
2018-10-11 23:03:33 +02:00
|
|
|
assert.strictEqual(this.player.currentBreakpointClass(), 'vjs-layout-huge', 'current breakpoint set');
|
2018-10-10 21:30:20 +02:00
|
|
|
});
|