2017-10-09 18:20:20 +08:00
|
|
|
/* globals describe, it, beforeEach */
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
const SizeFormatHelpers = require("../lib/SizeFormatHelpers");
|
|
|
|
|
|
|
|
describe("SizeFormatHelpers", () => {
|
|
|
|
describe("formatSize", () => {
|
|
|
|
it("should handle zero size", () => {
|
2018-01-24 20:17:21 +08:00
|
|
|
expect(SizeFormatHelpers.formatSize(0)).toBe("0 bytes");
|
2017-10-09 18:20:20 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
it("should handle bytes", () => {
|
2018-01-24 20:17:21 +08:00
|
|
|
expect(SizeFormatHelpers.formatSize(1000)).toBe("1000 bytes");
|
2017-10-09 18:20:20 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
it("should handle integer kibibytes", () => {
|
2018-01-24 20:17:21 +08:00
|
|
|
expect(SizeFormatHelpers.formatSize(2048)).toBe("2 KiB");
|
2017-10-09 18:20:20 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
it("should handle float kibibytes", () => {
|
2018-01-24 20:17:21 +08:00
|
|
|
expect(SizeFormatHelpers.formatSize(2560)).toBe("2.5 KiB");
|
2017-10-09 18:20:20 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
it("should handle integer mebibytes", () => {
|
2018-01-24 20:17:21 +08:00
|
|
|
expect(SizeFormatHelpers.formatSize(10 * 1024 * 1024)).toBe("10 MiB");
|
2017-10-09 18:20:20 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
it("should handle float mebibytes", () => {
|
2018-01-24 20:17:21 +08:00
|
|
|
expect(SizeFormatHelpers.formatSize(12.5 * 1024 * 1024)).toBe("12.5 MiB");
|
2017-10-09 18:20:20 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
it("should handle integer gibibytes", () => {
|
2018-02-25 18:46:17 +08:00
|
|
|
expect(SizeFormatHelpers.formatSize(3 * 1024 * 1024 * 1024)).toBe(
|
|
|
|
"3 GiB"
|
|
|
|
);
|
2017-10-09 18:20:20 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
it("should handle float gibibytes", () => {
|
2018-02-25 18:46:17 +08:00
|
|
|
expect(SizeFormatHelpers.formatSize(1.2 * 1024 * 1024 * 1024)).toBe(
|
|
|
|
"1.2 GiB"
|
|
|
|
);
|
2017-10-09 18:20:20 +08:00
|
|
|
});
|
2018-03-29 21:28:03 +08:00
|
|
|
|
|
|
|
it("should handle undefined/NaN", () => {
|
2018-04-19 01:54:24 +08:00
|
|
|
expect(SizeFormatHelpers.formatSize(undefined)).toBe("unknown size");
|
|
|
|
expect(SizeFormatHelpers.formatSize(NaN)).toBe("unknown size");
|
2018-03-29 21:28:03 +08:00
|
|
|
});
|
2017-10-09 18:20:20 +08:00
|
|
|
});
|
|
|
|
});
|