github.com/aminovpavel/nomad@v0.11.8/ui/tests/unit/helpers/format-bytes-test.js (about) 1 import { module, test } from 'qunit'; 2 import { formatBytes } from 'nomad-ui/helpers/format-bytes'; 3 4 module('Unit | Helper | format-bytes', function() { 5 test('formats null/undefined as 0 bytes', function(assert) { 6 assert.equal(formatBytes([undefined]), '0 Bytes'); 7 assert.equal(formatBytes([null]), '0 Bytes'); 8 }); 9 10 test('formats x < 1024 as bytes', function(assert) { 11 assert.equal(formatBytes([0]), '0 Bytes'); 12 assert.equal(formatBytes([100]), '100 Bytes'); 13 assert.equal(formatBytes([1023]), '1023 Bytes'); 14 }); 15 16 test('formats 1024 <= x < 1024 * 1024 as KiB', function(assert) { 17 assert.equal(formatBytes([1024]), '1 KiB'); 18 assert.equal(formatBytes([125952]), '123 KiB'); 19 assert.equal(formatBytes([1024 * 1024 - 1]), '1023 KiB'); 20 }); 21 22 test('formats 1024 * 1024 <= x < 1024 * 1024 * 1024 as MiB', function(assert) { 23 assert.equal(formatBytes([1024 * 1024]), '1 MiB'); 24 assert.equal(formatBytes([128974848]), '123 MiB'); 25 }); 26 27 test('formats x > 1024 * 1024 * 1024 as MiB, since it is the highest allowed unit', function(assert) { 28 assert.equal(formatBytes([1024 * 1024 * 1024]), '1024 MiB'); 29 assert.equal(formatBytes([1024 * 1024 * 1024 * 4]), '4096 MiB'); 30 }); 31 });