Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add tests * Add test for alignTableData * Add test for getBorderCharacters and validateConfig * Add test for createStream * Fix typo Co-authored-by: Nam Hoang Le <nam.hoang.le@mgm-tp.com>
- Loading branch information
Showing
13 changed files
with
592 additions
and
12 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,66 @@ | ||
/* eslint-disable max-nested-callbacks */ | ||
|
||
import { | ||
expect, | ||
} from 'chai'; | ||
import chalk from 'chalk'; | ||
import alignTableData from '../src/alignTableData'; | ||
import makeConfig from '../src/makeConfig'; | ||
|
||
describe('alignTableData', () => { | ||
context('when the string width is equal to column width config', () => { | ||
it('returns the unchange string', () => { | ||
const rows = [['aaa'], [chalk.red('bbb')]]; | ||
|
||
expect(alignTableData(rows, makeConfig(rows, { | ||
columns: { | ||
0: { | ||
width: 3, | ||
}, | ||
}, | ||
}))).to.deep.equal(rows); | ||
}); | ||
}); | ||
|
||
context('when the string is different from the column width config', () => { | ||
it('aligns cells with column width and alignment config', () => { | ||
const rows = [['a', 'b', 'c'], | ||
[chalk.red('a'), chalk.red('b'), chalk.red('c')]]; | ||
|
||
expect(alignTableData(rows, makeConfig(rows, { | ||
columnDefault: { | ||
width: 3, | ||
}, | ||
columns: { | ||
0: { | ||
alignment: 'left', | ||
}, | ||
1: { | ||
alignment: 'right', | ||
}, | ||
2: { | ||
alignment: 'center', | ||
}, | ||
}, | ||
}))).to.deep.equal([['a ', ' b', ' c '], [ | ||
chalk.red('a') + ' ', ' ' + chalk.red('b'), ' ' + chalk.red('c') + ' ', | ||
]]); | ||
}); | ||
}); | ||
|
||
context('when the string is longer then column width', () => { | ||
it('throws an error', () => { | ||
const rows = [['aaaa']]; | ||
|
||
expect(() => { | ||
alignTableData(rows, makeConfig(rows, { | ||
columns: { | ||
0: { | ||
width: 3, | ||
}, | ||
}, | ||
})); | ||
}).to.throw(Error, 'Subject parameter value width cannot be greater than the container width.'); | ||
}); | ||
}); | ||
}); |
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,18 @@ | ||
import { | ||
expect, | ||
} from 'chai'; | ||
import drawRow from '../src/drawRow'; | ||
|
||
describe('drawRow', () => { | ||
it('draws a row using parts', () => { | ||
const parts = { | ||
bodyJoin: '│', | ||
bodyLeft: '║', | ||
bodyRight: '║', | ||
}; | ||
|
||
expect(drawRow([], parts)).to.equal('║║\n'); | ||
expect(drawRow(['a'], parts)).to.equal('║a║\n'); | ||
expect(drawRow(['a', ' b '], parts)).to.equal('║a│ b ║\n'); | ||
}); | ||
}); |
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,116 @@ | ||
/* eslint-disable max-nested-callbacks */ | ||
|
||
import { | ||
expect, | ||
} from 'chai'; | ||
import getBorderCharacters from '../src/getBorderCharacters'; | ||
|
||
describe('getBorderCharacters', () => { | ||
context('given name \'honeywell\'', () => { | ||
it('returns the \'honeywell\' template', () => { | ||
expect(getBorderCharacters('honeywell')).to.be.deep.equal({ | ||
bodyJoin: '│', | ||
bodyLeft: '║', | ||
bodyRight: '║', | ||
bottomBody: '═', | ||
|
||
bottomJoin: '╧', | ||
bottomLeft: '╚', | ||
bottomRight: '╝', | ||
joinBody: '─', | ||
|
||
joinJoin: '┼', | ||
joinLeft: '╟', | ||
joinRight: '╢', | ||
|
||
topBody: '═', | ||
topJoin: '╤', | ||
topLeft: '╔', | ||
topRight: '╗', | ||
}); | ||
}); | ||
}); | ||
|
||
context('given name \'norc\'', () => { | ||
it('returns the \'norc\' template', () => { | ||
expect(getBorderCharacters('norc')).to.be.deep.equal({ | ||
bodyJoin: '│', | ||
bodyLeft: '│', | ||
bodyRight: '│', | ||
bottomBody: '─', | ||
|
||
bottomJoin: '┴', | ||
bottomLeft: '└', | ||
bottomRight: '┘', | ||
joinBody: '─', | ||
|
||
joinJoin: '┼', | ||
joinLeft: '├', | ||
joinRight: '┤', | ||
|
||
topBody: '─', | ||
topJoin: '┬', | ||
topLeft: '┌', | ||
topRight: '┐', | ||
}); | ||
}); | ||
}); | ||
|
||
context('given name \'ramac\'', () => { | ||
it('returns the \'ramac\' template', () => { | ||
expect(getBorderCharacters('ramac')).to.be.deep.equal({ | ||
bodyJoin: '|', | ||
bodyLeft: '|', | ||
bodyRight: '|', | ||
bottomBody: '-', | ||
|
||
bottomJoin: '+', | ||
bottomLeft: '+', | ||
bottomRight: '+', | ||
joinBody: '-', | ||
|
||
joinJoin: '|', | ||
joinLeft: '|', | ||
joinRight: '|', | ||
|
||
topBody: '-', | ||
topJoin: '+', | ||
topLeft: '+', | ||
topRight: '+', | ||
}); | ||
}); | ||
}); | ||
|
||
context('given name \'void\'', () => { | ||
it('returns the \'void\' template', () => { | ||
expect(getBorderCharacters('void')).to.be.deep.equal({ | ||
bodyJoin: '', | ||
bodyLeft: '', | ||
bodyRight: '', | ||
bottomBody: '', | ||
|
||
bottomJoin: '', | ||
bottomLeft: '', | ||
bottomRight: '', | ||
joinBody: '', | ||
|
||
joinJoin: '', | ||
joinLeft: '', | ||
joinRight: '', | ||
|
||
topBody: '', | ||
topJoin: '', | ||
topLeft: '', | ||
topRight: '', | ||
}); | ||
}); | ||
}); | ||
|
||
context('given another name', () => { | ||
it('throws an error', () => { | ||
expect(() => { | ||
return getBorderCharacters('bold'); | ||
}).to.throw(Error, 'Unknown border template "bold".'); | ||
}); | ||
}); | ||
}); |
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
Oops, something went wrong.