@netdata/charts
Version:
Netdata frontend SDK and chart utilities
85 lines (84 loc) • 4.4 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 _valueWithUnit = _interopRequireWildcard(require("./valueWithUnit"));
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("ValueWithUnit", function () {
it("renders one header for the value and unit subcolumns", function () {
(0, _testUtilities.renderWithChart)(/*#__PURE__*/(0, _jsxRuntime.jsx)(_valueWithUnit.ValueUnitHeader, {
label: "Value"
}));
expect(_react2.screen.getByText("Value")).toHaveStyle("grid-column: 1/-1; text-align: center");
expect(_react2.screen.queryByText("Unit")).not.toBeInTheDocument();
});
it("scales each value independently and renders its unit in a separate cell", function () {
var _makeTestChart = (0, _testUtilities.makeTestChart)({
attributes: {
units: ["By"],
desiredUnits: ["auto"],
viewDimensions: {
ids: ["bytes"],
names: ["bytes"],
units: ["By"],
contexts: ["test.bytes"]
},
dimensionIds: ["bytes"],
visibleDimensionIds: ["bytes"]
}
}),
chart = _makeTestChart.chart;
chart.updateDimensions();
(0, _testUtilities.renderWithChart)(/*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_valueWithUnit["default"], {
value: 1,
dimensionId: "bytes"
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_valueWithUnit["default"], {
value: 1024,
dimensionId: "bytes"
})]
}), {
chart: chart
});
var grids = _react2.screen.getAllByTestId("drawer-value-unit-grid");
var units = _react2.screen.getAllByTestId("drawer-value-unit-cell");
expect(grids[0]).toHaveTextContent("1B");
expect(units[0]).toHaveTextContent("B");
expect(grids[1]).toHaveTextContent("1KiB");
expect(units[1]).toHaveTextContent("KiB");
expect(grids[1]).toHaveStyle("grid-template-columns: minmax(0,1fr) 44px");
expect(units[1]).toHaveStyle({
minWidth: "0px",
padding: "0px 0px 0px 8px"
});
});
it("supports units that belong to a derived value instead of the chart", function () {
(0, _testUtilities.renderWithChart)(/*#__PURE__*/(0, _jsxRuntime.jsx)(_valueWithUnit["default"], {
value: 25.4,
valueKey: "percent",
unit: "%"
}));
expect(_react2.screen.getByTestId("drawer-value-unit-grid")).toHaveTextContent("25.40%");
expect(_react2.screen.getByTestId("drawer-value-unit-cell")).toHaveTextContent("%");
});
it("renders details beneath the value subcolumn", function () {
(0, _testUtilities.renderWithChart)(/*#__PURE__*/(0, _jsxRuntime.jsx)(_valueWithUnit.ValueUnitGrid, {
value: "99.5",
unit: "%",
detail: "Strong"
}));
var grid = _react2.screen.getByTestId("drawer-value-unit-grid");
var detail = _react2.screen.getByTestId("drawer-value-unit-detail");
expect(grid).toContainElement(detail);
expect(grid).toHaveStyle("grid-template-columns: minmax(0,1fr) 44px");
expect(detail).toHaveStyle({
margin: "4px 0px 0px",
textAlign: "right"
});
expect(detail).toHaveTextContent("Strong");
});
});