@netdata/charts
Version:
Netdata frontend SDK and chart utilities
115 lines (114 loc) • 3.98 kB
JavaScript
;
var _testUtilities = require("@jest/testUtilities");
var _index = _interopRequireDefault(require("./index"));
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("tableChart", function () {
it("creates chart instance with required methods", function () {
var _makeTestChart = (0, _testUtilities.makeTestChart)(),
sdk = _makeTestChart.sdk,
chart = _makeTestChart.chart;
var instance = (0, _index["default"])(sdk, chart);
expect(instance).toHaveProperty("mount");
expect(instance).toHaveProperty("unmount");
expect(instance).toHaveProperty("render");
expect(_typeof(instance.mount)).toBe("function");
expect(_typeof(instance.unmount)).toBe("function");
expect(_typeof(instance.render)).toBe("function");
});
it("mounts without errors", function () {
var _makeTestChart2 = (0, _testUtilities.makeTestChart)(),
sdk = _makeTestChart2.sdk,
chart = _makeTestChart2.chart;
var instance = (0, _index["default"])(sdk, chart);
var element = document.createElement("div");
expect(function () {
return instance.mount(element);
}).not.toThrow();
});
it("renders without errors when chart is not loaded", function () {
var _makeTestChart3 = (0, _testUtilities.makeTestChart)({
attributes: {
loaded: false
}
}),
sdk = _makeTestChart3.sdk,
chart = _makeTestChart3.chart;
var instance = (0, _index["default"])(sdk, chart);
expect(function () {
return instance.render();
}).not.toThrow();
});
it("renders without errors when chart is loaded", function () {
var _makeTestChart4 = (0, _testUtilities.makeTestChart)({
attributes: {
loaded: true
}
}),
sdk = _makeTestChart4.sdk,
chart = _makeTestChart4.chart;
chart.getPayload = function () {
return {
data: [[1617946860000, 10, 20]]
};
};
chart.getClosestRow = function () {
return 1;
};
var instance = (0, _index["default"])(sdk, chart);
expect(function () {
return instance.render();
}).not.toThrow();
});
it("handles hoverX attribute when rendering", function () {
var _makeTestChart5 = (0, _testUtilities.makeTestChart)({
attributes: {
loaded: true,
hoverX: [1617946865000]
}
}),
sdk = _makeTestChart5.sdk,
chart = _makeTestChart5.chart;
chart.getPayload = function () {
return {
data: [[1617946860000, 10], [1617946870000, 20]]
};
};
chart.getClosestRow = function () {
return 0;
};
var instance = (0, _index["default"])(sdk, chart);
expect(function () {
return instance.render();
}).not.toThrow();
});
it("handles empty data gracefully", function () {
var _makeTestChart6 = (0, _testUtilities.makeTestChart)({
attributes: {
loaded: true
}
}),
sdk = _makeTestChart6.sdk,
chart = _makeTestChart6.chart;
chart.getPayload = function () {
return {
data: []
};
};
var instance = (0, _index["default"])(sdk, chart);
expect(function () {
return instance.render();
}).not.toThrow();
});
it("unmounts without errors", function () {
var _makeTestChart7 = (0, _testUtilities.makeTestChart)(),
sdk = _makeTestChart7.sdk,
chart = _makeTestChart7.chart;
var instance = (0, _index["default"])(sdk, chart);
var element = document.createElement("div");
instance.mount(element);
expect(function () {
return instance.unmount();
}).not.toThrow();
});
});