UNPKG

@netdata/charts

Version:

Netdata frontend SDK and chart utilities

80 lines (76 loc) 4.22 kB
"use strict"; var _getInitialAttributes = _interopRequireWildcard(require("./getInitialAttributes")); var _testUtilities = require("@jest/testUtilities"); function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, "default": e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); } 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("getInitialAttributes", function () { var chart; beforeEach(function () { var testChart = (0, _testUtilities.makeTestChart)({ attributes: { dimensionIds: ["cpu", "memory"], selectedDimensions: [], groupBy: [], dimensionsOnNonDimensionGrouping: [], units: ["percentage"] } }); chart = testChart.chart; }); it("exports stackedAggregations constant", function () { expect(_getInitialAttributes.stackedAggregations).toEqual({ avg: true, sum: true }); }); it("returns correct initial attributes with no aggregationMethod", function () { var result = (0, _getInitialAttributes["default"])(chart); expect(result).toHaveProperty("aggregationMethod"); expect(result).toHaveProperty("selectedDimensions"); expect(result).toHaveProperty("initializedFilters", true); // Default aggregation method for percentage units should be "avg" expect(result.aggregationMethod).toBe("sum"); }); it("uses provided aggregationMethod when available", function () { chart.updateAttribute("aggregationMethod", "sum"); var result = (0, _getInitialAttributes["default"])(chart); expect(result.aggregationMethod).toBe("sum"); expect(result.initializedFilters).toBe(true); }); it("sets initializedFilters to false when no dimensionIds", function () { chart.updateAttribute("dimensionIds", []); var result = (0, _getInitialAttributes["default"])(chart); expect(result.initializedFilters).toBe(false); }); it("handles selectedDimensions", function () { chart.updateAttribute("selectedDimensions", ["cpu"]); var result = (0, _getInitialAttributes["default"])(chart); expect(result.selectedDimensions).toEqual(["cpu"]); }); it("uses aggregation method based on units", function () { // Test with binary units that might have different default chart.updateAttribute("units", "By"); // bytes var result = (0, _getInitialAttributes["default"])(chart); expect(result).toHaveProperty("aggregationMethod"); expect(_typeof(result.aggregationMethod)).toBe("string"); }); it("handles dimension grouping", function () { chart.updateAttribute("groupBy", ["dimension"]); chart.updateAttribute("selectedDimensions", ["cpu", "memory"]); var result = (0, _getInitialAttributes["default"])(chart); expect(result.selectedDimensions).toEqual(["cpu", "memory"]); }); it("handles non-dimension grouping", function () { chart.updateAttribute("groupBy", ["node"]); chart.updateAttribute("dimensionsOnNonDimensionGrouping", ["all"]); var result = (0, _getInitialAttributes["default"])(chart); expect(result.selectedDimensions).toEqual(["all"]); }); it("returns all dimensions when nothing selected and no grouping", function () { chart.updateAttribute("selectedDimensions", []); chart.updateAttribute("groupBy", []); var result = (0, _getInitialAttributes["default"])(chart); // Should return empty array when no dimensions selected expect(result.selectedDimensions).toEqual([]); }); });