github.com/anth0d/nomad@v0.0.0-20221214183521-ae3a0a2cad06/ui/tests/unit/utils/format-duration-test.js (about) 1 import { module, test } from 'qunit'; 2 import formatDuration from 'nomad-ui/utils/format-duration'; 3 4 module('Unit | Util | formatDuration', function () { 5 test('When all units have values, all units are displayed', function (assert) { 6 const expectation = 7 '39 years 1 month 13 days 23h 31m 30s 987ms 654µs 400ns'; 8 assert.equal(formatDuration(1234567890987654321), expectation, expectation); 9 }); 10 11 test('Any unit without values gets dropped from the display', function (assert) { 12 const expectation = '14 days 6h 56m 890ms 980µs'; 13 assert.equal(formatDuration(1234560890980000), expectation, expectation); 14 }); 15 16 test('The units option allows for units coarser than nanoseconds', function (assert) { 17 const expectation1 = '1s 200ms'; 18 const expectation2 = '20m'; 19 const expectation3 = '1 month 1 day'; 20 assert.equal(formatDuration(1200, 'ms'), expectation1, expectation1); 21 assert.equal(formatDuration(1200, 's'), expectation2, expectation2); 22 assert.equal(formatDuration(32, 'd'), expectation3, expectation3); 23 }); 24 25 test('When duration is 0, 0 is shown in terms of the units provided to the function', function (assert) { 26 assert.equal(formatDuration(0), '0ns', 'formatDuration(0) -> 0ns'); 27 assert.equal( 28 formatDuration(0, 'year'), 29 '0 years', 30 'formatDuration(0, "year") -> 0 years' 31 ); 32 }); 33 34 test('The longForm option expands suffixes to words', function (assert) { 35 const expectation1 = '3 seconds 20ms'; 36 const expectation2 = '5 hours 59 minutes'; 37 assert.equal(formatDuration(3020, 'ms', true), expectation1, expectation1); 38 assert.equal( 39 formatDuration(60 * 5 + 59, 'm', true), 40 expectation2, 41 expectation2 42 ); 43 }); 44 });