2016-08-03 21:27:03 +02:00
|
|
|
/* eslint-env qunit */
|
2015-09-22 00:04:10 +02:00
|
|
|
import { createTimeRanges, createTimeRange } from '../../../src/js/utils/time-ranges.js';
|
2015-05-04 01:12:38 +02:00
|
|
|
|
2016-08-03 21:27:03 +02:00
|
|
|
QUnit.module('time-ranges');
|
2015-08-03 21:19:36 +02:00
|
|
|
|
2016-08-12 19:51:31 +02:00
|
|
|
QUnit.test('should export the deprecated createTimeRange function', function(assert) {
|
|
|
|
assert.equal(createTimeRange,
|
2016-08-03 21:27:03 +02:00
|
|
|
createTimeRanges,
|
|
|
|
'createTimeRange is an alias to createTimeRanges');
|
2015-09-22 00:04:10 +02:00
|
|
|
});
|
|
|
|
|
2016-08-03 21:27:03 +02:00
|
|
|
QUnit.test('should create a fake single timerange', function(assert) {
|
|
|
|
const tr = createTimeRanges(0, 10);
|
2015-09-22 00:04:10 +02:00
|
|
|
|
2016-08-12 19:51:31 +02:00
|
|
|
assert.equal(tr.length, 1, 'length should be 1');
|
|
|
|
assert.equal(tr.start(0),
|
2016-08-03 21:27:03 +02:00
|
|
|
0,
|
|
|
|
'works if start is called with valid index');
|
2016-08-12 19:51:31 +02:00
|
|
|
assert.equal(tr.end(0),
|
2016-08-03 21:27:03 +02:00
|
|
|
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');
|
2015-09-22 00:04:10 +02:00
|
|
|
});
|
|
|
|
|
2016-08-03 21:27:03 +02:00
|
|
|
QUnit.test('should create a fake multiple timerange', function(assert) {
|
|
|
|
const tr = createTimeRanges([
|
2015-09-22 00:04:10 +02:00
|
|
|
[0, 10],
|
|
|
|
[11, 20]
|
|
|
|
]);
|
|
|
|
|
2016-08-12 19:51:31 +02:00
|
|
|
assert.equal(tr.length, 2, 'length should equal 2');
|
|
|
|
assert.equal(tr.start(1), 11, 'works if start is called with valid index');
|
|
|
|
assert.equal(tr.end(1), 20, 'works if end is called with with valid index');
|
2016-08-03 21:27:03 +02:00
|
|
|
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');
|
2015-05-04 01:12:38 +02:00
|
|
|
});
|