@netdata/charts
Version:
Netdata frontend SDK and chart utilities
154 lines (153 loc) • 6.61 kB
JavaScript
;
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); }
var _react = _interopRequireDefault(require("react"));
var _react2 = require("@testing-library/react");
require("@testing-library/jest-dom");
var _testUtilities = require("@jest/testUtilities");
var _index = _interopRequireWildcard(require("./index"));
var _jsxRuntime = require("react/jsx-runtime");
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, "default": e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
describe("Toolbox exports", function () {
it("exports all required components", function () {
expect(_index["default"]).toBeDefined();
expect(_index.Container).toBeDefined();
expect(_index.Separator).toBeDefined();
expect(_index.ChartType).toBeDefined();
expect(_index.Fullscreen).toBeDefined();
expect(_index.Information).toBeDefined();
expect(_index.Download).toBeDefined();
});
});
describe("Container component", function () {
it("renders container with children", function () {
(0, _testUtilities.renderWithChart)(/*#__PURE__*/(0, _jsxRuntime.jsx)(_index.Container, {
children: "Test Content"
}));
expect(_react2.screen.getByText("Test Content")).toBeInTheDocument();
});
it("has correct testid attribute", function () {
(0, _testUtilities.renderWithChart)(/*#__PURE__*/(0, _jsxRuntime.jsx)(_index.Container, {
children: "Content"
}));
expect(_react2.screen.getByTestId("chartHeaderToolbox")).toBeInTheDocument();
expect(_react2.screen.getByText("Content")).toBeInTheDocument();
});
});
describe("Toolbox component", function () {
it("renders toolbox with children", function () {
(0, _testUtilities.renderWithChart)(/*#__PURE__*/(0, _jsxRuntime.jsx)(_index["default"], {
children: "Test Content"
}), {
attributes: {
focused: true,
toolboxElements: []
}
});
expect(_react2.screen.getByText("Test Content")).toBeInTheDocument();
expect(_react2.screen.getByTestId("chartHeaderToolbox")).toBeInTheDocument();
});
it("renders custom toolbox elements with correct disabled state when not focused", function () {
var CustomElement = function CustomElement(_ref) {
var disabled = _ref.disabled;
return /*#__PURE__*/(0, _jsxRuntime.jsx)("button", {
disabled: disabled,
children: "Custom Button"
});
};
(0, _testUtilities.renderWithChart)(/*#__PURE__*/(0, _jsxRuntime.jsx)(_index["default"], {
children: "Regular Content"
}), {
attributes: {
focused: false,
toolboxElements: [CustomElement]
}
});
expect(_react2.screen.getByText("Custom Button")).toBeInTheDocument();
expect(_react2.screen.getByText("Custom Button")).toBeDisabled();
expect(_react2.screen.getByText("Regular Content")).toBeInTheDocument();
});
it("renders custom toolbox elements enabled when focused", function () {
var CustomElement = function CustomElement(_ref2) {
var disabled = _ref2.disabled;
return /*#__PURE__*/(0, _jsxRuntime.jsx)("button", {
disabled: disabled,
children: "Custom Button"
});
};
(0, _testUtilities.renderWithChart)(/*#__PURE__*/(0, _jsxRuntime.jsx)(_index["default"], {
children: "Regular Content"
}), {
attributes: {
focused: true,
toolboxElements: [CustomElement]
}
});
expect(_react2.screen.getByText("Custom Button")).toBeInTheDocument();
expect(_react2.screen.getByText("Custom Button")).not.toBeDisabled();
});
it("renders multiple toolbox elements", function () {
var Element1 = function Element1(_ref3) {
var disabled = _ref3.disabled;
return /*#__PURE__*/(0, _jsxRuntime.jsx)("button", {
disabled: disabled,
children: "Element 1"
});
};
var Element2 = function Element2(_ref4) {
var disabled = _ref4.disabled;
return /*#__PURE__*/(0, _jsxRuntime.jsx)("button", {
disabled: disabled,
children: "Element 2"
});
};
(0, _testUtilities.renderWithChart)(/*#__PURE__*/(0, _jsxRuntime.jsx)(_index["default"], {
children: "Content"
}), {
attributes: {
focused: true,
toolboxElements: [Element1, Element2]
}
});
expect(_react2.screen.getByText("Element 1")).toBeInTheDocument();
expect(_react2.screen.getByText("Element 2")).toBeInTheDocument();
expect(_react2.screen.getByText("Content")).toBeInTheDocument();
});
it("passes additional props to Container", function () {
(0, _testUtilities.renderWithChart)(/*#__PURE__*/(0, _jsxRuntime.jsx)(_index["default"], {
className: "custom-toolbox",
"data-test": "toolbox",
children: "Content"
}), {
attributes: {
focused: true,
toolboxElements: []
}
});
var container = _react2.screen.getByTestId("chartHeaderToolbox");
expect(container).toHaveClass("custom-toolbox");
expect(container).toHaveAttribute("data-test", "toolbox");
});
it("handles null toolboxElements gracefully", function () {
(0, _testUtilities.renderWithChart)(/*#__PURE__*/(0, _jsxRuntime.jsx)(_index["default"], {
children: "Content"
}), {
attributes: {
focused: true,
toolboxElements: null
}
});
expect(_react2.screen.getByText("Content")).toBeInTheDocument();
});
it("handles empty toolboxElements array", function () {
(0, _testUtilities.renderWithChart)(/*#__PURE__*/(0, _jsxRuntime.jsx)(_index["default"], {
children: "Content"
}), {
attributes: {
focused: true,
toolboxElements: []
}
});
expect(_react2.screen.getByText("Content")).toBeInTheDocument();
});
});