test(pagination): add test for pagination utils

This commit is contained in:
07akioni 2019-06-27 15:29:39 +08:00
parent c1e8799e98
commit f0397ff39b
3 changed files with 35 additions and 6 deletions

View File

@ -1,3 +1,4 @@
/* istanbul ignore file */
import NCheckbox from './src/main.vue'
NCheckbox.install = function (Vue) {

View File

@ -42,9 +42,8 @@ function pagesToShow (currentPage, pageCount) {
return items
}
function pageItems (currentPage, pageCount) {
const pages = pagesToShow(currentPage, pageCount)
const items = pages.map(page => {
function mapPagesToPageItems (pages, currentPage) {
return pages.map(page => {
switch (page) {
case -2:
return {
@ -67,12 +66,17 @@ function pageItems (currentPage, pageCount) {
return {
type: 'page',
label: page,
activa: false
active: false
}
}
}
})
}
function pageItems (currentPage, pageCount) {
const pages = pagesToShow(currentPage, pageCount)
const items = mapPagesToPageItems(pages, currentPage)
return items
}
export { pagesToShow, pageItems }
export { pagesToShow, mapPagesToPageItems, pageItems }

View File

@ -1,4 +1,4 @@
import { pagesToShow } from 'packages/common/Pagination/src/utils'
import { pagesToShow, mapPagesToPageItems } from 'packages/common/Pagination/src/utils'
describe('Pagination', function () {
describe('utils', function () {
@ -57,5 +57,29 @@ describe('Pagination', function () {
expect(pagesToShow(9, 9)).to.deep.equal([1, -2, 5, 6, 7, 8, 9])
})
})
describe('#mapPagesToPageItems', function () {
it('should return corresponding items', function () {
expect(mapPagesToPageItems([-2, -1, 1, 2], 1)).to.deep.equal([
{
type: 'fastBackward',
label: 'fastBackward'
},
{
type: 'fastForward',
label: 'fastForward'
},
{
type: 'page',
label: 1,
active: true
},
{
type: 'page',
label: 2,
active: false
}
])
})
})
})
})