1
0
mirror of https://github.com/videojs/video.js.git synced 2025-07-13 01:30:17 +02:00

@misteroneill updated tests to qunit 2.0. closes #3509

This commit is contained in:
Pat O'Neill
2016-08-12 13:51:31 -04:00
committed by Gary Katsevman
parent b3e4e95f9c
commit 72c44daaf3
45 changed files with 1701 additions and 1700 deletions

View File

@ -23,10 +23,10 @@ Component.registerComponent('TestComponent3', TestComponent3);
Component.registerComponent('TestComponent4', TestComponent4);
QUnit.module('Component', {
setup() {
beforeEach() {
this.clock = sinon.useFakeTimers();
},
teardown() {
afterEach() {
this.clock.restore();
}
});
@ -41,76 +41,76 @@ const getFakePlayer = function() {
};
};
QUnit.test('should create an element', function() {
QUnit.test('should create an element', function(assert) {
const comp = new Component(getFakePlayer(), {});
QUnit.ok(comp.el().nodeName);
assert.ok(comp.el().nodeName);
});
QUnit.test('should add a child component', function() {
QUnit.test('should add a child component', function(assert) {
const comp = new Component(getFakePlayer());
const child = comp.addChild('component');
QUnit.ok(comp.children().length === 1);
QUnit.ok(comp.children()[0] === child);
QUnit.ok(comp.el().childNodes[0] === child.el());
QUnit.ok(comp.getChild('component') === child);
QUnit.ok(comp.getChildById(child.id()) === child);
assert.ok(comp.children().length === 1);
assert.ok(comp.children()[0] === child);
assert.ok(comp.el().childNodes[0] === child.el());
assert.ok(comp.getChild('component') === child);
assert.ok(comp.getChildById(child.id()) === child);
});
QUnit.test('should add a child component to an index', function() {
QUnit.test('should add a child component to an index', function(assert) {
const comp = new Component(getFakePlayer());
const child = comp.addChild('component');
QUnit.ok(comp.children().length === 1);
QUnit.ok(comp.children()[0] === child);
assert.ok(comp.children().length === 1);
assert.ok(comp.children()[0] === child);
const child0 = comp.addChild('component', {}, 0);
QUnit.ok(comp.children().length === 2);
QUnit.ok(comp.children()[0] === child0);
QUnit.ok(comp.children()[1] === child);
assert.ok(comp.children().length === 2);
assert.ok(comp.children()[0] === child0);
assert.ok(comp.children()[1] === child);
const child1 = comp.addChild('component', {}, '2');
QUnit.ok(comp.children().length === 3);
QUnit.ok(comp.children()[2] === child1);
assert.ok(comp.children().length === 3);
assert.ok(comp.children()[2] === child1);
const child2 = comp.addChild('component', {}, undefined);
QUnit.ok(comp.children().length === 4);
QUnit.ok(comp.children()[3] === child2);
assert.ok(comp.children().length === 4);
assert.ok(comp.children()[3] === child2);
const child3 = comp.addChild('component', {}, -1);
QUnit.ok(comp.children().length === 5);
QUnit.ok(comp.children()[3] === child3);
QUnit.ok(comp.children()[4] === child2);
assert.ok(comp.children().length === 5);
assert.ok(comp.children()[3] === child3);
assert.ok(comp.children()[4] === child2);
});
QUnit.test('addChild should throw if the child does not exist', function() {
QUnit.test('addChild should throw if the child does not exist', function(assert) {
const comp = new Component(getFakePlayer());
throws(function() {
assert.throws(function() {
comp.addChild('non-existent-child');
}, new Error('Component Non-existent-child does not exist'), 'addChild threw');
});
QUnit.test('should init child components from options', function() {
QUnit.test('should init child components from options', function(assert) {
const comp = new Component(getFakePlayer(), {
children: {
component: {}
}
});
QUnit.ok(comp.children().length === 1);
QUnit.ok(comp.el().childNodes.length === 1);
assert.ok(comp.children().length === 1);
assert.ok(comp.el().childNodes.length === 1);
});
QUnit.test('should init child components from simple children array', function() {
QUnit.test('should init child components from simple children array', function(assert) {
const comp = new Component(getFakePlayer(), {
children: [
'component',
@ -119,11 +119,11 @@ QUnit.test('should init child components from simple children array', function()
]
});
QUnit.ok(comp.children().length === 3);
QUnit.ok(comp.el().childNodes.length === 3);
assert.ok(comp.children().length === 3);
assert.ok(comp.el().childNodes.length === 3);
});
QUnit.test('should init child components from children array of objects', function() {
QUnit.test('should init child components from children array of objects', function(assert) {
const comp = new Component(getFakePlayer(), {
children: [
{ name: 'component' },
@ -132,11 +132,11 @@ QUnit.test('should init child components from children array of objects', functi
]
});
QUnit.ok(comp.children().length === 3);
QUnit.ok(comp.el().childNodes.length === 3);
assert.ok(comp.children().length === 3);
assert.ok(comp.el().childNodes.length === 3);
});
QUnit.test('should do a deep merge of child options', function() {
QUnit.test('should do a deep merge of child options', function(assert) {
// Create a default option for component
Component.prototype.options_ = {
example: {
@ -157,31 +157,32 @@ QUnit.test('should do a deep merge of child options', function() {
const mergedOptions = comp.options_;
const children = mergedOptions.example;
QUnit.strictEqual(children.childOne.foo, 'baz', 'value three levels deep overridden');
QUnit.strictEqual(children.childOne.asdf, 'fdsa', 'value three levels deep maintained');
QUnit.strictEqual(children.childOne.abc, '123', 'value three levels deep added');
QUnit.ok(children.childTwo, 'object two levels deep maintained');
QUnit.strictEqual(children.childThree, false, 'object two levels deep removed');
QUnit.ok(children.childFour, 'object two levels deep added');
assert.strictEqual(children.childOne.foo, 'baz', 'value three levels deep overridden');
assert.strictEqual(children.childOne.asdf, 'fdsa', 'value three levels deep maintained');
assert.strictEqual(children.childOne.abc, '123', 'value three levels deep added');
assert.ok(children.childTwo, 'object two levels deep maintained');
assert.strictEqual(children.childThree, false, 'object two levels deep removed');
assert.ok(children.childFour, 'object two levels deep added');
QUnit.strictEqual(Component.prototype.options_.example.childOne.foo, 'bar',
'prototype options were not overridden');
assert.strictEqual(Component.prototype.options_.example.childOne.foo,
'bar',
'prototype options were not overridden');
// Reset default component options to none
Component.prototype.options_ = null;
});
QUnit.test('should init child components from component options', function() {
QUnit.test('should init child components from component options', function(assert) {
const testComp = new TestComponent1(TestHelpers.makePlayer(), {
testComponent2: false,
testComponent4: {}
});
QUnit.ok(!testComp.childNameIndex_.testComponent2, 'we do not have testComponent2');
QUnit.ok(testComp.childNameIndex_.testComponent4, 'we have a testComponent4');
assert.ok(!testComp.childNameIndex_.testComponent2, 'we do not have testComponent2');
assert.ok(testComp.childNameIndex_.testComponent4, 'we have a testComponent4');
});
QUnit.test('should allows setting child options at the parent options level', function() {
QUnit.test('should allows setting child options at the parent options level', function(assert) {
let parent;
// using children array
@ -200,10 +201,10 @@ QUnit.test('should allows setting child options at the parent options level', fu
try {
parent = new Component(getFakePlayer(), options);
} catch (err) {
QUnit.ok(false, 'Child with `false` option was initialized');
assert.ok(false, 'Child with `false` option was initialized');
}
QUnit.equal(parent.children()[0].options_.foo, true, 'child options set when children array is used');
QUnit.equal(parent.children().length, 1, 'we should only have one child');
assert.equal(parent.children()[0].options_.foo, true, 'child options set when children array is used');
assert.equal(parent.children().length, 1, 'we should only have one child');
// using children object
options = {
@ -223,19 +224,19 @@ QUnit.test('should allows setting child options at the parent options level', fu
try {
parent = new Component(getFakePlayer(), options);
} catch (err) {
QUnit.ok(false, 'Child with `false` option was initialized');
assert.ok(false, 'Child with `false` option was initialized');
}
QUnit.equal(parent.children()[0].options_.foo, true, 'child options set when children object is used');
QUnit.equal(parent.children().length, 1, 'we should only have one child');
assert.equal(parent.children()[0].options_.foo, true, 'child options set when children object is used');
assert.equal(parent.children().length, 1, 'we should only have one child');
});
QUnit.test('should dispose of component and children', function() {
QUnit.test('should dispose of component and children', function(assert) {
const comp = new Component(getFakePlayer());
// Add a child
const child = comp.addChild('Component');
QUnit.ok(comp.children().length === 1);
assert.ok(comp.children().length === 1);
// Add a listener
comp.on('click', function() {
@ -254,28 +255,28 @@ QUnit.test('should dispose of component and children', function() {
comp.dispose();
QUnit.ok(hasDisposed, 'component fired dispose event');
QUnit.ok(bubbles === false, 'dispose event does not bubble');
QUnit.ok(!comp.children(), 'component children were deleted');
QUnit.ok(!comp.el(), 'component element was deleted');
QUnit.ok(!child.children(), 'child children were deleted');
QUnit.ok(!child.el(), 'child element was deleted');
QUnit.ok(!Dom.hasElData(el), 'listener data nulled');
QUnit.ok(!Object.getOwnPropertyNames(data).length,
assert.ok(hasDisposed, 'component fired dispose event');
assert.ok(bubbles === false, 'dispose event does not bubble');
assert.ok(!comp.children(), 'component children were deleted');
assert.ok(!comp.el(), 'component element was deleted');
assert.ok(!child.children(), 'child children were deleted');
assert.ok(!child.el(), 'child element was deleted');
assert.ok(!Dom.hasElData(el), 'listener data nulled');
assert.ok(!Object.getOwnPropertyNames(data).length,
'original listener data object was emptied');
});
QUnit.test('should add and remove event listeners to element', function() {
QUnit.test('should add and remove event listeners to element', function(assert) {
const comp = new Component(getFakePlayer(), {});
// No need to make this async because we're triggering events inline.
// We're going to trigger the event after removing the listener,
// So if we get extra asserts that's a problem.
QUnit.expect(2);
assert.expect(2);
const testListener = function() {
QUnit.ok(true, 'fired event once');
QUnit.ok(this === comp, 'listener has the component as context');
assert.ok(true, 'fired event once');
assert.ok(this === comp, 'listener has the component as context');
};
comp.on('test-event', testListener);
@ -284,13 +285,13 @@ QUnit.test('should add and remove event listeners to element', function() {
comp.trigger('test-event');
});
QUnit.test('should trigger a listener once using one()', function() {
QUnit.test('should trigger a listener once using one()', function(assert) {
const comp = new Component(getFakePlayer(), {});
QUnit.expect(1);
assert.expect(1);
const testListener = function() {
QUnit.ok(true, 'fired event once');
assert.ok(true, 'fired event once');
};
comp.one('test-event', testListener);
@ -298,17 +299,17 @@ QUnit.test('should trigger a listener once using one()', function() {
comp.trigger('test-event');
});
QUnit.test('should be possible to pass data when you trigger an event', function() {
QUnit.test('should be possible to pass data when you trigger an event', function(assert) {
const comp = new Component(getFakePlayer(), {});
const data1 = 'Data1';
const data2 = {txt: 'Data2'};
QUnit.expect(3);
assert.expect(3);
const testListener = function(evt, hash) {
QUnit.ok(true, 'fired event once');
deepEqual(hash.d1, data1);
deepEqual(hash.d2, data2);
assert.ok(true, 'fired event once');
assert.deepEqual(hash.d1, data1);
assert.deepEqual(hash.d2, data2);
};
comp.one('test-event', testListener);
@ -316,47 +317,47 @@ QUnit.test('should be possible to pass data when you trigger an event', function
comp.trigger('test-event');
});
QUnit.test('should add listeners to other components and remove them', function() {
QUnit.test('should add listeners to other components and remove them', function(assert) {
const player = getFakePlayer();
const comp1 = new Component(player);
const comp2 = new Component(player);
let listenerFired = 0;
const testListener = function() {
QUnit.equal(this, comp1, 'listener has the first component as context');
assert.equal(this, comp1, 'listener has the first component as context');
listenerFired++;
};
comp1.on(comp2, 'test-event', testListener);
comp2.trigger('test-event');
QUnit.equal(listenerFired, 1, 'listener was fired once');
assert.equal(listenerFired, 1, 'listener was fired once');
listenerFired = 0;
comp1.off(comp2, 'test-event', testListener);
comp2.trigger('test-event');
QUnit.equal(listenerFired, 0, 'listener was not fired after being removed');
assert.equal(listenerFired, 0, 'listener was not fired after being removed');
// this component is disposed first
listenerFired = 0;
comp1.on(comp2, 'test-event', testListener);
comp1.dispose();
comp2.trigger('test-event');
QUnit.equal(listenerFired, 0, 'listener was removed when this component was disposed first');
assert.equal(listenerFired, 0, 'listener was removed when this component was disposed first');
comp1.off = function() {
throw new Error('Comp1 off called');
};
comp2.dispose();
QUnit.ok(true, 'this component removed dispose listeners from other component');
assert.ok(true, 'this component removed dispose listeners from other component');
});
QUnit.test('should add listeners to other components and remove when them other component is disposed', function() {
QUnit.test('should add listeners to other components and remove when them other component is disposed', function(assert) {
const player = getFakePlayer();
const comp1 = new Component(player);
const comp2 = new Component(player);
let listenerFired = 0;
const testListener = function() {
QUnit.equal(this, comp1, 'listener has the first component as context');
assert.equal(this, comp1, 'listener has the first component as context');
listenerFired++;
};
@ -366,53 +367,53 @@ QUnit.test('should add listeners to other components and remove when them other
throw new Error('Comp2 off called');
};
comp1.dispose();
QUnit.ok(true, 'this component removed dispose listener from this component that referenced other component');
assert.ok(true, 'this component removed dispose listener from this component that referenced other component');
});
QUnit.test('should add listeners to other components that are fired once', function() {
QUnit.test('should add listeners to other components that are fired once', function(assert) {
const player = getFakePlayer();
const comp1 = new Component(player);
const comp2 = new Component(player);
let listenerFired = 0;
const testListener = function() {
QUnit.equal(this, comp1, 'listener has the first component as context');
assert.equal(this, comp1, 'listener has the first component as context');
listenerFired++;
};
comp1.one(comp2, 'test-event', testListener);
comp2.trigger('test-event');
QUnit.equal(listenerFired, 1, 'listener was executed once');
assert.equal(listenerFired, 1, 'listener was executed once');
comp2.trigger('test-event');
QUnit.equal(listenerFired, 1, 'listener was executed only once');
assert.equal(listenerFired, 1, 'listener was executed only once');
});
QUnit.test('should add listeners to other element and remove them', function() {
QUnit.test('should add listeners to other element and remove them', function(assert) {
const player = getFakePlayer();
const comp1 = new Component(player);
const el = document.createElement('div');
let listenerFired = 0;
const testListener = function() {
QUnit.equal(this, comp1, 'listener has the first component as context');
assert.equal(this, comp1, 'listener has the first component as context');
listenerFired++;
};
comp1.on(el, 'test-event', testListener);
Events.trigger(el, 'test-event');
QUnit.equal(listenerFired, 1, 'listener was fired once');
assert.equal(listenerFired, 1, 'listener was fired once');
listenerFired = 0;
comp1.off(el, 'test-event', testListener);
Events.trigger(el, 'test-event');
QUnit.equal(listenerFired, 0, 'listener was not fired after being removed from other element');
assert.equal(listenerFired, 0, 'listener was not fired after being removed from other element');
// this component is disposed first
listenerFired = 0;
comp1.on(el, 'test-event', testListener);
comp1.dispose();
Events.trigger(el, 'test-event');
QUnit.equal(listenerFired, 0, 'listener was removed when this component was disposed first');
assert.equal(listenerFired, 0, 'listener was removed when this component was disposed first');
comp1.off = function() {
throw new Error('Comp1 off called');
};
@ -420,31 +421,31 @@ QUnit.test('should add listeners to other element and remove them', function() {
try {
Events.trigger(el, 'dispose');
} catch (e) {
QUnit.ok(false, 'listener was not removed from other element');
assert.ok(false, 'listener was not removed from other element');
}
Events.trigger(el, 'dispose');
QUnit.ok(true, 'this component removed dispose listeners from other element');
assert.ok(true, 'this component removed dispose listeners from other element');
});
QUnit.test('should add listeners to other components that are fired once', function() {
QUnit.test('should add listeners to other components that are fired once', function(assert) {
const player = getFakePlayer();
const comp1 = new Component(player);
const el = document.createElement('div');
let listenerFired = 0;
const testListener = function() {
QUnit.equal(this, comp1, 'listener has the first component as context');
assert.equal(this, comp1, 'listener has the first component as context');
listenerFired++;
};
comp1.one(el, 'test-event', testListener);
Events.trigger(el, 'test-event');
QUnit.equal(listenerFired, 1, 'listener was executed once');
assert.equal(listenerFired, 1, 'listener was executed once');
Events.trigger(el, 'test-event');
QUnit.equal(listenerFired, 1, 'listener was executed only once');
assert.equal(listenerFired, 1, 'listener was executed only once');
});
QUnit.test('should trigger a listener when ready', function() {
QUnit.test('should trigger a listener when ready', function(assert) {
let initListenerFired;
let methodListenerFired;
let syncListenerFired;
@ -463,13 +464,13 @@ QUnit.test('should trigger a listener when ready', function() {
syncListenerFired = true;
}, true);
QUnit.ok(!initListenerFired, 'init listener should NOT fire synchronously');
QUnit.ok(!methodListenerFired, 'method listener should NOT fire synchronously');
QUnit.ok(syncListenerFired, 'sync listener SHOULD fire synchronously if after ready');
assert.ok(!initListenerFired, 'init listener should NOT fire synchronously');
assert.ok(!methodListenerFired, 'method listener should NOT fire synchronously');
assert.ok(syncListenerFired, 'sync listener SHOULD fire synchronously if after ready');
this.clock.tick(1);
QUnit.ok(initListenerFired, 'init listener should fire asynchronously');
QUnit.ok(methodListenerFired, 'method listener should fire asynchronously');
assert.ok(initListenerFired, 'init listener should fire asynchronously');
assert.ok(methodListenerFired, 'method listener should fire asynchronously');
// Listeners should only be fired once and then removed
initListenerFired = false;
@ -479,12 +480,12 @@ QUnit.test('should trigger a listener when ready', function() {
comp.triggerReady();
this.clock.tick(1);
QUnit.ok(!initListenerFired, 'init listener should be removed');
QUnit.ok(!methodListenerFired, 'method listener should be removed');
QUnit.ok(!syncListenerFired, 'sync listener should be removed');
assert.ok(!initListenerFired, 'init listener should be removed');
assert.ok(!methodListenerFired, 'method listener should be removed');
assert.ok(!syncListenerFired, 'sync listener should be removed');
});
QUnit.test('should not retrigger a listener when the listener calls triggerReady', function() {
QUnit.test('should not retrigger a listener when the listener calls triggerReady', function(assert) {
let timesCalled = 0;
let selfTriggered = false;
const comp = new Component(getFakePlayer(), {});
@ -505,32 +506,32 @@ QUnit.test('should not retrigger a listener when the listener calls triggerReady
this.clock.tick(100);
QUnit.equal(timesCalled, 1, 'triggerReady from inside a ready handler does not result in an infinite loop');
assert.equal(timesCalled, 1, 'triggerReady from inside a ready handler does not result in an infinite loop');
});
QUnit.test('should add and remove a CSS class', function() {
QUnit.test('should add and remove a CSS class', function(assert) {
const comp = new Component(getFakePlayer(), {});
comp.addClass('test-class');
QUnit.ok(comp.el().className.indexOf('test-class') !== -1);
assert.ok(comp.el().className.indexOf('test-class') !== -1);
comp.removeClass('test-class');
QUnit.ok(comp.el().className.indexOf('test-class') === -1);
assert.ok(comp.el().className.indexOf('test-class') === -1);
comp.toggleClass('test-class');
QUnit.ok(comp.el().className.indexOf('test-class') !== -1);
assert.ok(comp.el().className.indexOf('test-class') !== -1);
comp.toggleClass('test-class');
QUnit.ok(comp.el().className.indexOf('test-class') === -1);
assert.ok(comp.el().className.indexOf('test-class') === -1);
});
QUnit.test('should show and hide an element', function() {
QUnit.test('should show and hide an element', function(assert) {
const comp = new Component(getFakePlayer(), {});
comp.hide();
QUnit.ok(comp.hasClass('vjs-hidden') === true);
assert.ok(comp.hasClass('vjs-hidden') === true);
comp.show();
QUnit.ok(comp.hasClass('vjs-hidden') === false);
assert.ok(comp.hasClass('vjs-hidden') === false);
});
QUnit.test('dimension() should treat NaN and null as zero', function() {
QUnit.test('dimension() should treat NaN and null as zero', function(assert) {
let newWidth;
const width = 300;
@ -543,23 +544,23 @@ QUnit.test('dimension() should treat NaN and null as zero', function() {
newWidth = comp.dimension('width', null);
QUnit.notEqual(newWidth, width, 'new width and old width are not the same');
QUnit.equal(newWidth, comp, 'we set a value, so, return value is component');
QUnit.equal(comp.width(), 0, 'the new width is zero');
assert.notEqual(newWidth, width, 'new width and old width are not the same');
assert.equal(newWidth, comp, 'we set a value, so, return value is component');
assert.equal(comp.width(), 0, 'the new width is zero');
const newHeight = comp.dimension('height', NaN);
QUnit.notEqual(newHeight, height, 'new height and old height are not the same');
QUnit.equal(newHeight, comp, 'we set a value, so, return value is component');
QUnit.equal(comp.height(), 0, 'the new height is zero');
assert.notEqual(newHeight, height, 'new height and old height are not the same');
assert.equal(newHeight, comp, 'we set a value, so, return value is component');
assert.equal(comp.height(), 0, 'the new height is zero');
comp.width(width);
newWidth = comp.dimension('width', undefined);
QUnit.equal(newWidth, width, 'we did not set the width with undefined');
assert.equal(newWidth, width, 'we did not set the width with undefined');
});
QUnit.test('should change the width and height of a component', function() {
QUnit.test('should change the width and height of a component', function(assert) {
const container = document.createElement('div');
const comp = new Component(getFakePlayer(), {});
const el = comp.el();
@ -574,22 +575,22 @@ QUnit.test('should change the width and height of a component', function() {
comp.width('50%');
comp.height('123px');
QUnit.ok(comp.width() === 500, 'percent values working');
assert.ok(comp.width() === 500, 'percent values working');
const compStyle = TestHelpers.getComputedStyle(el, 'width');
QUnit.ok(compStyle === comp.width() + 'px', 'matches computed style');
QUnit.ok(comp.height() === 123, 'px values working');
assert.ok(compStyle === comp.width() + 'px', 'matches computed style');
assert.ok(comp.height() === 123, 'px values working');
comp.width(321);
QUnit.ok(comp.width() === 321, 'integer values working');
assert.ok(comp.width() === 321, 'integer values working');
comp.width('auto');
comp.height('auto');
QUnit.ok(comp.width() === 1000, 'forced width was removed');
QUnit.ok(comp.height() === 0, 'forced height was removed');
assert.ok(comp.width() === 1000, 'forced width was removed');
assert.ok(comp.height() === 0, 'forced height was removed');
});
QUnit.test('should get the computed dimensions', function() {
QUnit.test('should get the computed dimensions', function(assert) {
const container = document.createElement('div');
const comp = new Component(getFakePlayer(), {});
const el = comp.el();
@ -607,18 +608,18 @@ QUnit.test('should get the computed dimensions', function() {
comp.width('50%');
comp.height('50%');
QUnit.equal(comp.currentWidth() + 'px', computedWidth, 'matches computed width');
QUnit.equal(comp.currentHeight() + 'px', computedHeight, 'matches computed height');
assert.equal(comp.currentWidth() + 'px', computedWidth, 'matches computed width');
assert.equal(comp.currentHeight() + 'px', computedHeight, 'matches computed height');
QUnit.equal(comp.currentDimension('width') + 'px', computedWidth, 'matches computed width');
QUnit.equal(comp.currentDimension('height') + 'px', computedHeight, 'matches computed height');
assert.equal(comp.currentDimension('width') + 'px', computedWidth, 'matches computed width');
assert.equal(comp.currentDimension('height') + 'px', computedHeight, 'matches computed height');
QUnit.equal(comp.currentDimensions().width + 'px', computedWidth, 'matches computed width');
QUnit.equal(comp.currentDimensions().height + 'px', computedHeight, 'matches computed width');
assert.equal(comp.currentDimensions().width + 'px', computedWidth, 'matches computed width');
assert.equal(comp.currentDimensions().height + 'px', computedHeight, 'matches computed width');
});
QUnit.test('should use a defined content el for appending children', function() {
QUnit.test('should use a defined content el for appending children', function(assert) {
class CompWithContent extends Component {}
CompWithContent.prototype.createEl = function() {
@ -634,30 +635,30 @@ QUnit.test('should use a defined content el for appending children', function()
const comp = new CompWithContent(getFakePlayer());
const child = comp.addChild('component');
QUnit.ok(comp.children().length === 1);
QUnit.ok(comp.el().childNodes[0].id === 'contentEl');
QUnit.ok(comp.el().childNodes[0].childNodes[0] === child.el());
assert.ok(comp.children().length === 1);
assert.ok(comp.el().childNodes[0].id === 'contentEl');
assert.ok(comp.el().childNodes[0].childNodes[0] === child.el());
comp.removeChild(child);
QUnit.ok(comp.children().length === 0, 'Length should now be zero');
QUnit.ok(comp.el().childNodes[0].id === 'contentEl', 'Content El should still exist');
QUnit.ok(comp.el().childNodes[0].childNodes[0] !== child.el(),
assert.ok(comp.children().length === 0, 'Length should now be zero');
assert.ok(comp.el().childNodes[0].id === 'contentEl', 'Content El should still exist');
assert.ok(comp.el().childNodes[0].childNodes[0] !== child.el(),
'Child el should be removed.');
});
QUnit.test('should emit a tap event', function() {
QUnit.test('should emit a tap event', function(assert) {
const comp = new Component(getFakePlayer());
let singleTouch = {};
const origTouch = browser.TOUCH_ENABLED;
QUnit.expect(3);
assert.expect(3);
// Fake touch support. Real touch support isn't needed for this test.
browser.TOUCH_ENABLED = true;
comp.emitTapEvents();
comp.on('tap', function() {
QUnit.ok(true, 'Tap event emitted');
assert.ok(true, 'Tap event emitted');
});
// A touchstart followed by touchend should trigger a tap
@ -704,30 +705,30 @@ QUnit.test('should emit a tap event', function() {
browser.TOUCH_ENABLED = origTouch;
});
QUnit.test('should provide timeout methods that automatically get cleared on component disposal', function() {
QUnit.test('should provide timeout methods that automatically get cleared on component disposal', function(assert) {
const comp = new Component(getFakePlayer());
let timeoutsFired = 0;
const timeoutToClear = comp.setTimeout(function() {
timeoutsFired++;
QUnit.ok(false, 'Timeout should have been manually cleared');
assert.ok(false, 'Timeout should have been manually cleared');
}, 500);
QUnit.expect(4);
assert.expect(4);
comp.setTimeout(function() {
timeoutsFired++;
QUnit.equal(this, comp, 'Timeout fn has the component as its context');
QUnit.ok(true, 'Timeout created and fired.');
assert.equal(this, comp, 'Timeout fn has the component as its context');
assert.ok(true, 'Timeout created and fired.');
}, 100);
comp.setTimeout(function() {
timeoutsFired++;
QUnit.ok(false, 'Timeout should have been disposed');
assert.ok(false, 'Timeout should have been disposed');
}, 1000);
this.clock.tick(100);
QUnit.ok(timeoutsFired === 1, 'One timeout should have fired by this point');
assert.ok(timeoutsFired === 1, 'One timeout should have fired by this point');
comp.clearTimeout(timeoutToClear);
@ -737,45 +738,45 @@ QUnit.test('should provide timeout methods that automatically get cleared on com
this.clock.tick(1000);
QUnit.ok(timeoutsFired === 1, 'One timeout should have fired overall');
assert.ok(timeoutsFired === 1, 'One timeout should have fired overall');
});
QUnit.test('should provide interval methods that automatically get cleared on component disposal', function() {
QUnit.test('should provide interval methods that automatically get cleared on component disposal', function(assert) {
const comp = new Component(getFakePlayer());
let intervalsFired = 0;
const interval = comp.setInterval(function() {
intervalsFired++;
QUnit.equal(this, comp, 'Interval fn has the component as its context');
QUnit.ok(true, 'Interval created and fired.');
assert.equal(this, comp, 'Interval fn has the component as its context');
assert.ok(true, 'Interval created and fired.');
}, 100);
QUnit.expect(13);
assert.expect(13);
comp.setInterval(function() {
intervalsFired++;
QUnit.ok(false, 'Interval should have been disposed');
assert.ok(false, 'Interval should have been disposed');
}, 1200);
this.clock.tick(500);
QUnit.ok(intervalsFired === 5, 'Component interval fired 5 times');
assert.ok(intervalsFired === 5, 'Component interval fired 5 times');
comp.clearInterval(interval);
this.clock.tick(600);
QUnit.ok(intervalsFired === 5, 'Interval was manually cleared');
assert.ok(intervalsFired === 5, 'Interval was manually cleared');
comp.dispose();
this.clock.tick(1200);
QUnit.ok(intervalsFired === 5, 'Interval was cleared when component was disposed');
assert.ok(intervalsFired === 5, 'Interval was cleared when component was disposed');
});
QUnit.test('$ and $$ functions', function() {
QUnit.test('$ and $$ functions', function(assert) {
const comp = new Component(getFakePlayer());
const contentEl = document.createElement('div');
const children = [
@ -786,6 +787,6 @@ QUnit.test('$ and $$ functions', function() {
comp.contentEl_ = contentEl;
children.forEach(child => contentEl.appendChild(child));
QUnit.strictEqual(comp.$('div'), children[0], '$ defaults to contentEl as scope');
QUnit.strictEqual(comp.$$('div').length, children.length, '$$ defaults to contentEl as scope');
assert.strictEqual(comp.$('div'), children[0], '$ defaults to contentEl as scope');
assert.strictEqual(comp.$$('div').length, children.length, '$$ defaults to contentEl as scope');
});