UNPKG

@netdata/charts

Version:

Netdata frontend SDK and chart utilities

72 lines 2.7 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("per-dimension custom colors", function () { it("array form: a late-arriving dimension cannot receive a named custom color", function () { var _makeTestChart = makeTestChart({ attributes: { colors: [] } }), chart = _makeTestChart.chart; var initial = ["a", "b", "c", "d"].map(function (id) { return chart.selectDimensionColor(id); }); chart.updateAttribute("colors", ["#FF0000"]); expect(chart.selectDimensionColor("e")).not.toBe("#FF0000"); expect(chart.selectDimensionColor("a")).toBe(initial[0]); }); it("object form: late-arriving named dimensions receive their custom colors", function () { var _makeTestChart2 = makeTestChart({ attributes: { colors: {} } }), chart = _makeTestChart2.chart; ["a", "b", "c", "d"].forEach(function (id) { return chart.selectDimensionColor(id); }); chart.updateAttribute("colors", { e: "#FF0000", f: "#00FF00", g: "#0000FF", h: "#FFFF00", i: "#FF00FF" }); expect(chart.selectDimensionColor("e")).toBe("#FF0000"); expect(chart.selectDimensionColor("f")).toBe("#00FF00"); expect(chart.selectDimensionColor("g")).toBe("#0000FF"); expect(chart.selectDimensionColor("h")).toBe("#FFFF00"); expect(chart.selectDimensionColor("i")).toBe("#FF00FF"); }); it("object form with numeric palette index resolves to a palette color", function () { var _makeTestChart3 = makeTestChart({ attributes: { colors: { cpu: 2 } } }), chart = _makeTestChart3.chart; var color = chart.selectDimensionColor("cpu"); expect(_typeof(color)).toBe("string"); expect(color).not.toBe(""); }); it("auto colors do not depend on arrival order", function () { var a1 = makeTestChart({ attributes: { colors: [] } }).chart; var a2 = makeTestChart({ attributes: { colors: [] } }).chart; a1.setAttribute("dimensionIds", ["b", "a"]); a2.setAttribute("dimensionIds", ["a", "b"]); a1.updateColors(); a2.updateColors(); expect(a1.selectDimensionColor("a")).toBe(a2.selectDimensionColor("a")); expect(a1.selectDimensionColor("b")).toBe(a2.selectDimensionColor("b")); }); });