UNPKG

simple-ascii-chart

Version:
76 lines (75 loc) 3.49 kB
"use strict"; var __assign = (this && this.__assign) || function () { __assign = Object.assign || function(t) { for (var s, i = 1, n = arguments.length; i < n; i++) { s = arguments[i]; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; } return t; }; return __assign.apply(this, arguments); }; Object.defineProperty(exports, "__esModule", { value: true }); var settings_1 = require("../settings"); var constants_1 = require("../../constants"); describe('getAnsiColor', function () { describe.each([ ['ansiBlack', '\u001b[30m'], ['ansiRed', '\u001b[31m'], ['ansiGreen', '\u001b[32m'], ['ansiYellow', '\u001b[33m'], ['ansiBlue', '\u001b[34m'], ['ansiMagenta', '\u001b[35m'], ['ansiCyan', '\u001b[36m'], ['ansiWhite', '\u001b[37m'], ['default', '\u001b[37m'], ])('', function (input, output) { it(input, function () { var formatted = (0, settings_1.getAnsiColor)(input); expect(formatted).toBe(output); }); }); }); describe('getChartSymbols', function () { describe.each([ ['ansiBlack', '\u001b[30m', 0], ['ansiRed', '\u001b[31m', 0], ['ansiGreen', '\u001b[32m', 0], ['ansiYellow', '\u001b[33m', 0], ['ansiBlue', '\u001b[34m', 0], ['ansiMagenta', '\u001b[35m', 0], ['ansiCyan', '\u001b[36m', 0], ['ansiWhite', '\u001b[37m', 0], ['default', '\u001b[37m', 0], [['ansiBlack', 'ansiRed'], '\u001b[30m', 0], [['ansiBlack', 'ansiRed'], '\u001b[31m', 1], ])('applies color based on input and series index', function (input, output, series) { it("applies color ".concat(input.toString(), " to series index ").concat(series), function () { var formatted = (0, settings_1.getChartSymbols)(input, series, undefined, [[]], false); expect(formatted.we).toBe("".concat(output, "\u2501\u001B[0m")); expect(formatted.wns).toBe("".concat(output, "\u2513\u001B[0m")); expect(formatted.ns).toBe("".concat(output, "\u2503\u001B[0m")); expect(formatted.nse).toBe("".concat(output, "\u2517\u001B[0m")); expect(formatted.wsn).toBe("".concat(output, "\u251B\u001B[0m")); expect(formatted.sne).toBe("".concat(output, "\u250F\u001B[0m")); expect(formatted.area).toBe("".concat(output, "\u2588\u001B[0m")); }); }); it('applies fill area symbol when fillArea is true', function () { var formatted = (0, settings_1.getChartSymbols)('ansiBlue', 0, undefined, [[]], true); Object.keys(constants_1.CHART).forEach(function (key) { expect(formatted[key]).toBe(formatted.area); }); }); it('uses custom chart symbols when provided', function () { var customSymbols = __assign(__assign({}, constants_1.CHART), { we: '-' }); var formatted = (0, settings_1.getChartSymbols)('ansiRed', 0, customSymbols, [[]], false); expect(formatted.we).toBe("\u001B[31m-\u001B[0m"); }); it('handles color getter function for color input', function () { var colorGetter = function (series) { return (series === 0 ? 'ansiGreen' : 'ansiYellow'); }; var formatted = (0, settings_1.getChartSymbols)(colorGetter, 1, undefined, [[]], false); expect(formatted.we).toBe("\u001B[33m\u2501\u001B[0m"); }); });