@netdata/charts
Version:
Netdata frontend SDK and chart utilities
38 lines • 1.36 kB
JavaScript
import { getPointValue, getRowPointValue } from "./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(getPointValue(cell, point)).toBe(10);
expect(getPointValue(cell, point, "arp")).toBe(20);
expect(getPointValue(cell, point, "pa")).toBe(30);
});
it("keeps compatibility with object and scalar cells", function () {
expect(getPointValue({
value: 10,
arp: 20
}, point)).toBe(10);
expect(getPointValue({
value: 10,
arp: 20
}, point, "arp")).toBe(20);
expect(getPointValue(10, point)).toBe(10);
expect(getPointValue(10, point, "arp")).toBeUndefined();
expect(getPointValue(null, point)).toBeNull();
expect(getPointValue(null, point, "arp")).toBeUndefined();
});
it("returns undefined when an array cell has no requested field", function () {
expect(getPointValue([10], point, "unknown")).toBeUndefined();
expect(getPointValue([10], {}, "value")).toBeUndefined();
});
});
describe("getRowPointValue", function () {
it("reads a cell at the requested row index", function () {
expect(getRowPointValue([1000, [10, 20, 30]], 1, point, "pa")).toBe(30);
expect(getRowPointValue(null, 1, point)).toBeUndefined();
});
});