@netdata/charts
Version:
Netdata frontend SDK and chart utilities
128 lines • 3.39 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 makeLog from "./makeLog";
import { makeTestChart } from "@jest/testUtilities";
describe("makeLog", function () {
var sendLogCalls;
var realSendLog;
beforeEach(function () {
sendLogCalls = [];
realSendLog = function realSendLog(data) {
sendLogCalls.push(data);
};
});
it("creates log function", function () {
var _makeTestChart = makeTestChart(),
chart = _makeTestChart.chart;
var log = makeLog(chart);
expect(_typeof(log)).toBe("function");
});
it("calls sendLog with merged data", function () {
var _makeTestChart2 = makeTestChart({
attributes: {
logOptions: {
sendLog: realSendLog,
payload: {
data: {
base: "value"
}
}
}
}
}),
chart = _makeTestChart2.chart;
var log = makeLog(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 = makeTestChart({
attributes: {
logOptions: {
sendLog: realSendLog,
payload: {
data: {
base: "value"
}
}
}
}
}),
chart = _makeTestChart3.chart;
var log = makeLog(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 = makeLog(null);
expect(_typeof(nullLog())).toBe("function");
});
it("handles missing sendLog function", function () {
var _makeTestChart4 = makeTestChart({
attributes: {
logOptions: {
payload: {}
}
}
}),
chart = _makeTestChart4.chart;
var logWithoutSender = makeLog(chart);
expect(function () {
return logWithoutSender();
}).not.toThrow();
});
it("merges payload data correctly", function () {
var _makeTestChart5 = makeTestChart({
attributes: {
logOptions: {
sendLog: realSendLog,
payload: {
data: {
base: "value"
}
}
}
}
}),
chart = _makeTestChart5.chart;
var log = makeLog(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")
});
});
});