Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vjsstandard - Tests - Utils folder #3482

Merged
merged 2 commits into from
Aug 3, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
426 changes: 248 additions & 178 deletions test/unit/utils/dom.test.js

Large diffs are not rendered by default.

13 changes: 7 additions & 6 deletions test/unit/utils/fn.test.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
/* eslint-env qunit */
import * as Fn from '../../../src/js/utils/fn.js';

q.module('fn');
QUnit.module('fn');

test('should add context to a function', function(){
var newContext = { test: 'obj'};
var asdf = function(){
ok(this === newContext);
QUnit.test('should add context to a function', function() {
const newContext = { test: 'obj'};
const asdf = function() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these are great function names...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

haha

QUnit.ok(this === newContext);
};
var fdsa = Fn.bind(newContext, asdf);
const fdsa = Fn.bind(newContext, asdf);

fdsa();
});
48 changes: 24 additions & 24 deletions test/unit/utils/format-time.test.js
Original file line number Diff line number Diff line change
@@ -1,35 +1,35 @@
/* eslint-env qunit */
import formatTime from '../../../src/js/utils/format-time.js';

q.module('format-time');
QUnit.module('format-time');

test('should format time as a string', function(){
ok(formatTime(1) === '0:01');
ok(formatTime(10) === '0:10');
ok(formatTime(60) === '1:00');
ok(formatTime(600) === '10:00');
ok(formatTime(3600) === '1:00:00');
ok(formatTime(36000) === '10:00:00');
ok(formatTime(360000) === '100:00:00');
QUnit.test('should format time as a string', function() {
QUnit.ok(formatTime(1) === '0:01');
QUnit.ok(formatTime(10) === '0:10');
QUnit.ok(formatTime(60) === '1:00');
QUnit.ok(formatTime(600) === '10:00');
QUnit.ok(formatTime(3600) === '1:00:00');
QUnit.ok(formatTime(36000) === '10:00:00');
QUnit.ok(formatTime(360000) === '100:00:00');

// Using guide should provide extra leading zeros
ok(formatTime(1,1) === '0:01');
ok(formatTime(1,10) === '0:01');
ok(formatTime(1,60) === '0:01');
ok(formatTime(1,600) === '00:01');
ok(formatTime(1,3600) === '0:00:01');
QUnit.ok(formatTime(1, 1) === '0:01');
QUnit.ok(formatTime(1, 10) === '0:01');
QUnit.ok(formatTime(1, 60) === '0:01');
QUnit.ok(formatTime(1, 600) === '00:01');
QUnit.ok(formatTime(1, 3600) === '0:00:01');
// Don't do extra leading zeros for hours
ok(formatTime(1,36000) === '0:00:01');
ok(formatTime(1,360000) === '0:00:01');
QUnit.ok(formatTime(1, 36000) === '0:00:01');
QUnit.ok(formatTime(1, 360000) === '0:00:01');

// Do not display negative time
ok(formatTime(-1) === '0:00');
ok(formatTime(-1,3600) === '0:00:00');
QUnit.ok(formatTime(-1) === '0:00');
QUnit.ok(formatTime(-1, 3600) === '0:00:00');
});

test('should format invalid times as dashes', function(){
equal(formatTime(Infinity, 90), '-:-');
equal(formatTime(NaN), '-:-');
// equal(formatTime(NaN, 216000), '-:--:--');
equal(formatTime(10, Infinity), '0:00:10');
equal(formatTime(90, NaN), '1:30');
QUnit.test('should format invalid times as dashes', function() {
QUnit.equal(formatTime(Infinity, 90), '-:-');
QUnit.equal(formatTime(NaN), '-:-');
QUnit.equal(formatTime(10, Infinity), '0:00:10');
QUnit.equal(formatTime(90, NaN), '1:30');
});
26 changes: 14 additions & 12 deletions test/unit/utils/log.test.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
/* eslint-env qunit */
import {IE_VERSION} from '../../../src/js/utils/browser';
import log from '../../../src/js/utils/log.js';
import {logByType} from '../../../src/js/utils/log.js';
import window from 'global/window';
import sinon from 'sinon';

q.module('log', {
QUnit.module('log', {

beforeEach() {

Expand Down Expand Up @@ -35,7 +37,7 @@ q.module('log', {
const getConsoleArgs = (...arr) =>
IE_VERSION && IE_VERSION < 11 ? [arr.join(' ')] : arr;

test('logging functions should work', function() {
QUnit.test('logging functions should work', function() {

// Need to reset history here because there are extra messages logged
// when running via Karma.
Expand All @@ -45,28 +47,28 @@ test('logging functions should work', function() {
log.warn('warn1', 'warn2');
log.error('error1', 'error2');

ok(window.console.log.called, 'log was called');
deepEqual(
QUnit.ok(window.console.log.called, 'log was called');
QUnit.deepEqual(
window.console.log.firstCall.args,
getConsoleArgs('VIDEOJS:', 'log1', 'log2')
);

ok(window.console.warn.called, 'warn was called');
deepEqual(
QUnit.ok(window.console.warn.called, 'warn was called');
QUnit.deepEqual(
window.console.warn.firstCall.args,
getConsoleArgs('VIDEOJS:', 'WARN:', 'warn1', 'warn2')
);

ok(window.console.error.called, 'error was called');
deepEqual(
QUnit.ok(window.console.error.called, 'error was called');
QUnit.deepEqual(
window.console.error.firstCall.args,
getConsoleArgs('VIDEOJS:', 'ERROR:', 'error1', 'error2')
);

equal(log.history.length, 3, 'there should be three messages in the log history');
QUnit.equal(log.history.length, 3, 'there should be three messages in the log history');
});

test('in IE pre-11 (or when requested) objects and arrays are stringified', function() {
QUnit.test('in IE pre-11 (or when requested) objects and arrays are stringified', function() {

// Run a custom log call, explicitly requesting object/array stringification.
logByType('log', [
Expand All @@ -78,7 +80,7 @@ test('in IE pre-11 (or when requested) objects and arrays are stringified', func
null
], true);

ok(window.console.log.called, 'log was called');
deepEqual(window.console.log.firstCall.args,
QUnit.ok(window.console.log.called, 'log was called');
QUnit.deepEqual(window.console.log.firstCall.args,
['VIDEOJS: test {"foo":"bar"} [1,2,3] 0 false null']);
});
16 changes: 7 additions & 9 deletions test/unit/utils/merge-options.test.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
/* eslint-env qunit */
import mergeOptions from '../../../src/js/utils/merge-options.js';

q.module('merge-options');

test('should merge options objects', function(){
var ob1, ob2, ob3;

ob1 = {
QUnit.module('merge-options');
QUnit.test('should merge options objects', function() {
const ob1 = {
a: true,
b: { b1: true, b2: true, b3: true },
c: true
};

ob2 = {
const ob2 = {
// override value
a: false,
// merge sub-option values
Expand All @@ -20,9 +18,9 @@ test('should merge options objects', function(){
d: true
};

ob3 = mergeOptions(ob1, ob2);
const ob3 = mergeOptions(ob1, ob2);

deepEqual(ob3, {
QUnit.deepEqual(ob3, {
a: false,
b: { b1: true, b2: false, b3: true, b4: true },
c: true,
Expand Down
49 changes: 32 additions & 17 deletions test/unit/utils/time-ranges.test.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,45 @@
/* eslint-env qunit */
import { createTimeRanges, createTimeRange } from '../../../src/js/utils/time-ranges.js';

q.module('time-ranges');
QUnit.module('time-ranges');

test('should export the deprecated createTimeRange function', function(){
equal(createTimeRange, createTimeRanges, 'createTimeRange is an alias to createTimeRanges');
QUnit.test('should export the deprecated createTimeRange function', function() {
QUnit.equal(createTimeRange,
createTimeRanges,
'createTimeRange is an alias to createTimeRanges');
});

test('should create a fake single timerange', function(assert){
var tr = createTimeRanges(0, 10);
QUnit.test('should create a fake single timerange', function(assert) {
const tr = createTimeRanges(0, 10);

equal(tr.length, 1, 'length should be 1');
equal(tr.start(0), 0, 'works if start is called with valid index');
equal(tr.end(0), 10, 'works if end is called with with valid index');
assert.throws(()=>tr.start(1), /Failed to execute 'start'/, 'fails if start is called with an invalid index');
assert.throws(()=>tr.end(1), /Failed to execute 'end'/, 'fails if end is called with with an invalid index');
QUnit.equal(tr.length, 1, 'length should be 1');
QUnit.equal(tr.start(0),
0,
'works if start is called with valid index');
QUnit.equal(tr.end(0),
10,
'works if end is called with with valid index');
assert.throws(()=>tr.start(1),
/Failed to execute 'start'/,
'fails if start is called with an invalid index');
assert.throws(()=>tr.end(1),
/Failed to execute 'end'/,
'fails if end is called with with an invalid index');
});

test('should create a fake multiple timerange', function(assert){
var tr = createTimeRanges([
QUnit.test('should create a fake multiple timerange', function(assert) {
const tr = createTimeRanges([
[0, 10],
[11, 20]
]);

equal(tr.length, 2, 'length should equal 2');
equal(tr.start(1), 11, 'works if start is called with valid index');
equal(tr.end(1), 20, 'works if end is called with with valid index');
assert.throws(()=>tr.start(-1), /Failed to execute 'start'/, 'fails if start is called with an invalid index');
assert.throws(()=>tr.end(-1), /Failed to execute 'end'/, 'fails if end is called with with an invalid index');
QUnit.equal(tr.length, 2, 'length should equal 2');
QUnit.equal(tr.start(1), 11, 'works if start is called with valid index');
QUnit.equal(tr.end(1), 20, 'works if end is called with with valid index');
assert.throws(()=>tr.start(-1),
/Failed to execute 'start'/,
'fails if start is called with an invalid index');
assert.throws(()=>tr.end(-1),
/Failed to execute 'end'/,
'fails if end is called with with an invalid index');
});
10 changes: 6 additions & 4 deletions test/unit/utils/to-title-case.test.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
/* eslint-env qunit */
import toTitleCase from '../../../src/js/utils/to-title-case.js';

q.module('to-title-case');
QUnit.module('to-title-case');

test('should make a string start with an uppercase letter', function(){
var foo = toTitleCase('bar');
ok(foo === 'Bar');
QUnit.test('should make a string start with an uppercase letter', function() {
const foo = toTitleCase('bar');

QUnit.ok(foo === 'Bar');
});
Loading