Skip to content

Commit 4323d60

Browse files
authored
fix: Allow empty Column Title (#451)
1 parent ec89482 commit 4323d60

File tree

4 files changed

+57
-2
lines changed

4 files changed

+57
-2
lines changed

src/internalTable/input-converter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export const rawColumnToInternalColumn = (
1717
column: ColumnOptionsRaw
1818
): Column => ({
1919
name: column.name,
20-
title: column.title || column.name,
20+
title: column.title ?? column.name,
2121
...objIfExists('color', column.color as COLOR),
2222
...objIfExists('maxLen', column.maxLen),
2323
...objIfExists('minLen', column.minLen),

src/utils/table-helpers.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ export const createColumFromComputedColumn = (
7373
column: ComputedColumn
7474
): Column => ({
7575
name: column.name,
76-
title: column.title || column.name,
76+
title: column.title ?? column.name,
7777
...objIfExists('color', column.color as COLOR),
7878
...objIfExists('maxLen', column.maxLen),
7979
...objIfExists('minLen', column.minLen),

test/internalTable/__snapshots__/headerTitle.test.ts.snap

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3+
exports[`Testing Title Of Column Empty string title means blank title 1`] = `
4+
"┌───┬───────────────────────────────────┬───────────────────────────┐
5+
│   │   │ Other two should be blank │
6+
├───┼───────────────────────────────────┼───────────────────────────┤
7+
│ 2 │  This row is blue │  10.212  │
8+
│ 3 │ I would like some red wine please │  10.212  │
9+
└───┴───────────────────────────────────┴───────────────────────────┘"
10+
`;
11+
312
exports[`Testing Title Of Column title is used in table printing 1`] = `
413
"┌──────────────────────┬───────────────────────────────────┬────────────────────────┐
514
│ Red Left Align Index │  Right Align Text │ Big Green Value Center │

test/internalTable/headerTitle.test.ts

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,52 @@ describe('Testing Title Of Column', () => {
4747

4848
console.log(returned);
4949
expect(returned).toMatchSnapshot();
50+
});
51+
52+
it('Empty string title means blank title', () => {
53+
// Create a table
54+
const p = new Table({
55+
columns: [
56+
{
57+
name: 'red_left_align_index',
58+
alignment: 'left',
59+
title: '',
60+
},
61+
{
62+
name: 'right_align_text',
63+
alignment: 'right',
64+
title: '',
65+
},
66+
{
67+
name: 'green_value_center',
68+
alignment: 'center',
69+
title: 'Other two should be blank',
70+
},
71+
],
72+
});
73+
74+
// add rows with color
75+
p.addRow(
76+
{
77+
red_left_align_index: 2,
78+
right_align_text: 'This row is blue',
79+
green_value_center: 10.212,
80+
},
81+
{ color: 'blue' }
82+
);
83+
p.addRow(
84+
{
85+
red_left_align_index: 3,
86+
right_align_text: 'I would like some red wine please',
87+
green_value_center: 10.212,
88+
},
89+
{ color: 'red' }
90+
);
91+
92+
// print
93+
const returned = renderTable(p.table);
94+
5095
console.log(returned);
96+
expect(returned).toMatchSnapshot();
5197
});
5298
});

0 commit comments

Comments
 (0)