-
Notifications
You must be signed in to change notification settings - Fork 516
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Also code simplification
- Loading branch information
Alexandre Stanislawski
committed
Nov 23, 2015
1 parent
91e91f7
commit d8f1196
Showing
3 changed files
with
179 additions
and
9 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
../css/debug.css | ||
../src/css/debug.css |
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,161 @@ | ||
/* eslint-env mocha */ | ||
|
||
import expect from 'expect'; | ||
|
||
import Paginator from '../Paginator'; | ||
|
||
describe('paginator: simple cases', () => { | ||
context('on the first page', () => { | ||
const pager = new Paginator({ | ||
currentPage: 0, | ||
total: 10, | ||
padding: 2 | ||
}); | ||
|
||
it('should return the pages', () => { | ||
const pages = pager.pages(); | ||
expect(pages.length).toBe(5); | ||
expect(pages).toEqual([0, 1, 2, 3, 4]); | ||
}); | ||
|
||
it('should be the first page', () => { | ||
expect(pager.isFirstPage()).toBe(true); | ||
}); | ||
|
||
it('should not be the last page', () => { | ||
expect(pager.isLastPage()).toBe(false); | ||
}); | ||
}); | ||
|
||
context('on 3rd page', () => { | ||
const pager = new Paginator({ | ||
currentPage: 2, | ||
total: 10, | ||
padding: 2 | ||
}); | ||
|
||
it('should return the pages', () => { | ||
const pages = pager.pages(); | ||
expect(pages.length).toBe(5); | ||
expect(pages).toEqual([0, 1, 2, 3, 4]); | ||
}); | ||
|
||
it('should not be the first page', () => { | ||
expect(pager.isFirstPage()).toBe(false); | ||
}); | ||
|
||
it('should not be the last page', () => { | ||
expect(pager.isLastPage()).toBe(false); | ||
}); | ||
}); | ||
|
||
context('on 5th page', () => { | ||
const pager = new Paginator({ | ||
currentPage: 5, | ||
total: 10, | ||
padding: 2 | ||
}); | ||
|
||
it('should return the pages', () => { | ||
const pages = pager.pages(); | ||
expect(pages.length).toBe(5); | ||
expect(pages).toEqual([3, 4, 5, 6, 7]); | ||
}); | ||
|
||
it('should not be the first page', () => { | ||
expect(pager.isFirstPage()).toBe(false); | ||
}); | ||
|
||
it('should not be the last page', () => { | ||
expect(pager.isLastPage()).toBe(false); | ||
}); | ||
}); | ||
|
||
context('on the page before the last', () => { | ||
const pager = new Paginator({ | ||
currentPage: 8, | ||
total: 10, | ||
padding: 2 | ||
}); | ||
|
||
it('should return the pages', () => { | ||
const pages = pager.pages(); | ||
expect(pages.length).toBe(5); | ||
expect(pages).toEqual([5, 6, 7, 8, 9]); | ||
}); | ||
|
||
it('should not be the first page', () => { | ||
expect(pager.isFirstPage()).toBe(false); | ||
}); | ||
|
||
it('should not be the last page', () => { | ||
expect(pager.isLastPage()).toBe(false); | ||
}); | ||
}); | ||
|
||
context('on last page', () => { | ||
const pager = new Paginator({ | ||
currentPage: 9, | ||
total: 10, | ||
padding: 2 | ||
}); | ||
|
||
it('should return the pages', () => { | ||
const pages = pager.pages(); | ||
expect(pages.length).toBe(5); | ||
expect(pages).toEqual([5, 6, 7, 8, 9]); | ||
}); | ||
|
||
it('should not be the first page', () => { | ||
expect(pager.isFirstPage()).toBe(false); | ||
}); | ||
|
||
it('should not be the last page', () => { | ||
expect(pager.isLastPage()).toBe(true); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('paginator: number of pages is less than 2*padding+1', () => { | ||
const pager = new Paginator({ | ||
currentPage: 0, | ||
total: 1, | ||
padding: 2 | ||
}); | ||
|
||
it('should return the pages', () => { | ||
const pages = pager.pages(); | ||
expect(pages.length).toBe(1); | ||
expect(pages).toEqual([0]); | ||
}); | ||
|
||
it('should be the first page', () => { | ||
expect(pager.isFirstPage()).toBe(true); | ||
}); | ||
|
||
it('should not be the last page', () => { | ||
expect(pager.isLastPage()).toBe(true); | ||
}); | ||
}); | ||
|
||
describe('paginator: bug #668', () => { | ||
const pager = new Paginator({ | ||
currentPage: 4, | ||
total: 6, | ||
padding: 3 | ||
}); | ||
|
||
it('should return the pages', () => { | ||
const pages = pager.pages(); | ||
expect(pages.length).toBe(6); | ||
expect(pages).toEqual([0, 1, 2, 3, 4, 5]); | ||
}); | ||
|
||
it('should be the first page', () => { | ||
expect(pager.isFirstPage()).toBe(false); | ||
}); | ||
|
||
it('should not be the last page', () => { | ||
expect(pager.isLastPage()).toBe(false); | ||
}); | ||
}); |