From 780ef66d4f21c14ce0cc159ff8ec8585ee7d07c2 Mon Sep 17 00:00:00 2001 From: cornholio <0@mcornholio.ru> Date: Sat, 27 Oct 2018 13:45:09 +0300 Subject: [PATCH] Added docs and tests for header logic It was undocumented that `head` can accept custom cells, not just strings. Couldn't find info about it both in docs and tests. So, I've added some docs and tests --- advanced-usage.md | 14 +++++++++++ test/table-test.js | 58 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+) diff --git a/advanced-usage.md b/advanced-usage.md index 7181050..cbc0c2c 100644 --- a/advanced-usage.md +++ b/advanced-usage.md @@ -17,6 +17,20 @@ ``` +##### colSpan works with headers too: + ┌───────────┬────────┐ + │ foobar │ bazbar │ + ├─────┬─────┼────────┤ + │ foo │ bar │ baz │ + └─────┴─────┴────────┘ +```javascript + var table = new Table({ + style: {border:[], head: []}, + head:[{content: 'foobar', colSpan: 2}, {content: 'bazbar'}] + }); + + table.push(['foo', 'bar', 'baz']); +``` ##### use colSpan to span columns - (colSpan below normal cell) ┌───────┬───────┐ diff --git a/test/table-test.js b/test/table-test.js index 4bc3e05..4e8d570 100644 --- a/test/table-test.js +++ b/test/table-test.js @@ -69,6 +69,64 @@ describe('@api Table ',function(){ expect(table.toString()).to.equal(expected.join("\n")); }); + + it('will render head with text', function() { + var table = new Table({ + style: {border:[], head: []}, + head:['foobar', 'barbar', 'bazbar'], + }); + + table.push(['foo', 'bar', 'baz']); + + var expected = [ + '┌────────┬────────┬────────┐' + ,'│ foobar │ barbar │ bazbar │' + ,'├────────┼────────┼────────┤' + ,'│ foo │ bar │ baz │' + ,'└────────┴────────┴────────┘' + ]; + + expect(table.toString()).to.equal(expected.join('\n')); + }); + + it('will render head with Cells', function() { + var table = new Table({ + style: {border:[], head: []}, + head:[{content: 'foobar'}, {content: 'barbar'}, {content: 'bazbar'}], + }); + + table.push(['foo', 'bar', 'baz']); + + var expected = [ + '┌────────┬────────┬────────┐' + ,'│ foobar │ barbar │ bazbar │' + ,'├────────┼────────┼────────┤' + ,'│ foo │ bar │ baz │' + ,'└────────┴────────┴────────┘' + ]; + + expect(table.toString()).to.equal(expected.join('\n')); + }); + + it('will render colSpan in head correctly', function() { + var table = new Table({ + style: {border:[], head: []}, + head:[{content: 'foobar', colSpan: 2}, {content: 'bazbar'}], + }); + + table.push(['foo', 'bar', 'baz']); + + + var expected = [ + '┌───────────┬────────┐' + ,'│ foobar │ bazbar │' + ,'├─────┬─────┼────────┤' + ,'│ foo │ bar │ baz │' + ,'└─────┴─────┴────────┘' + ]; + + expect(table.toString()).to.equal(expected.join('\n')); + }); });