UNPKG

@netdata/charts

Version:

Netdata frontend SDK and chart utilities

72 lines (69 loc) 3.42 kB
"use strict"; var _getInitialAttributes = _interopRequireDefault(require("./getInitialAttributes")); var _testUtilities = require("@jest/testUtilities"); 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("getInitialAttributes", function () { var chart; beforeEach(function () { var testChart = (0, _testUtilities.makeTestChart)({ attributes: { dimensionIds: ["cpu", "memory"], selectedDimensions: [], groupBy: [], dimensionsOnNonDimensionGrouping: [], units: ["percentage"] } }); chart = testChart.chart; }); 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); expect(result.aggregationMethod).toBe("avg"); }); 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([]); }); });