@netdata/charts
Version:
Netdata frontend SDK and chart utilities
71 lines (70 loc) • 2.41 kB
JavaScript
;
var _makeGetUnitSign = _interopRequireDefault(require("./makeGetUnitSign"));
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
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); }
describe("makeGetUnitSign", function () {
var mockChart;
beforeEach(function () {
mockChart = {
getUnitAttributes: jest.fn(function () {
return {
base: "bytes",
prefix: "K",
unit: "bytes"
};
})
};
(0, _makeGetUnitSign["default"])(mockChart);
});
it("creates getUnitSign function on chart", function () {
expect(_typeof(mockChart.getUnitSign)).toBe("function");
});
it("returns unit string with conversion", function () {
var result = mockChart.getUnitSign({
dimensionId: "test"
});
expect(_typeof(result)).toBe("string");
expect(mockChart.getUnitAttributes).toBeCalledWith("test", "units");
});
it("uses custom key parameter", function () {
mockChart.getUnitSign({
dimensionId: "test",
key: "customUnits"
});
expect(mockChart.getUnitAttributes).toBeCalledWith("test", "customUnits");
});
it("returns unit name without conversion when requested", function () {
mockChart.getUnitAttributes.mockReturnValue({
base: "bytes",
prefix: "M",
unit: "bytes"
});
var result = mockChart.getUnitSign({
dimensionId: "test",
withoutConversion: true
});
expect(_typeof(result)).toBe("string");
});
it("handles long format", function () {
var result = mockChart.getUnitSign({
dimensionId: "test",
"long": true
});
expect(_typeof(result)).toBe("string");
});
it("uses default parameters", function () {
mockChart.getUnitSign();
expect(mockChart.getUnitAttributes).toBeCalledWith(undefined, "units");
});
it("handles missing base unit", function () {
mockChart.getUnitAttributes.mockReturnValue({
base: null,
prefix: "",
unit: "percent"
});
var result = mockChart.getUnitSign({
dimensionId: "test"
});
expect(_typeof(result)).toBe("string");
});
});