UNPKG

@netdata/charts

Version:

Netdata frontend SDK and chart utilities

105 lines (104 loc) 3.11 kB
"use strict"; var _makeDefaultSDK = _interopRequireDefault(require("./makeDefaultSDK")); var _sdk = _interopRequireDefault(require("./sdk")); function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; } jest.mock("./sdk"); describe("makeDefaultSDK", function () { beforeEach(function () { jest.clearAllMocks(); _sdk["default"].mockReturnValue({ makeChart: jest.fn(), getRoot: jest.fn(), appendChild: jest.fn() }); }); it("creates SDK with all chart libraries", function () { (0, _makeDefaultSDK["default"])(); expect(_sdk["default"]).toHaveBeenCalledWith({ ui: expect.objectContaining({ dygraph: expect.any(Function), easypiechart: expect.any(Function), gauge: expect.any(Function), groupBoxes: expect.any(Function), number: expect.any(Function), d3pie: expect.any(Function), bars: expect.any(Function), table: expect.any(Function) }), plugins: expect.objectContaining({ move: expect.any(Function), hover: expect.any(Function), pan: expect.any(Function), highlight: expect.any(Function), select: expect.any(Function), selectVertical: expect.any(Function), play: expect.any(Function), annotationSync: expect.any(Function) }), attributes: expect.objectContaining({ _v: "v3", chartLibrary: "dygraph", navigation: "pan", after: -900, overlays: { proceeded: { type: "proceeded" } } }) }); }); it("merges custom attributes with defaults", function () { var customAttributes = { chartLibrary: "gauge", customAttribute: "test" }; (0, _makeDefaultSDK["default"])({ attributes: customAttributes }); expect(_sdk["default"]).toHaveBeenCalledWith(expect.objectContaining({ attributes: expect.objectContaining({ _v: "v3", chartLibrary: "gauge", navigation: "pan", after: -900, customAttribute: "test", overlays: { proceeded: { type: "proceeded" } } }) })); }); it("passes through additional options", function () { var customOptions = { customOption: "value", anotherOption: 123 }; (0, _makeDefaultSDK["default"])(customOptions); expect(_sdk["default"]).toHaveBeenCalledWith(expect.objectContaining({ customOption: "value", anotherOption: 123 })); }); it("returns SDK instance", function () { var mockSDK = { test: "sdk" }; _sdk["default"].mockReturnValue(mockSDK); var result = (0, _makeDefaultSDK["default"])(); expect(result).toBe(mockSDK); }); it("handles no options provided", function () { (0, _makeDefaultSDK["default"])(); expect(_sdk["default"]).toHaveBeenCalledWith(expect.objectContaining({ attributes: expect.objectContaining({ _v: "v3", chartLibrary: "dygraph", navigation: "pan", after: -900 }) })); }); });