Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(row separator): Added row separator option (#372)
- Loading branch information
Showing
9 changed files
with
240 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,5 +8,6 @@ export interface Dictionary { | |
} | ||
export interface Row { | ||
color: COLOR; | ||
separator?: boolean; | ||
text: Dictionary; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,165 @@ | ||
import { renderTable } from '../../src/internalTable/internal-table-printer'; | ||
import { Table } from '../../index'; | ||
|
||
describe('Testing Row separator', () => { | ||
it('Batch Row separator by each row', () => { | ||
// Create a table | ||
const p = new Table(); | ||
|
||
p.addRow({ index: 3, text: 'row without separator', value: 100 }); | ||
|
||
p.addRow( | ||
{ index: 4, text: 'row with separator', value: 300 }, | ||
{ separator: true } | ||
); | ||
|
||
p.addRow({ index: 5, text: 'row without separator', value: 100 }); | ||
|
||
const returned = renderTable(p.table); | ||
|
||
const expected = [ | ||
'βββββββββ¬ββββββββββββββββββββββββ¬ββββββββ', | ||
'\u001b[37mβ\u001b[0m\u001b[37m \u001b[0m\u001b[01mindex\u001b[0m\u001b[37m β\u001b[0m\u001b[37m \u001b[0m\u001b[01m text\u001b[0m\u001b[37m β\u001b[0m\u001b[37m \u001b[0m\u001b[01mvalue\u001b[0m\u001b[37m β\u001b[0m', | ||
'βββββββββΌββββββββββββββββββββββββΌββββββββ€', | ||
'\u001b[37mβ\u001b[0m\u001b[37m \u001b[0m\u001b[37m 3\u001b[0m\u001b[37m β\u001b[0m\u001b[37m \u001b[0m\u001b[37mrow without separator\u001b[0m\u001b[37m β\u001b[0m\u001b[37m \u001b[0m\u001b[37m 100\u001b[0m\u001b[37m β\u001b[0m', | ||
'\u001b[37mβ\u001b[0m\u001b[37m \u001b[0m\u001b[37m 4\u001b[0m\u001b[37m β\u001b[0m\u001b[37m \u001b[0m\u001b[37m row with separator\u001b[0m\u001b[37m β\u001b[0m\u001b[37m \u001b[0m\u001b[37m 300\u001b[0m\u001b[37m β\u001b[0m', | ||
'βββββββββΌββββββββββββββββββββββββΌββββββββ€', | ||
'\u001b[37mβ\u001b[0m\u001b[37m \u001b[0m\u001b[37m 5\u001b[0m\u001b[37m β\u001b[0m\u001b[37m \u001b[0m\u001b[37mrow without separator\u001b[0m\u001b[37m β\u001b[0m\u001b[37m \u001b[0m\u001b[37m 100\u001b[0m\u001b[37m β\u001b[0m', | ||
'βββββββββ΄ββββββββββββββββββββββββ΄ββββββββ', | ||
]; | ||
expect(returned).toBe(expected.join('\n')); | ||
}); | ||
|
||
it('Batch Row default separator is working', () => { | ||
// Create a table | ||
const p = new Table(); | ||
|
||
p.addRows([ | ||
// adding multiple rows are possible | ||
{ index: 3, text: 'row default separator', value: 100 }, | ||
{ index: 4, text: 'row default separator', value: 300 }, | ||
]); | ||
|
||
const returned = renderTable(p.table); | ||
|
||
const expected = [ | ||
'βββββββββ¬ββββββββββββββββββββββββ¬ββββββββ', | ||
'\u001b[37mβ\u001b[0m\u001b[37m \u001b[0m\u001b[01mindex\u001b[0m\u001b[37m β\u001b[0m\u001b[37m \u001b[0m\u001b[01m text\u001b[0m\u001b[37m β\u001b[0m\u001b[37m \u001b[0m\u001b[01mvalue\u001b[0m\u001b[37m β\u001b[0m', | ||
'βββββββββΌββββββββββββββββββββββββΌββββββββ€', | ||
'\u001b[37mβ\u001b[0m\u001b[37m \u001b[0m\u001b[37m 3\u001b[0m\u001b[37m β\u001b[0m\u001b[37m \u001b[0m\u001b[37mrow default separator\u001b[0m\u001b[37m β\u001b[0m\u001b[37m \u001b[0m\u001b[37m 100\u001b[0m\u001b[37m β\u001b[0m', | ||
'\u001b[37mβ\u001b[0m\u001b[37m \u001b[0m\u001b[37m 4\u001b[0m\u001b[37m β\u001b[0m\u001b[37m \u001b[0m\u001b[37mrow default separator\u001b[0m\u001b[37m β\u001b[0m\u001b[37m \u001b[0m\u001b[37m 300\u001b[0m\u001b[37m β\u001b[0m', | ||
'βββββββββ΄ββββββββββββββββββββββββ΄ββββββββ', | ||
]; | ||
expect(returned).toBe(expected.join('\n')); | ||
}); | ||
|
||
it('Batch Row table separator option is working', () => { | ||
// Create a table | ||
const p = new Table({ rowSeparator: true }); | ||
|
||
p.addRows([ | ||
// adding multiple rows are possible | ||
{ index: 3, text: 'table row separator', value: 100 }, | ||
{ index: 4, text: 'table row separator', value: 300 }, | ||
]); | ||
|
||
const returned = renderTable(p.table); | ||
|
||
const expected = [ | ||
'βββββββββ¬ββββββββββββββββββββββ¬ββββββββ', | ||
'\u001b[37mβ\u001b[0m\u001b[37m \u001b[0m\u001b[01mindex\u001b[0m\u001b[37m β\u001b[0m\u001b[37m \u001b[0m\u001b[01m text\u001b[0m\u001b[37m β\u001b[0m\u001b[37m \u001b[0m\u001b[01mvalue\u001b[0m\u001b[37m β\u001b[0m', | ||
'βββββββββΌββββββββββββββββββββββΌββββββββ€', | ||
'\u001b[37mβ\u001b[0m\u001b[37m \u001b[0m\u001b[37m 3\u001b[0m\u001b[37m β\u001b[0m\u001b[37m \u001b[0m\u001b[37mtable row separator\u001b[0m\u001b[37m β\u001b[0m\u001b[37m \u001b[0m\u001b[37m 100\u001b[0m\u001b[37m β\u001b[0m', | ||
'βββββββββΌββββββββββββββββββββββΌββββββββ€', | ||
'\u001b[37mβ\u001b[0m\u001b[37m \u001b[0m\u001b[37m 4\u001b[0m\u001b[37m β\u001b[0m\u001b[37m \u001b[0m\u001b[37mtable row separator\u001b[0m\u001b[37m β\u001b[0m\u001b[37m \u001b[0m\u001b[37m 300\u001b[0m\u001b[37m β\u001b[0m', | ||
'βββββββββ΄ββββββββββββββββββββββ΄ββββββββ', | ||
]; | ||
expect(returned).toBe(expected.join('\n')); | ||
}); | ||
|
||
it('Batch Row table separator override is working', () => { | ||
// Create a table | ||
const p = new Table({ rowSeparator: true }); | ||
|
||
p.addRows([ | ||
// adding multiple rows are possible | ||
{ index: 3, text: 'override table row separator', value: 100 }, | ||
{ index: 4, text: 'override table row separator', value: 300 }, | ||
], { separator: false }); | ||
|
||
const returned = renderTable(p.table); | ||
|
||
const expected = [ | ||
'βββββββββ¬βββββββββββββββββββββββββββββββ¬ββββββββ', | ||
'\u001b[37mβ\u001b[0m\u001b[37m \u001b[0m\u001b[01mindex\u001b[0m\u001b[37m β\u001b[0m\u001b[37m \u001b[0m\u001b[01m text\u001b[0m\u001b[37m β\u001b[0m\u001b[37m \u001b[0m\u001b[01mvalue\u001b[0m\u001b[37m β\u001b[0m', | ||
'βββββββββΌβββββββββββββββββββββββββββββββΌββββββββ€', | ||
'\u001b[37mβ\u001b[0m\u001b[37m \u001b[0m\u001b[37m 3\u001b[0m\u001b[37m β\u001b[0m\u001b[37m \u001b[0m\u001b[37moverride table row separator\u001b[0m\u001b[37m β\u001b[0m\u001b[37m \u001b[0m\u001b[37m 100\u001b[0m\u001b[37m β\u001b[0m', | ||
'\u001b[37mβ\u001b[0m\u001b[37m \u001b[0m\u001b[37m 4\u001b[0m\u001b[37m β\u001b[0m\u001b[37m \u001b[0m\u001b[37moverride table row separator\u001b[0m\u001b[37m β\u001b[0m\u001b[37m \u001b[0m\u001b[37m 300\u001b[0m\u001b[37m β\u001b[0m', | ||
'βββββββββ΄βββββββββββββββββββββββββββββββ΄ββββββββ', | ||
]; | ||
expect(returned).toBe(expected.join('\n')); | ||
}); | ||
|
||
it('Batch Row separator is working', () => { | ||
// Create a table | ||
const p = new Table(); | ||
|
||
p.addRows( | ||
[ | ||
// adding multiple rows are possible | ||
{ index: 3, text: 'row with separator', value: 100 }, | ||
{ index: 4, text: 'row with separator', value: 300 }, | ||
], | ||
{ separator: true } | ||
); | ||
|
||
const returned = renderTable(p.table); | ||
|
||
const expected = [ | ||
'βββββββββ¬βββββββββββββββββββββ¬ββββββββ', | ||
'\u001b[37mβ\u001b[0m\u001b[37m \u001b[0m\u001b[01mindex\u001b[0m\u001b[37m β\u001b[0m\u001b[37m \u001b[0m\u001b[01m text\u001b[0m\u001b[37m β\u001b[0m\u001b[37m \u001b[0m\u001b[01mvalue\u001b[0m\u001b[37m β\u001b[0m', | ||
'βββββββββΌβββββββββββββββββββββΌββββββββ€', | ||
'\u001b[37mβ\u001b[0m\u001b[37m \u001b[0m\u001b[37m 3\u001b[0m\u001b[37m β\u001b[0m\u001b[37m \u001b[0m\u001b[37mrow with separator\u001b[0m\u001b[37m β\u001b[0m\u001b[37m \u001b[0m\u001b[37m 100\u001b[0m\u001b[37m β\u001b[0m', | ||
'βββββββββΌβββββββββββββββββββββΌββββββββ€', | ||
'\u001b[37mβ\u001b[0m\u001b[37m \u001b[0m\u001b[37m 4\u001b[0m\u001b[37m β\u001b[0m\u001b[37m \u001b[0m\u001b[37mrow with separator\u001b[0m\u001b[37m β\u001b[0m\u001b[37m \u001b[0m\u001b[37m 300\u001b[0m\u001b[37m β\u001b[0m', | ||
'βββββββββ΄βββββββββββββββββββββ΄ββββββββ', | ||
]; | ||
expect(returned).toBe(expected.join('\n')); | ||
}); | ||
|
||
it('Batch Row separator combined with sorting', () => { | ||
// Create a table and sort by index | ||
const p = new Table({ sort: (row1, row2) => row1.index - row2.index, rowSeparator: true }); | ||
|
||
//Row with index 1 will have separator because it inherits from Table options | ||
p.addRow({ index: 1, text: 'row inherit separator', value: 100 }); | ||
p.addRow({ index: 4, text: 'row without separator', value: 100 }, { separator: false }); | ||
//Row with index 5 will be last row so separator will be ignored anyway | ||
p.addRow({ index: 5, text: 'row with separator', value: 100 }, { separator: true }); | ||
p.addRow({ index: 2, text: 'row with separator', value: 100 }, { separator: true }); | ||
p.addRow({ index: 3, text: 'row without separator', value: 100 }, { separator: false }); | ||
|
||
const returned = renderTable(p.table); | ||
|
||
const expected = [ | ||
'βββββββββ¬ββββββββββββββββββββββββ¬ββββββββ', | ||
'\u001b[37mβ\u001b[0m\u001b[37m \u001b[0m\u001b[01mindex\u001b[0m\u001b[37m β\u001b[0m\u001b[37m \u001b[0m\u001b[01m text\u001b[0m\u001b[37m β\u001b[0m\u001b[37m \u001b[0m\u001b[01mvalue\u001b[0m\u001b[37m β\u001b[0m', | ||
'βββββββββΌββββββββββββββββββββββββΌββββββββ€', | ||
'\u001b[37mβ\u001b[0m\u001b[37m \u001b[0m\u001b[37m 1\u001b[0m\u001b[37m β\u001b[0m\u001b[37m \u001b[0m\u001b[37mrow inherit separator\u001b[0m\u001b[37m β\u001b[0m\u001b[37m \u001b[0m\u001b[37m 100\u001b[0m\u001b[37m β\u001b[0m', | ||
'βββββββββΌββββββββββββββββββββββββΌββββββββ€', | ||
'\u001b[37mβ\u001b[0m\u001b[37m \u001b[0m\u001b[37m 2\u001b[0m\u001b[37m β\u001b[0m\u001b[37m \u001b[0m\u001b[37m row with separator\u001b[0m\u001b[37m β\u001b[0m\u001b[37m \u001b[0m\u001b[37m 100\u001b[0m\u001b[37m β\u001b[0m', | ||
'βββββββββΌββββββββββββββββββββββββΌββββββββ€', | ||
'\u001b[37mβ\u001b[0m\u001b[37m \u001b[0m\u001b[37m 3\u001b[0m\u001b[37m β\u001b[0m\u001b[37m \u001b[0m\u001b[37mrow without separator\u001b[0m\u001b[37m β\u001b[0m\u001b[37m \u001b[0m\u001b[37m 100\u001b[0m\u001b[37m β\u001b[0m', | ||
'\u001b[37mβ\u001b[0m\u001b[37m \u001b[0m\u001b[37m 4\u001b[0m\u001b[37m β\u001b[0m\u001b[37m \u001b[0m\u001b[37mrow without separator\u001b[0m\u001b[37m β\u001b[0m\u001b[37m \u001b[0m\u001b[37m 100\u001b[0m\u001b[37m β\u001b[0m', | ||
'\u001b[37mβ\u001b[0m\u001b[37m \u001b[0m\u001b[37m 5\u001b[0m\u001b[37m β\u001b[0m\u001b[37m \u001b[0m\u001b[37m row with separator\u001b[0m\u001b[37m β\u001b[0m\u001b[37m \u001b[0m\u001b[37m 100\u001b[0m\u001b[37m β\u001b[0m', | ||
'βββββββββ΄ββββββββββββββββββββββββ΄ββββββββ', | ||
]; | ||
expect(returned).toBe(expected.join('\n')); | ||
}); | ||
}); |