UNPKG

@netdata/charts

Version:

Netdata frontend SDK and chart utilities

72 lines (71 loc) 2.83 kB
"use strict"; var _react = _interopRequireDefault(require("react")); var _testUtilities = require("@jest/testUtilities"); var _getInitialOptions = _interopRequireDefault(require("./getInitialOptions")); var _jsxRuntime = require("react/jsx-runtime"); 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("getInitialOptions", function () { it("returns valid d3pie configuration object", function () { var _renderWithChart = (0, _testUtilities.renderWithChart)(/*#__PURE__*/(0, _jsxRuntime.jsx)("div", {}), { attributes: { chartType: "pie" } }), chart = _renderWithChart.chart; var mockChartUI = { getElement: function getElement() { return { clientWidth: 400, clientHeight: 300 }; }, chart: chart }; var options = (0, _getInitialOptions["default"])(mockChartUI); expect(options).toHaveProperty("header"); expect(options).toHaveProperty("footer"); expect(options).toHaveProperty("data"); expect(options).toHaveProperty("labels"); expect(options).toHaveProperty("effects"); expect(options).toHaveProperty("tooltips"); expect(options).toHaveProperty("misc"); expect(options).toHaveProperty("callbacks"); expect(options).toHaveProperty("size"); }); it("sets canvas dimensions from element size", function () { var _renderWithChart2 = (0, _testUtilities.renderWithChart)(/*#__PURE__*/(0, _jsxRuntime.jsx)("div", {}), { chartType: "pie" }), chart = _renderWithChart2.chart; var mockChartUI = { getElement: function getElement() { return { clientWidth: 500, clientHeight: 400 }; }, chart: chart }; var options = (0, _getInitialOptions["default"])(mockChartUI); expect(options.size.canvasWidth).toBe(500); expect(options.size.canvasHeight).toBe(400); }); it("includes custom formatter function", function () { var _renderWithChart3 = (0, _testUtilities.renderWithChart)(/*#__PURE__*/(0, _jsxRuntime.jsx)("div", {}), { chartType: "pie" }), chart = _renderWithChart3.chart; var mockChartUI = { getElement: function getElement() { return { clientWidth: 400, clientHeight: 300 }; }, chart: chart }; var options = (0, _getInitialOptions["default"])(mockChartUI); expect(_typeof(options.labels.formatter)).toBe("function"); }); });