@netdata/charts
Version:
Netdata frontend SDK and chart utilities
80 lines (79 loc) • 3.16 kB
JavaScript
;
var _testUtilities = require("@jest/testUtilities");
var _selectVertical = _interopRequireDefault(require("./selectVertical"));
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
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); }
describe("selectVertical plugin", function () {
var sdk, chart, mockNode;
beforeEach(function () {
var _makeTestChart = (0, _testUtilities.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 = (0, _selectVertical["default"])(sdk);
expect(_typeof(cleanup)).toBe("function");
});
it("handles highlightVerticalStart for selectVertical navigation", function () {
(0, _selectVertical["default"])(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";
});
(0, _selectVertical["default"])(sdk);
sdk.trigger("highlightVerticalStart", chart);
expect(mockNode.updateAttributes).not.toHaveBeenCalled();
});
it("handles highlightVerticalEnd for selectVertical navigation", function () {
(0, _selectVertical["default"])(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 () {
(0, _selectVertical["default"])(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";
});
(0, _selectVertical["default"])(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 = (0, _selectVertical["default"])(sdk);
expect(function () {
return cleanup();
}).not.toThrow();
});
});