Fixing up validation and tests for pagination helper where prev and next are undefined by default, rather than null.

This commit is contained in:
ErisDS 2013-07-17 14:37:52 +01:00
parent 061c3d6176
commit 4fd9556904
2 changed files with 23 additions and 26 deletions

View File

@ -155,14 +155,13 @@ coreHelpers = function (ghost) {
return;
}
if (_.isUndefined(this.pagination.page) || _.isUndefined(this.pagination.pages)
|| _.isUndefined(this.pagination.total) || _.isUndefined(this.pagination.limit)
|| _.isUndefined(this.pagination.prev) || _.isUndefined(this.pagination.prev)) {
errors.logAndThrowError('All values must be defined for page, pages, limit, total, prev and next');
|| _.isUndefined(this.pagination.total) || _.isUndefined(this.pagination.limit)) {
errors.logAndThrowError('All values must be defined for page, pages, limit and total');
return;
}
if ((!_.isNumber(this.pagination.next) && !_.isNull(this.pagination.next))
|| (!_.isNumber(this.pagination.prev) && !_.isNull(this.pagination.prev))) {
errors.logAndThrowError('Invalid value, Next/Prev must be a number or null');
if ((!_.isUndefined(this.pagination.next) && !_.isNumber(this.pagination.next))
|| (!_.isUndefined(this.pagination.prev) && !_.isNumber(this.pagination.prev))) {
errors.logAndThrowError('Invalid value, Next/Prev must be a number');
return;
}
if (!_.isNumber(this.pagination.page) || !_.isNumber(this.pagination.pages)

View File

@ -78,7 +78,7 @@ describe('Core Helpers', function () {
it('can render single page with no pagination necessary', function (done) {
var rendered;
helpers.loadCoreHelpers(ghost).then(function () {
rendered = handlebars.helpers.paginate.call({pagination: {page: 1, prev: null, next: null, limit: 15, total: 8, pages: 1}});
rendered = handlebars.helpers.paginate.call({pagination: {page: 1, prev: undefined, next: undefined, limit: 15, total: 8, pages: 1}});
should.exist(rendered);
rendered.string.should.equal('\n<nav id="pagination" role="pagination">\n \n <div class="page-number">Page 1<span class="extended"> of 1</span></div>\n \n</nav>');
done();
@ -88,7 +88,7 @@ describe('Core Helpers', function () {
it('can render first page of many with older posts link', function (done) {
var rendered;
helpers.loadCoreHelpers(ghost).then(function () {
rendered = handlebars.helpers.paginate.call({pagination: {page: 1, prev: null, next: 2, limit: 15, total: 8, pages: 3}});
rendered = handlebars.helpers.paginate.call({pagination: {page: 1, prev: undefined, next: 2, limit: 15, total: 8, pages: 3}});
should.exist(rendered);
rendered.string.should.equal('\n<nav id="pagination" role="pagination">\n \n <div class="previous-page"><a href="/page/2/">Older Posts →</a></div>\n \n <div class="page-number">Page 1<span class="extended"> of 3</span></div>\n \n</nav>');
done();
@ -108,7 +108,7 @@ describe('Core Helpers', function () {
it('can render last page of many with newer posts link', function (done) {
var rendered;
helpers.loadCoreHelpers(ghost).then(function () {
rendered = handlebars.helpers.paginate.call({pagination: {page: 3, prev: 2, next: null, limit: 15, total: 8, pages: 3}});
rendered = handlebars.helpers.paginate.call({pagination: {page: 3, prev: 2, next: undefined, limit: 15, total: 8, pages: 3}});
should.exist(rendered);
rendered.string.should.equal('\n<nav id="pagination" role="pagination">\n \n <div class="page-number">Page 3<span class="extended"> of 3</span></div>\n \n <div class="next-page"><a href="/page/2/">← Newer Posts</a></div>\n \n</nav>');
done();
@ -123,29 +123,27 @@ describe('Core Helpers', function () {
};
};
runErrorTest({pagination: {page: 3, prev: true, next: null, limit: 15, total: 8, pages: 3}})
.should.throwError('Invalid value, Next/Prev must be a number or null');
runErrorTest({pagination: {page: 3, prev: true, next: undefined, limit: 15, total: 8, pages: 3}})
.should.throwError('Invalid value, Next/Prev must be a number');
runErrorTest({pagination: {page: 3, prev: 2, next: true, limit: 15, total: 8, pages: 3}})
.should.throwError('Invalid value, Next/Prev must be a number or null');
.should.throwError('Invalid value, Next/Prev must be a number');
runErrorTest({pagination: {prev: 2, next: null, limit: 15, total: 8, pages: 3}})
.should.throwError('All values must be defined for page, pages, limit, total, prev and next');
runErrorTest({pagination: {page: 3, next: null, limit: 15, total: 8, pages: 3}})
.should.throwError('All values must be defined for page, pages, limit, total, prev and next');
runErrorTest({pagination: {page: 3, prev: 2, next: null, total: 8, pages: 3}})
.should.throwError('All values must be defined for page, pages, limit, total, prev and next');
runErrorTest({pagination: {page: 3, prev: 2, next: null, limit: 15,pages: 3}})
.should.throwError('All values must be defined for page, pages, limit, total, prev and next');
runErrorTest({pagination: {page: 3, prev: 2, next: null, limit: 15, total: 8}})
.should.throwError('All values must be defined for page, pages, limit, total, prev and next');
runErrorTest({pagination: {limit: 15, total: 8, pages: 3}})
.should.throwError('All values must be defined for page, pages, limit and total');
runErrorTest({pagination: {page: 3, total: 8, pages: 3}})
.should.throwError('All values must be defined for page, pages, limit and total');
runErrorTest({pagination: {page: 3, limit: 15, pages: 3}})
.should.throwError('All values must be defined for page, pages, limit and total');
runErrorTest({pagination: {page: 3, limit: 15, total: 8}})
.should.throwError('All values must be defined for page, pages, limit and total');
runErrorTest({pagination: {page: null, prev: 2, next: null, limit: 15, total: 8, pages: 3}})
runErrorTest({pagination: {page: null, limit: 15, total: 8, pages: 3}})
.should.throwError('Invalid value, check page, pages, limit and total are numbers');
runErrorTest({pagination: {page: 1, prev: 2, next: null, limit: null, total: 8, pages: 3}})
runErrorTest({pagination: {page: 1, limit: null, total: 8, pages: 3}})
.should.throwError('Invalid value, check page, pages, limit and total are numbers');
runErrorTest({pagination: {page: 1, prev: 2, next: null, limit: 15, total: null, pages: 3}})
runErrorTest({pagination: {page: 1, limit: 15, total: null, pages: 3}})
.should.throwError('Invalid value, check page, pages, limit and total are numbers');
runErrorTest({pagination: {page: 1, prev: 2, next: null, limit: 15, total: 8, pages: null}})
runErrorTest({pagination: {page: 1, limit: 15, total: 8, pages: null}})
.should.throwError('Invalid value, check page, pages, limit and total are numbers');
done();