UNPKG

@netdata/charts

Version:

Netdata frontend SDK and chart utilities

114 lines 4.17 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); } function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; } function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; } function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); } import { makeTestChart } from "@jest/testUtilities"; import movePlugin from "./move"; describe("move plugin", function () { var sdk, chart, mockNode; beforeEach(function () { var _makeTestChart = makeTestChart({ attributes: { autoPlay: false } }), testSdk = _makeTestChart.sdk, testChart = _makeTestChart.chart; chart = testChart; sdk = testSdk; mockNode = _defineProperty({ updateAttributes: jest.fn(), updateAttribute: jest.fn(), getAttribute: jest.fn(function () { return true; }), setAttributes: jest.fn(), getAttributes: jest.fn(function () { return { after: 0, hovering: false, active: true, loaded: true, fetchStartedAt: null }; }), getRoot: jest.fn(function () { return { getAttribute: jest.fn(function () { return false; }) }; }), lastFetch: [0, 0], getDateWindow: jest.fn(function () { return [0, 0]; }) }, "updateAttribute", jest.fn()); chart.getApplicableNodes = jest.fn(function () { return [mockNode]; }); chart.updateStaticValueRange = jest.fn(); chart.resetStaticValueRange = jest.fn(); chart.moveX = jest.fn(); chart.onAttributeChange = jest.fn(function () { return jest.fn(); }); jest.spyOn(Date, "now").mockReturnValue(2000000); }); afterEach(function () { Date.now.mockRestore(); }); it("handles moveX events", function () { movePlugin(sdk); sdk.trigger("moveX", chart, 1000, 2000); expect(mockNode.updateAttributes).toHaveBeenCalledWith({ after: 1000, before: 2000 }); }); it("handles negative after values in moveX", function () { movePlugin(sdk); sdk.trigger("moveX", chart, -300, 0); expect(mockNode.updateAttributes).toHaveBeenCalledWith({ after: -300, before: 0 }); }); it("adjusts for autoPlay when before is in future", function () { chart.getAttribute = jest.fn(function () { return true; }); movePlugin(sdk); sdk.trigger("moveX", chart, 1000, 3000); expect(mockNode.updateAttributes).toHaveBeenCalledWith({ after: -1999, before: 0 }); }); it("handles moveY events", function () { movePlugin(sdk); sdk.trigger("moveY", chart, 10, 100); expect(chart.updateStaticValueRange).toHaveBeenCalledWith([10, 100]); }); it("handles moveY with negative after value", function () { chart.getAttribute = jest.fn(function () { return -300; }); movePlugin(sdk); sdk.trigger("moveY", chart, 10, 100); expect(chart.moveX).toHaveBeenCalled(); }); it("sets up after attribute listener on moveY", function () { movePlugin(sdk); sdk.trigger("moveY", chart, 10, 100); expect(chart.onAttributeChange).toHaveBeenCalledWith("after", expect.any(Function)); }); it("updates inactive nodes as not loaded", function () { mockNode.getAttribute = jest.fn(function () { return false; }); movePlugin(sdk); sdk.trigger("moveX", chart, 1000, 2000); expect(mockNode.updateAttribute).toHaveBeenCalledWith("loaded", false); }); });