Skip to content

Commit 5a3608e

Browse files
committed
[cdt-98] - tests fixed
Signed-off-by: ashish <[email protected]>
1 parent 8cbaff6 commit 5a3608e

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

src/commands/showfile.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import Utilities from '../utilities/utilities'
77
export default class ShowFile extends Command {
88
static description = 'File Minifier'
99

10+
static DEFAULT_COUNT = 10
1011
static flags = {
1112
help: flags.help({char: 'h'}),
1213
file: flags.string({char: 'f' , description: 'formatted file to be shown'}),
@@ -37,7 +38,10 @@ export default class ShowFile extends Command {
3738
}
3839

3940
private getFileLinesToShow(flags: any) {
40-
return flags.num || 10
41+
if(flags.num && flags.num>0) // if value available and valid
42+
return flags.num;
43+
else
44+
return ShowFile.DEFAULT_COUNT;
4145
}
4246
// tslint:disable-next-line:no-unused
4347
private checkParameters(flags: unknown, args: { [p: string]: any }) {

test/commands/showfile.test.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,32 +13,33 @@ describe('showfile', () => {
1313
.stdout()
1414
.command(['showfile', 'test/resources/showfile.csv'])
1515
.it('check 10 lines are found', ctx => {
16-
expect(ctx.stdout).to.contain('|1 |2 |1 |14.0 |30.0708|1 |0 |')
16+
expect(ctx.stdout).to.contain('|1 |2 |1 |14.0 |30.0708|1 |0 |')
1717
})
1818
test
1919
.stdout()
2020
.command(['showfile', 'test/resources/showfile.csv', '-n', '5'])
2121
.it('check 5th line is found', ctx => {
22-
expect(ctx.stdout).to.contain('|0 |3 |0 |35.0|8.05 |0 |0 |')
22+
expect(ctx.stdout).to.contain('|0 |3 |0 |35.0|8.05 |0 |0 |')
2323
})
2424

2525
test
2626
.stdout()
27-
.command(['showfile', 'test/resources/showfile.csv', '-n', '900'])
27+
.command (['showfile', 'test/resources/showfile.csv', '-n', '900'])
2828
.it('check if the given number is greater than total lines', ctx => {
29-
expect(ctx.stdout).to.contain('|0 |3 |0 |32.0 |7.75 |0 |0 |')
29+
expect(ctx.stdout).to.contain('|0 |3 |0 |32.0 |7.75 |0 |0 |')
3030
})
31+
3132
test
3233
.stdout()
3334
.command(['showfile', 'test/resources/showfile.csv', '-n', '900'])
3435
.it('check if 900 count is used, it shows only total present rows', ctx => {
3536
expect(ctx.stdout).to.contain('showing top 892 rows.')
3637
})
38+
3739
test
3840
.stdout()
3941
.command(['showfile', 'test/resources/showfile.csv', '-n', '0'])
40-
.it('check if the given number is greater than total lines', ctx => {
41-
expect(ctx.stdout).to.contain('|Survived|Pclass|Sex|Age|Fare|Family_count|Cabin_ind |')
42+
.it('check if the given number is invalid then show default 10 lines', ctx => {
43+
expect(ctx.stdout).to.contain('|1 |2 |1 |14.0 |30.0708|1 |0 |')
4244
})
43-
//|Survived|Pclass|Sex|Age|Fare|Family_count|Cabin_ind |
4445
})

0 commit comments

Comments
 (0)