Skip to content

Commit

Permalink
Fix empty text property and empty string
Browse files Browse the repository at this point in the history
  • Loading branch information
ioncakephper committed Aug 17, 2023
1 parent eea2a34 commit b3f12bf
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 3 deletions.
33 changes: 32 additions & 1 deletion __tests__/html.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,35 @@ describe('table', () => {
})



describe('gridHeaders', () => {

describe('Only headers, no url string', () => {

test(`No headers, no url string`, () => {
expect(gridHeaders()).toEqual([]);
});

test('Single header in the array, header item is string, no url string', () => {
expect(gridHeaders(['hello'])).toEqual(['hello']);
});

test('Single header in the array, header item is object with text property, no url string', () => {
expect(gridHeaders([{ text: 'hello' }])).toEqual(['hello']);
})

test('Single header in the array, header item is object with text property as empty string, no url string', () => {
expect(gridHeaders([{ text: ' ' }])).toEqual(['']);
})

test('Single header in the array, header item is an empty object, no url string', () => {
expect(gridHeaders([{}])).toEqual(['']);
})

})


describe('Headers and url string', () => {
test.todo('')
})

})
5 changes: 3 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,13 +167,14 @@ function gridHeaders(headers = [], urlString = '') {
}
return headers.map(header => {
if (isString(header)) {
return header;
return header.trim();
}

if (!header.data) {
return header.text || header.data || ''
return (header.text || header.data || '').trim()
}
header.text = header.text || header.data;
header.text = header.text.trim();
if (!header.sort) {
return header.text;
}
Expand Down

0 comments on commit b3f12bf

Please sign in to comment.