@netdata/charts
Version:
Netdata frontend SDK and chart utilities
40 lines (39 loc) • 1.62 kB
JavaScript
;
var _getPointValue = require("./getPointValue");
var point = {
value: 0,
arp: 1,
pa: 2
};
describe("getPointValue", function () {
it("reads JSON2 array cells using the point schema", function () {
var cell = [10, 20, 30];
expect((0, _getPointValue.getPointValue)(cell, point)).toBe(10);
expect((0, _getPointValue.getPointValue)(cell, point, "arp")).toBe(20);
expect((0, _getPointValue.getPointValue)(cell, point, "pa")).toBe(30);
});
it("keeps compatibility with object and scalar cells", function () {
expect((0, _getPointValue.getPointValue)({
value: 10,
arp: 20
}, point)).toBe(10);
expect((0, _getPointValue.getPointValue)({
value: 10,
arp: 20
}, point, "arp")).toBe(20);
expect((0, _getPointValue.getPointValue)(10, point)).toBe(10);
expect((0, _getPointValue.getPointValue)(10, point, "arp")).toBeUndefined();
expect((0, _getPointValue.getPointValue)(null, point)).toBeNull();
expect((0, _getPointValue.getPointValue)(null, point, "arp")).toBeUndefined();
});
it("returns undefined when an array cell has no requested field", function () {
expect((0, _getPointValue.getPointValue)([10], point, "unknown")).toBeUndefined();
expect((0, _getPointValue.getPointValue)([10], {}, "value")).toBeUndefined();
});
});
describe("getRowPointValue", function () {
it("reads a cell at the requested row index", function () {
expect((0, _getPointValue.getRowPointValue)([1000, [10, 20, 30]], 1, point, "pa")).toBe(30);
expect((0, _getPointValue.getRowPointValue)(null, 1, point)).toBeUndefined();
});
});