2016-08-03 15:27:03 -04:00
|
|
|
/* eslint-env qunit */
|
2015-05-03 16:12:38 -07:00
|
|
|
import formatTime from '../../../src/js/utils/format-time.js';
|
|
|
|
|
2016-08-03 15:27:03 -04:00
|
|
|
QUnit.module('format-time');
|
2015-08-03 15:19:36 -04:00
|
|
|
|
2016-08-12 13:51:31 -04:00
|
|
|
QUnit.test('should format time as a string', function(assert) {
|
|
|
|
assert.ok(formatTime(1) === '0:01');
|
|
|
|
assert.ok(formatTime(10) === '0:10');
|
|
|
|
assert.ok(formatTime(60) === '1:00');
|
|
|
|
assert.ok(formatTime(600) === '10:00');
|
|
|
|
assert.ok(formatTime(3600) === '1:00:00');
|
|
|
|
assert.ok(formatTime(36000) === '10:00:00');
|
|
|
|
assert.ok(formatTime(360000) === '100:00:00');
|
2015-05-03 16:12:38 -07:00
|
|
|
|
|
|
|
// Using guide should provide extra leading zeros
|
2016-08-12 13:51:31 -04:00
|
|
|
assert.ok(formatTime(1, 1) === '0:01');
|
|
|
|
assert.ok(formatTime(1, 10) === '0:01');
|
|
|
|
assert.ok(formatTime(1, 60) === '0:01');
|
|
|
|
assert.ok(formatTime(1, 600) === '00:01');
|
|
|
|
assert.ok(formatTime(1, 3600) === '0:00:01');
|
2015-05-03 16:12:38 -07:00
|
|
|
// Don't do extra leading zeros for hours
|
2016-08-12 13:51:31 -04:00
|
|
|
assert.ok(formatTime(1, 36000) === '0:00:01');
|
|
|
|
assert.ok(formatTime(1, 360000) === '0:00:01');
|
2015-11-25 16:46:41 -05:00
|
|
|
|
|
|
|
// Do not display negative time
|
2016-08-12 13:51:31 -04:00
|
|
|
assert.ok(formatTime(-1) === '0:00');
|
|
|
|
assert.ok(formatTime(-1, 3600) === '0:00:00');
|
2015-05-03 16:12:38 -07:00
|
|
|
});
|
|
|
|
|
2016-08-12 13:51:31 -04:00
|
|
|
QUnit.test('should format invalid times as dashes', function(assert) {
|
|
|
|
assert.equal(formatTime(Infinity, 90), '-:-');
|
|
|
|
assert.equal(formatTime(NaN), '-:-');
|
|
|
|
assert.equal(formatTime(10, Infinity), '0:00:10');
|
|
|
|
assert.equal(formatTime(90, NaN), '1:30');
|
2015-05-03 16:12:38 -07:00
|
|
|
});
|