Skip to content
This repository has been archived by the owner on Aug 5, 2024. It is now read-only.

Commit

Permalink
Update emitter to respect page sizes and defaults
Browse files Browse the repository at this point in the history
  • Loading branch information
cbetta committed Mar 22, 2017
1 parent b82553c commit 11b375b
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/emitter.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class Emitter {
const size = parseInt(flags.size || 100);
const total = data.count;
const start = size*(page-1) + 1;
const end = start + size - 1;
const end = Math.min(start + size - 1, total);

if (this.amplified) this.log(`Item ${start}-${end} of ${total}\n`);
}
Expand Down
41 changes: 41 additions & 0 deletions tests/emitter.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,4 +130,45 @@ describe('Emitter', () => {
expect(log).not.to.have.been.calledWith(message);
}));
});

describe('.pagination', () => {
it('should output the current page', sinon.test(function() {
let log = this.stub(console, 'log');
let data = { count: 2 };
let flags = {};

let message = 'Item 1-2 of 2\n';

emitter.verbose();
emitter.pagination(flags, data);
expect(log).to.have.been.calledOnce;
expect(log).to.have.been.calledWith(message);
}));

it('should handle different pages', sinon.test(function() {
let log = this.stub(console, 'log');
let data = { count: 102 };
let flags = { page: 2 };

let message = 'Item 101-102 of 102\n';

emitter.verbose();
emitter.pagination(flags, data);
expect(log).to.have.been.calledOnce;
expect(log).to.have.been.calledWith(message);
}));

it('should handle different page sizes', sinon.test(function() {
let log = this.stub(console, 'log');
let data = { count: 102 };
let flags = { page: 4, size: 25 };

let message = 'Item 76-100 of 102\n';

emitter.verbose();
emitter.pagination(flags, data);
expect(log).to.have.been.calledOnce;
expect(log).to.have.been.calledWith(message);
}));
});
});

0 comments on commit 11b375b

Please sign in to comment.