-
-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
526a098
commit d5f8be5
Showing
3 changed files
with
135 additions
and
39 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 |
---|---|---|
@@ -0,0 +1,95 @@ | ||
/* eslint-disable max-nested-callbacks */ | ||
|
||
import { | ||
expect, | ||
} from 'chai'; | ||
import makeConfig from '../src/makeConfig'; | ||
import table from '../src/table'; | ||
import type { | ||
TableConfig, | ||
} from '../src/types/internal'; | ||
|
||
const data = [ | ||
['Lorem ipsum', 'dolor sit'], | ||
['amet', 'consectetur'], | ||
['adipiscing', 'elit'], | ||
]; | ||
|
||
const basicConfig = makeConfig(data, { | ||
columnDefault: { | ||
width: 5, | ||
}, | ||
}); | ||
|
||
describe('drawTable', () => { | ||
describe('drawHorizontalLine', () => { | ||
context('only draw top and bottom borders', () => { | ||
it('draws proper borders', () => { | ||
const config: TableConfig = { | ||
...basicConfig, | ||
drawHorizontalLine: (index, size) => { | ||
return index === 0 || index === size; | ||
}, | ||
}; | ||
|
||
expect(table(data, config)).to.be.deep.equal(` | ||
╔═══════╤═══════╗ | ||
║ Lorem │ dolor ║ | ||
║ ipsum │ sit ║ | ||
║ amet │ conse ║ | ||
║ │ ctetu ║ | ||
║ │ r ║ | ||
║ adipi │ elit ║ | ||
║ scing │ ║ | ||
╚═══════╧═══════╝ | ||
`.trimLeft()); | ||
}); | ||
}); | ||
|
||
context('only draw inner borders', () => { | ||
it('draws proper borders', () => { | ||
const config: TableConfig = { | ||
...basicConfig, | ||
drawHorizontalLine: (index, size) => { | ||
return index > 0 && index < size; | ||
}, | ||
}; | ||
|
||
expect(table(data, config)).to.be.deep.equal(` | ||
║ Lorem │ dolor ║ | ||
║ ipsum │ sit ║ | ||
╟───────┼───────╢ | ||
║ amet │ conse ║ | ||
║ │ ctetu ║ | ||
║ │ r ║ | ||
╟───────┼───────╢ | ||
║ adipi │ elit ║ | ||
║ scing │ ║ | ||
`.trimLeft()); | ||
}); | ||
}); | ||
|
||
context('only draw top and next-to-last borders', () => { | ||
it('draws proper borders', () => { | ||
const config: TableConfig = { | ||
...basicConfig, | ||
drawHorizontalLine: (index, size) => { | ||
return index === 0 || index === size - 1; | ||
}, | ||
}; | ||
|
||
expect(table(data, config)).to.be.deep.equal(` | ||
╔═══════╤═══════╗ | ||
║ Lorem │ dolor ║ | ||
║ ipsum │ sit ║ | ||
║ amet │ conse ║ | ||
║ │ ctetu ║ | ||
║ │ r ║ | ||
╟───────┼───────╢ | ||
║ adipi │ elit ║ | ||
║ scing │ ║ | ||
`.trimLeft()); | ||
}); | ||
}); | ||
}); | ||
}); |