UNPKG

@netdata/charts

Version:

Netdata frontend SDK and chart utilities

77 lines 2.93 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 selectVerticalPlugin from "./selectVertical"; describe("selectVertical plugin", function () { var sdk, chart, mockNode; beforeEach(function () { var _makeTestChart = makeTestChart({ attributes: { navigation: "selectVertical" } }), testSdk = _makeTestChart.sdk, testChart = _makeTestChart.chart; chart = testChart; sdk = testSdk; mockNode = { updateAttributes: jest.fn() }; chart.getApplicableNodes = jest.fn(function () { return [mockNode]; }); chart.moveY = jest.fn(); }); it("returns cleanup function", function () { var cleanup = selectVerticalPlugin(sdk); expect(_typeof(cleanup)).toBe("function"); }); it("handles highlightVerticalStart for selectVertical navigation", function () { selectVerticalPlugin(sdk); sdk.trigger("highlightVerticalStart", chart); expect(mockNode.updateAttributes).toHaveBeenCalledWith({ enabledHover: false, highlighting: true }); }); it("ignores highlightVerticalStart for non-selectVertical navigation", function () { chart.getAttribute = jest.fn(function () { return "pan"; }); selectVerticalPlugin(sdk); sdk.trigger("highlightVerticalStart", chart); expect(mockNode.updateAttributes).not.toHaveBeenCalled(); }); it("handles highlightVerticalEnd for selectVertical navigation", function () { selectVerticalPlugin(sdk); sdk.trigger("highlightVerticalEnd", chart, [10, 100]); expect(mockNode.updateAttributes).toHaveBeenCalledWith({ enabledHover: true, highlighting: false }); expect(chart.moveY).toHaveBeenCalledWith(10, 100); }); it("handles highlightVerticalEnd with null value range", function () { selectVerticalPlugin(sdk); sdk.trigger("highlightVerticalEnd", chart, null); expect(mockNode.updateAttributes).toHaveBeenCalledWith({ enabledHover: true, highlighting: false }); expect(chart.moveY).not.toHaveBeenCalled(); }); it("ignores highlightVerticalEnd for non-selectVertical navigation", function () { chart.getAttribute = jest.fn(function () { return "pan"; }); selectVerticalPlugin(sdk); sdk.trigger("highlightVerticalEnd", chart, [10, 100]); expect(mockNode.updateAttributes).not.toHaveBeenCalled(); expect(chart.moveY).not.toHaveBeenCalled(); }); it("cleanup function removes event listeners", function () { var cleanup = selectVerticalPlugin(sdk); expect(function () { return cleanup(); }).not.toThrow(); }); });