2017-12-28 21:31:19 +00:00
|
|
|
"use strict";
|
|
|
|
|
|
|
|
const expect = require("chai").expect;
|
2019-11-21 09:11:06 +00:00
|
|
|
const friendlysize = require("../../../../client/js/helpers/friendlysize").default;
|
2017-12-28 21:31:19 +00:00
|
|
|
|
2020-03-21 20:55:36 +00:00
|
|
|
describe("friendlysize helper", function () {
|
|
|
|
it("should render human-readable version", function () {
|
2019-12-16 11:26:10 +00:00
|
|
|
expect(friendlysize(51200)).to.equal("50 KiB");
|
|
|
|
expect(friendlysize(2)).to.equal("2 Bytes");
|
|
|
|
expect(friendlysize(1023)).to.equal("1023 Bytes");
|
|
|
|
expect(friendlysize(1024)).to.equal("1 KiB");
|
|
|
|
expect(friendlysize(Math.pow(1024, 2))).to.equal("1 MiB");
|
|
|
|
expect(friendlysize(Math.pow(1024, 3))).to.equal("1 GiB");
|
|
|
|
expect(friendlysize(Math.pow(1024, 4))).to.equal("1 TiB");
|
|
|
|
expect(friendlysize(Math.pow(1024, 5))).to.equal("1 PiB");
|
2017-12-28 21:31:19 +00:00
|
|
|
});
|
|
|
|
|
2020-03-21 20:55:36 +00:00
|
|
|
it("should round with 1 digit", function () {
|
2019-12-16 11:26:10 +00:00
|
|
|
expect(friendlysize(1234567)).to.equal("1.2 MiB");
|
2017-12-28 21:31:19 +00:00
|
|
|
});
|
|
|
|
|
2020-03-21 20:55:36 +00:00
|
|
|
it("should render special case 0 as 0 Bytes", function () {
|
2017-12-28 21:31:19 +00:00
|
|
|
expect(friendlysize(0)).to.equal("0 Bytes");
|
|
|
|
});
|
2019-12-16 11:26:10 +00:00
|
|
|
|
2020-03-21 20:55:36 +00:00
|
|
|
it("should render max safe integer as petabytes", function () {
|
2019-12-16 11:26:10 +00:00
|
|
|
expect(friendlysize(Number.MAX_SAFE_INTEGER)).to.equal("8 PiB");
|
|
|
|
});
|
2017-12-28 21:31:19 +00:00
|
|
|
});
|