UNPKG

@netdata/charts

Version:

Netdata frontend SDK and chart utilities

164 lines 4.58 kB
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); } import { makeTestChart } from "@jest/testUtilities"; describe("makeGetUnitSign", function () { var chart; beforeEach(function () { chart = makeTestChart().chart; }); var setUnitAttributes = function setUnitAttributes(attrs) { var key = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "units"; return chart.updateAttribute("".concat(key, "ByDimension"), { test: attrs }); }; it("creates getUnitSign function on chart", function () { expect(_typeof(chart.getUnitSign)).toBe("function"); }); it("returns unit string with conversion", function () { setUnitAttributes({ base: "bytes", prefix: "K", unit: "bytes" }); var result = chart.getUnitSign({ dimensionId: "test" }); expect(_typeof(result)).toBe("string"); }); it("uses custom key parameter", function () { setUnitAttributes({ base: "By", prefix: "Mi", unit: "KiBy" }, "customUnits"); var result = chart.getUnitSign({ dimensionId: "test", key: "customUnits" }); expect(result).toBe("MiB"); }); it("returns normalized unit name without conversion when requested", function () { setUnitAttributes({ base: "By", prefix: "M", unit: "KiBy" }); var result = chart.getUnitSign({ dimensionId: "test", withoutConversion: true }); expect(result).toBe("bytes"); }); it("keeps the denominator when normalizing pre-scaled source units", function () { setUnitAttributes({ base: "s/{request}", prefix: "u", unit: "ms/{request}" }); var result = chart.getUnitSign({ dimensionId: "test", withoutConversion: true }); expect(result).toBe("seconds per request"); }); it("uses compact denominators for compound unit labels", function () { setUnitAttributes({ base: "By/{operation}", prefix: "Mi", unit: "KiBy/{operation}" }); var result = chart.getUnitSign({ dimensionId: "test" }); expect(result).toBe("MiB/op"); }); it("uses compact denominators for latency per request labels", function () { setUnitAttributes({ base: "s/{request}", prefix: "u", unit: "ms/{request}" }); var result = chart.getUnitSign({ dimensionId: "test" }); expect(result).toBe("µs/req"); }); it("labels whole CPU-core scale as cores", function () { setUnitAttributes({ base: "[CPU]", prefix: "", unit: "m[CPU]" }); var result = chart.getUnitSign({ dimensionId: "test" }); expect(result).toBe("core"); }); it("keeps milliCPU for sub-core scale", function () { setUnitAttributes({ base: "[CPU]", prefix: "m", unit: "m[CPU]" }); var result = chart.getUnitSign({ dimensionId: "test" }); expect(result).toBe("mCPU"); }); it("does not normalize non-scalable special units", function () { setUnitAttributes({ base: "dB[mW]", prefix: "", unit: "dB[mW]" }); var result = chart.getUnitSign({ dimensionId: "test", withoutConversion: true }); expect(result).toBe("decibel milliwatts"); }); it("normalizes source duration units to seconds", function () { setUnitAttributes({ base: "d:h:mm", prefix: "", unit: "h" }); var result = chart.getUnitSign({ dimensionId: "test", withoutConversion: true }); expect(result).toBe("seconds"); }); it("handles long format", function () { setUnitAttributes({ base: "bytes", prefix: "K", unit: "bytes" }); var result = chart.getUnitSign({ dimensionId: "test", "long": true }); expect(_typeof(result)).toBe("string"); }); it("uses default parameters", function () { setUnitAttributes({ base: "bytes", prefix: "K", unit: "bytes" }); var result = chart.getUnitSign(); expect(_typeof(result)).toBe("string"); }); it("handles missing base unit", function () { setUnitAttributes({ base: null, prefix: "", unit: "percent" }); var result = chart.getUnitSign({ dimensionId: "test" }); expect(_typeof(result)).toBe("string"); }); });