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