@netdata/charts
Version:
Netdata frontend SDK and chart utilities
131 lines (130 loc) • 3.73 kB
JavaScript
;
var _makeLog = _interopRequireDefault(require("./makeLog"));
var _testUtilities = require("@jest/testUtilities");
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("makeLog", function () {
var sendLogCalls;
var realSendLog;
beforeEach(function () {
sendLogCalls = [];
realSendLog = function realSendLog(data) {
sendLogCalls.push(data);
};
});
it("creates log function", function () {
var _makeTestChart = (0, _testUtilities.makeTestChart)(),
chart = _makeTestChart.chart;
var log = (0, _makeLog["default"])(chart);
expect(_typeof(log)).toBe("function");
});
it("calls sendLog with merged data", function () {
var _makeTestChart2 = (0, _testUtilities.makeTestChart)({
attributes: {
logOptions: {
sendLog: realSendLog,
payload: {
data: {
base: "value"
}
}
}
}
}),
chart = _makeTestChart2.chart;
var log = (0, _makeLog["default"])(chart);
var payload = {
action: "test",
data: {
custom: "data"
}
};
log(payload);
expect(sendLogCalls).toHaveLength(1);
expect(sendLogCalls[0]).toEqual({
action: "test",
data: {
base: "value"
},
custom: "data",
base: "value",
chartId: chart.getAttribute("id")
});
});
it("handles empty payload", function () {
var _makeTestChart3 = (0, _testUtilities.makeTestChart)({
attributes: {
logOptions: {
sendLog: realSendLog,
payload: {
data: {
base: "value"
}
}
}
}
}),
chart = _makeTestChart3.chart;
var log = (0, _makeLog["default"])(chart);
log();
expect(sendLogCalls).toHaveLength(1);
expect(sendLogCalls[0]).toEqual({
data: {
base: "value"
},
base: "value",
chartId: chart.getAttribute("id")
});
});
it("returns noop when chart is null", function () {
var nullLog = (0, _makeLog["default"])(null);
expect(_typeof(nullLog())).toBe("function");
});
it("handles missing sendLog function", function () {
var _makeTestChart4 = (0, _testUtilities.makeTestChart)({
attributes: {
logOptions: {
payload: {}
}
}
}),
chart = _makeTestChart4.chart;
var logWithoutSender = (0, _makeLog["default"])(chart);
expect(function () {
return logWithoutSender();
}).not.toThrow();
});
it("merges payload data correctly", function () {
var _makeTestChart5 = (0, _testUtilities.makeTestChart)({
attributes: {
logOptions: {
sendLog: realSendLog,
payload: {
data: {
base: "value"
}
}
}
}
}),
chart = _makeTestChart5.chart;
var log = (0, _makeLog["default"])(chart);
var payload = {
event: "click",
data: {
overlay: "annotation"
}
};
log(payload);
expect(sendLogCalls).toHaveLength(1);
expect(sendLogCalls[0]).toEqual({
event: "click",
data: {
base: "value"
},
overlay: "annotation",
base: "value",
chartId: chart.getAttribute("id")
});
});
});