mirror of
https://github.com/tusen-ai/naive-ui.git
synced 2025-04-12 14:40:47 +08:00
fix(pagination): endIndex is incorrect if there's only 1 page of data (#4058)
* fix(pagination): `endIndex` calc incorrect, closes #4057 * test(pagination): pagination info
This commit is contained in:
parent
67485b0bfd
commit
2e343130d3
@ -45,6 +45,7 @@
|
||||
- Fix `n-popover` doesn't wrap line if word is too long.
|
||||
- Fix `n-date-picker` can't delete all input content in some cases, closes [#3922](https://github.com/tusen-ai/naive-ui/issues/3922).
|
||||
- Fix `n-input`'s `autosize` prop doesn't work properly if there are multiple spaces, closes [#4027](https://github.com/tusen-ai/naive-ui/issues/4027).
|
||||
- Fix `n-pagination`'s `endIndex` calc incorrect,closes [#4057](https://github.com/tusen-ai/naive-ui/issues/4057)
|
||||
|
||||
### i18n
|
||||
|
||||
|
@ -44,6 +44,7 @@
|
||||
- 修复 `n-timeline-item` 在 `n-timeline` 设定 `horizontal` 之后,`line-type="dashed"` 不生效,关闭 [#4014](https://github.com/tusen-ai/naive-ui/issues/4014)
|
||||
- 修复 `n-popover` 在英文和数字过长时不断行
|
||||
- 修复 `n-input` 的属性 `autosize` 在输入包含多个空格的时候表现不正确,关闭 [#4027](https://github.com/tusen-ai/naive-ui/issues/4027)
|
||||
- 修复 `n-pagination` 的 `endIndex` 计算错误,关闭 [#4057](https://github.com/tusen-ai/naive-ui/issues/4057)
|
||||
|
||||
### i18n
|
||||
|
||||
|
@ -271,7 +271,7 @@ export default defineComponent({
|
||||
const endIndex = mergedPageRef.value * mergedPageSizeRef.value - 1
|
||||
const { itemCount } = props
|
||||
if (itemCount !== undefined) {
|
||||
return endIndex > itemCount ? itemCount : endIndex
|
||||
return endIndex > itemCount - 1 ? itemCount - 1 : endIndex
|
||||
}
|
||||
return endIndex
|
||||
})
|
||||
|
@ -1,6 +1,6 @@
|
||||
import { h } from 'vue'
|
||||
import { mount } from '@vue/test-utils'
|
||||
import { NPagination, PaginationRenderLabel } from '../index'
|
||||
import { NPagination, PaginationRenderLabel, PaginationInfo } from '../index'
|
||||
|
||||
describe('n-pagination', () => {
|
||||
it('should work with import on demand', () => {
|
||||
@ -33,6 +33,36 @@ describe('n-pagination', () => {
|
||||
})
|
||||
expect(wrapper.findAll('.n-pagination-item').length).toEqual(4)
|
||||
})
|
||||
it('should work with corrent pagination info', async () => {
|
||||
let paginationInfo: PaginationInfo | undefined
|
||||
const wrapper = mount(NPagination, {
|
||||
props: {
|
||||
itemCount: 1,
|
||||
pageSize: 10,
|
||||
prefix: (info: PaginationInfo) => {
|
||||
paginationInfo = info
|
||||
}
|
||||
}
|
||||
})
|
||||
expect(wrapper.findAll('.n-pagination-item').length).toEqual(3)
|
||||
expect(paginationInfo?.itemCount).toBe(1)
|
||||
expect(paginationInfo?.page).toBe(1)
|
||||
expect(paginationInfo?.pageCount).toBe(1)
|
||||
expect(paginationInfo?.pageSize).toBe(10)
|
||||
expect(paginationInfo?.startIndex).toBe(0)
|
||||
expect(paginationInfo?.endIndex).toBe(0)
|
||||
await wrapper.setProps({
|
||||
itemCount: 12,
|
||||
pageSize: 5,
|
||||
page: 3
|
||||
})
|
||||
expect(paginationInfo?.itemCount).toBe(12)
|
||||
expect(paginationInfo?.pageSize).toBe(5)
|
||||
expect(paginationInfo?.page).toBe(3)
|
||||
expect(paginationInfo?.pageCount).toBe(3)
|
||||
expect(paginationInfo?.startIndex).toBe(10)
|
||||
expect(paginationInfo?.endIndex).toBe(11)
|
||||
})
|
||||
it('should work with prev slot', async () => {
|
||||
const wrapper = mount(NPagination, {
|
||||
slots: {
|
||||
|
Loading…
x
Reference in New Issue
Block a user