UNPKG

@netdata/charts

Version:

Netdata frontend SDK and chart utilities

66 lines 2.4 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"; import d3pieChart from "./index"; describe("d3pieChart", function () { it("creates chart instance with required methods", function () { var _makeTestChart = makeTestChart(), sdk = _makeTestChart.sdk, chart = _makeTestChart.chart; var instance = d3pieChart(sdk, chart); expect(instance).toHaveProperty("mount"); expect(instance).toHaveProperty("unmount"); expect(instance).toHaveProperty("render"); expect(_typeof(instance.mount)).toBe("function"); expect(_typeof(instance.unmount)).toBe("function"); expect(_typeof(instance.render)).toBe("function"); }); it("handles mount attempt with DOM limitations", function () { var _makeTestChart2 = makeTestChart(), sdk = _makeTestChart2.sdk, chart = _makeTestChart2.chart; var instance = d3pieChart(sdk, chart); var element = document.createElement("div"); expect(function () { return instance.mount(element); }).toThrow(); }); it("unmounts without errors when not mounted", function () { var _makeTestChart3 = makeTestChart(), sdk = _makeTestChart3.sdk, chart = _makeTestChart3.chart; var instance = d3pieChart(sdk, chart); expect(function () { return instance.unmount(); }).not.toThrow(); }); it("renders without errors when not mounted", function () { var _makeTestChart4 = makeTestChart({ attributes: { loaded: true } }), sdk = _makeTestChart4.sdk, chart = _makeTestChart4.chart; chart.getPayload = function () { return { data: [[1, 50, 30]] }; }; chart.getVisibleDimensionIds = function () { return ["cpu", "memory"]; }; chart.getDimensionValue = function () { return 25; }; chart.selectDimensionColor = function () { return "#ff0000"; }; chart.getClosestRow = function () { return 0; }; var instance = d3pieChart(sdk, chart); expect(function () { return instance.render(); }).not.toThrow(); }); });