UNPKG

@netdata/charts

Version:

Netdata frontend SDK and chart utilities

75 lines (74 loc) 4.67 kB
"use strict"; 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 _ = _interopRequireWildcard(require(".")); 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); } describe("shorten", function () { it("returns string as-is for non-string inputs", function () { expect((0, _["default"])(null)).toBeNull(); expect((0, _["default"])(undefined)).toBeUndefined(); expect((0, _["default"])(123)).toBe(123); expect((0, _["default"])({})).toEqual({}); }); it("trims whitespace at round 0", function () { expect((0, _["default"])(" test ", 0)).toBe("test"); expect((0, _["default"])(" hello world ", 0)).toBe("hello world"); }); it("removes duplicate letters at round 1", function () { // Functions only work on compound words with separators, not single words expect((0, _["default"])("hello", 1)).toBe("hello"); expect((0, _["default"])("testing", 1)).toBe("testing"); expect((0, _["default"])("bookkeeper", 1)).toBe("bookkeeper"); }); it("removes middle vowels at round 2", function () { // Functions only work on compound words with separators, not single words expect((0, _["default"])("hello", 2)).toBe("hello"); expect((0, _["default"])("testing", 2)).toBe("testing"); expect((0, _["default"])("a", 2)).toBe("a"); // too short expect((0, _["default"])("ab", 2)).toBe("ab"); // too short expect((0, _["default"])("abc", 2)).toBe("abc"); // too short }); it("keeps numbers intact when removing vowels", function () { expect((0, _["default"])("test123", 2)).toBe("test123"); // contains digit expect((0, _["default"])("hello", 2)).toBe("hello"); // no separators, no transformation }); it("creates ellipsis in middle for round > 2", function () { expect((0, _["default"])("very long string", 10)).toBe("ver...ing"); expect((0, _["default"])("short", 10)).toBe("..."); // short strings get truncated to just ellipsis }); it("handles compound words with separators for round 1", function () { expect((0, _["default"])("hello-world", 1)).toBe("helo-world"); // removes duplicate 'l' expect((0, _["default"])("bookkeeper-test", 1)).toBe("bokeper-test"); // removes duplicates }); it("handles compound words with separators for round 2", function () { expect((0, _["default"])("hello-world", 2)).toBe("hllo-world"); // only first part gets transformed expect((0, _["default"])("testing_case", 2)).toBe("tstng_case"); // only first part gets transformed }); }); describe("shortForLength", function () { it("returns string as-is for non-string inputs", function () { expect((0, _.shortForLength)(null)).toBeNull(); expect((0, _.shortForLength)(undefined)).toBeUndefined(); expect((0, _.shortForLength)(123)).toBe(123); }); it("returns string as-is when under max length", function () { expect((0, _.shortForLength)("short", 30)).toBe("short"); expect((0, _.shortForLength)("medium length", 20)).toBe("medium length"); }); it("progressively shortens long strings", function () { var longString = "this is a very long string that needs shortening"; var result = (0, _.shortForLength)(longString, 20); expect(result.length).toBeLessThanOrEqual(20); expect(result).toBeTruthy(); }); it("uses default max length of 30", function () { var longString = "this is a very long string that definitely exceeds thirty characters"; var result = (0, _.shortForLength)(longString); expect(result.length).toBeLessThanOrEqual(30); }); it("handles extreme shortening with ellipsis", function () { var veryLongString = "extremely long string with many repeated letters and vowels"; var result = (0, _.shortForLength)(veryLongString, 10); expect(result.length).toBeLessThanOrEqual(10); expect(result).toContain("..."); }); });