@netdata/charts
Version:
Netdata frontend SDK and chart utilities
56 lines (55 loc) • 2.11 kB
JavaScript
;
var _makeWeights = _interopRequireDefault(require("./makeWeights"));
var _testUtilities = require("@jest/testUtilities");
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
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); }
describe("makeWeights", function () {
var chart;
var sdk;
var weightsModule;
beforeEach(function () {
var testChart = (0, _testUtilities.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 = (0, _makeWeights["default"])(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();
});
});