UNPKG

@netdata/charts

Version:

Netdata frontend SDK and chart utilities

64 lines (63 loc) 1.85 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 parseDOM from "./parseDOM"; describe("parseDOM", function () { var mockSDK; var mockDocument; beforeEach(function () { mockSDK = { getRoot: jest.fn(function () { return { id: "root" }; }), makeContainer: jest.fn(function () { return { id: "container" }; }), makeChart: jest.fn(function () { return { id: "chart" }; }) }; // Mock DOM global.document = { querySelectorAll: jest.fn(function () { return []; }) }; }); it("creates parseDOM result object", function () { var result = parseDOM(mockSDK); expect(_typeof(result)).toBe("object"); expect(result).toHaveProperty("elements"); expect(result).toHaveProperty("nodeByElement"); }); it("handles empty DOM", function () { expect(function () { return parseDOM(mockSDK); }).not.toThrow(); }); it("initializes with SDK when elements present", function () { mockSDK.getRoot.mockReturnValue({ appendChild: jest.fn() }); global.document.querySelectorAll = jest.fn(function () { return [{ hasAttribute: jest.fn(function () { return true; }), getAttributeNames: jest.fn(function () { return ["data-id"]; }), getAttribute: jest.fn(function () { return "test"; }), parentElement: null }]; }); parseDOM(mockSDK); expect(mockSDK.getRoot).toBeCalled(); }); });