Skip to content

Commit

Permalink
fix: Allow empty Column Title (#451)
Browse files Browse the repository at this point in the history
  • Loading branch information
ayonious authored Jul 2, 2023
1 parent ec89482 commit 4323d60
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/internalTable/input-converter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export const rawColumnToInternalColumn = (
column: ColumnOptionsRaw
): Column => ({
name: column.name,
title: column.title || column.name,
title: column.title ?? column.name,
...objIfExists('color', column.color as COLOR),
...objIfExists('maxLen', column.maxLen),
...objIfExists('minLen', column.minLen),
Expand Down
2 changes: 1 addition & 1 deletion src/utils/table-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export const createColumFromComputedColumn = (
column: ComputedColumn
): Column => ({
name: column.name,
title: column.title || column.name,
title: column.title ?? column.name,
...objIfExists('color', column.color as COLOR),
...objIfExists('maxLen', column.maxLen),
...objIfExists('minLen', column.minLen),
Expand Down
9 changes: 9 additions & 0 deletions test/internalTable/__snapshots__/headerTitle.test.ts.snap
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Testing Title Of Column Empty string title means blank title 1`] = `
"β”Œβ”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   β”‚   β”‚ Other two should be blank β”‚
β”œβ”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ 2 β”‚  This row is blue β”‚  10.212  β”‚
β”‚ 3 β”‚ I would like some red wine please β”‚  10.212  β”‚
β””β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜"
`;

exports[`Testing Title Of Column title is used in table printing 1`] = `
"β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Red Left Align Index β”‚  Right Align Text β”‚ Big Green Value Center β”‚
Expand Down
46 changes: 46 additions & 0 deletions test/internalTable/headerTitle.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,52 @@ describe('Testing Title Of Column', () => {

console.log(returned);
expect(returned).toMatchSnapshot();
});

it('Empty string title means blank title', () => {
// Create a table
const p = new Table({
columns: [
{
name: 'red_left_align_index',
alignment: 'left',
title: '',
},
{
name: 'right_align_text',
alignment: 'right',
title: '',
},
{
name: 'green_value_center',
alignment: 'center',
title: 'Other two should be blank',
},
],
});

// add rows with color
p.addRow(
{
red_left_align_index: 2,
right_align_text: 'This row is blue',
green_value_center: 10.212,
},
{ color: 'blue' }
);
p.addRow(
{
red_left_align_index: 3,
right_align_text: 'I would like some red wine please',
green_value_center: 10.212,
},
{ color: 'red' }
);

// print
const returned = renderTable(p.table);

console.log(returned);
expect(returned).toMatchSnapshot();
});
});

0 comments on commit 4323d60

Please sign in to comment.