navy
Version:
Quick and powerful development environments using Docker and Docker Compose
44 lines (42 loc) • 2.13 kB
JavaScript
;
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
var _chai = require("chai");
var _stripAnsi = _interopRequireDefault(require("strip-ansi"));
var _table = _interopRequireDefault(require("../table"));
/* eslint-env mocha */
describe('table', function () {
it('should return an empty string when given no rows', function () {
(0, _chai.expect)((0, _table.default)([])).to.equal('');
});
it('should render a single-row table padded by 2 spaces', function () {
const result = (0, _table.default)([['a', 'bb']]);
(0, _chai.expect)(result).to.equal('a bb ');
});
it('should pad each column to the longest value in that column plus 2', function () {
const result = (0, _table.default)([['name', 'status'], ['api', 'running'], ['web', 'stopped']]);
const lines = result.split('\n');
(0, _chai.expect)(lines).to.have.lengthOf(3);
(0, _chai.expect)(lines[0]).to.equal('name status ');
(0, _chai.expect)(lines[1]).to.equal('api running ');
(0, _chai.expect)(lines[2]).to.equal('web stopped ');
});
it('should treat null/undefined cells in the header as empty strings when sizing', function () {
const result = (0, _table.default)([[null, 'b'], ['xx', 'yyy']]);
const lines = result.split('\n');
(0, _chai.expect)(lines[0]).to.equal(' b ');
(0, _chai.expect)(lines[1]).to.equal('xx yyy ');
});
it('should only render the cells that exist on each row (shorter rows are not back-padded)', function () {
const result = (0, _table.default)([['a', 'b'], ['x']]);
const lines = result.split('\n');
(0, _chai.expect)(lines[0]).to.equal('a b ');
(0, _chai.expect)(lines[1]).to.equal('x ');
});
it('should size columns by visible (ANSI-stripped) length', function () {
const ansiCell = '\u001b[31mhello\u001b[0m';
const result = (0, _table.default)([['col1'], [ansiCell]]);
const lines = result.split('\n');
(0, _chai.expect)((0, _stripAnsi.default)(lines[0])).to.equal('col1 ');
(0, _chai.expect)((0, _stripAnsi.default)(lines[1])).to.equal('hello ');
});
});