@netdata/charts
Version:
Netdata frontend SDK and chart utilities
77 lines • 2.74 kB
JavaScript
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 selectPlugin from "./select";
describe("select plugin", function () {
var sdk, chart, mockNode;
beforeEach(function () {
var _makeTestChart = makeTestChart({
attributes: {
navigation: "select"
}
}),
testSdk = _makeTestChart.sdk,
testChart = _makeTestChart.chart;
chart = testChart;
sdk = testSdk;
mockNode = {
updateAttributes: jest.fn()
};
chart.getApplicableNodes = jest.fn(function () {
return [mockNode];
});
chart.moveX = jest.fn();
});
it("returns cleanup function", function () {
var cleanup = selectPlugin(sdk);
expect(_typeof(cleanup)).toBe("function");
});
it("handles highlightStart for select navigation", function () {
selectPlugin(sdk);
sdk.trigger("highlightStart", chart);
expect(mockNode.updateAttributes).toHaveBeenCalledWith({
enabledHover: false,
highlighting: true
});
});
it("ignores highlightStart for non-select navigation", function () {
chart.getAttribute = jest.fn(function () {
return "pan";
});
selectPlugin(sdk);
sdk.trigger("highlightStart", chart);
expect(mockNode.updateAttributes).not.toHaveBeenCalled();
});
it("handles highlightEnd for select navigation", function () {
selectPlugin(sdk);
sdk.trigger("highlightEnd", chart, [1000, 2000]);
expect(mockNode.updateAttributes).toHaveBeenCalledWith({
enabledHover: true,
highlighting: false
});
expect(chart.moveX).toHaveBeenCalledWith(1000, 2000);
});
it("handles highlightEnd with null highlight", function () {
selectPlugin(sdk);
sdk.trigger("highlightEnd", chart, null);
expect(mockNode.updateAttributes).toHaveBeenCalledWith({
enabledHover: true,
highlighting: false
});
expect(chart.moveX).not.toHaveBeenCalled();
});
it("ignores highlightEnd for non-select navigation", function () {
chart.getAttribute = jest.fn(function () {
return "pan";
});
selectPlugin(sdk);
sdk.trigger("highlightEnd", chart, [1000, 2000]);
expect(mockNode.updateAttributes).not.toHaveBeenCalled();
expect(chart.moveX).not.toHaveBeenCalled();
});
it("cleanup function removes event listeners", function () {
var cleanup = selectPlugin(sdk);
expect(function () {
return cleanup();
}).not.toThrow();
});
});