UNPKG

@netdata/charts

Version:

Netdata frontend SDK and chart utilities

117 lines (116 loc) 3.43 kB
"use strict"; var _annotations = _interopRequireDefault(require("./annotations")); function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; } describe("annotations plotter", function () { var mockChartUI; var mockPlotter; var mockCtx; var fillAlphaValues; beforeEach(function () { fillAlphaValues = []; mockCtx = { strokeStyle: "black", fillStyle: "black", globalAlpha: 1, fillRect: jest.fn(function () { return fillAlphaValues.push(mockCtx.globalAlpha); }), strokeRect: jest.fn() }; mockPlotter = { setName: "ANNOTATIONS", drawingContext: mockCtx, points: [{ canvasx: 10, xval: 1000 }, { canvasx: 20, xval: 2000 }], dygraph: { getArea: function getArea() { return { h: 100 }; } } }; mockChartUI = { chart: { getPayloadDimensionIds: function getPayloadDimensionIds() { return ["dim1", "dim2"]; }, getAttribute: function getAttribute() { return []; }, isDimensionVisible: function isDimensionVisible() { return true; }, getPayload: function getPayload() { return { all: [[1000, { pa: 1 }, { pa: 2 }], [2000, { pa: 4 }, { pa: 8 }]] }; }, getClosestRow: function getClosestRow(xval) { return xval === 1000 ? 0 : 1; } } }; }); it("returns early if no chartUI", function () { var plotter = (0, _annotations["default"])(null); expect(function () { return plotter(mockPlotter); }).not.toThrow(); }); it("returns early if setName is not ANNOTATIONS", function () { mockPlotter.setName = "OTHER"; var plotter = (0, _annotations["default"])(mockChartUI); plotter(mockPlotter); expect(mockCtx.fillRect).not.toHaveBeenCalled(); }); it("returns early if no points", function () { mockPlotter.points = []; var plotter = (0, _annotations["default"])(mockChartUI); plotter(mockPlotter); expect(mockCtx.fillRect).not.toHaveBeenCalled(); }); it("returns early if less than 2 points", function () { mockPlotter.points = [{ canvasx: 10, xval: 1000 }]; var plotter = (0, _annotations["default"])(mockChartUI); plotter(mockPlotter); expect(mockCtx.fillRect).not.toHaveBeenCalled(); }); it("renders annotations with transparent background", function () { var plotter = (0, _annotations["default"])(mockChartUI); plotter(mockPlotter); expect(mockCtx.fillRect).toHaveBeenCalled(); expect(mockCtx.strokeRect).toHaveBeenCalled(); }); it("renders the annotation line with reduced intensity", function () { var plotter = (0, _annotations["default"])(mockChartUI); plotter(mockPlotter); expect(fillAlphaValues).toContain(0.45); expect(mockCtx.globalAlpha).toBe(1); }); it("processes points with selected legend dimensions", function () { mockChartUI.chart.getAttribute = function () { return ["dim1"]; }; var plotter = (0, _annotations["default"])(mockChartUI); plotter(mockPlotter); expect(mockCtx.fillRect).toHaveBeenCalled(); expect(mockCtx.strokeRect).toHaveBeenCalled(); }); });