mirror of
https://github.com/tusen-ai/naive-ui.git
synced 2025-04-12 14:40:47 +08:00
test(pagination): add test for pagination utils
This commit is contained in:
parent
c1e8799e98
commit
f0397ff39b
@ -1,3 +1,4 @@
|
||||
/* istanbul ignore file */
|
||||
import NCheckbox from './src/main.vue'
|
||||
|
||||
NCheckbox.install = function (Vue) {
|
||||
|
@ -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 }
|
||||
|
@ -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
|
||||
}
|
||||
])
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
Loading…
x
Reference in New Issue
Block a user