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:
吉仔 2022-11-21 01:38:18 +08:00 committed by GitHub
parent 67485b0bfd
commit 2e343130d3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 34 additions and 2 deletions

View File

@ -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 incorrectcloses [#4057](https://github.com/tusen-ai/naive-ui/issues/4057)
### i18n

View File

@ -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

View File

@ -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
})

View File

@ -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: {