UNPKG

@netdata/charts

Version:

Netdata frontend SDK and chart utilities

53 lines 1.94 kB
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 makeWeights from "./makeWeights"; import { makeTestChart } from "@jest/testUtilities"; describe("makeWeights", function () { var chart; var sdk; var weightsModule; beforeEach(function () { var testChart = makeTestChart(); chart = testChart.chart; sdk = testChart.sdk; global.AbortController = jest.fn(function () { return { abort: jest.fn(), signal: {} }; }); global.fetch = jest.fn(function () { return Promise.resolve({ json: function json() { return Promise.resolve({ weights: {} }); } }); }); weightsModule = makeWeights(chart, sdk); }); afterEach(function () { jest.clearAllMocks(); }); it("returns weights object and fetchWeights function", function () { expect(weightsModule).toHaveProperty("weights"); expect(weightsModule).toHaveProperty("fetchWeights"); expect(_typeof(weightsModule.fetchWeights)).toBe("function"); }); it("initializes with empty weights object", function () { expect(weightsModule.weights).toEqual({}); }); it("fetchWeights updates loading state", function () { var spy = jest.spyOn(chart, "updateAttributes"); var triggerSpy = jest.spyOn(chart, "trigger"); weightsModule.fetchWeights("test-tab"); expect(spy).toHaveBeenCalledWith({ weightsLoading: true }); expect(triggerSpy).toHaveBeenCalledWith("weights:startFetch"); }); it("creates abort controller when fetching", function () { weightsModule.fetchWeights("test-tab"); expect(global.AbortController).toHaveBeenCalled(); }); });