mirror of
https://github.com/langgenius/dify.git
synced 2026-09-19 02:07:44 +08:00
fix(dify-ui): refine pagination navigation semantics (#40723)
This commit is contained in:
@@ -305,6 +305,11 @@ const createWrapper = () => {
|
||||
)
|
||||
}
|
||||
|
||||
const getPageSummaryButton = (page: number, totalPages: number) =>
|
||||
screen.getByRole('button', {
|
||||
name: `common.pagination.editPageNumber:{"page":${page},"totalPages":${totalPages}}`,
|
||||
})
|
||||
|
||||
describe('SegmentListContext', () => {
|
||||
describe('Default Values', () => {
|
||||
it('should have correct default context values', () => {
|
||||
@@ -497,12 +502,10 @@ describe('Completed Component', () => {
|
||||
|
||||
describe('Pagination', () => {
|
||||
it('should start on the first page', () => {
|
||||
mockSegmentListData.total = 30
|
||||
render(<Completed {...defaultProps} />, { wrapper: createWrapper() })
|
||||
|
||||
expect(screen.getByRole('navigation', { name: 'Pagination' })).toHaveAttribute(
|
||||
'data-page',
|
||||
'1',
|
||||
)
|
||||
expect(getPageSummaryButton(1, 3)).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('should update page when pagination changes', async () => {
|
||||
@@ -513,10 +516,7 @@ describe('Completed Component', () => {
|
||||
fireEvent.click(nextPageButton)
|
||||
|
||||
await waitFor(() => {
|
||||
expect(screen.getByRole('navigation', { name: 'Pagination' })).toHaveAttribute(
|
||||
'data-page',
|
||||
'2',
|
||||
)
|
||||
expect(getPageSummaryButton(2, 3)).toBeInTheDocument()
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1082,19 +1082,13 @@ describe('Inline callback and hook initialization coverage', () => {
|
||||
|
||||
fireEvent.click(screen.getByRole('button', { name: 'common.pagination.next' }))
|
||||
await waitFor(() => {
|
||||
expect(screen.getByRole('navigation', { name: 'Pagination' })).toHaveAttribute(
|
||||
'data-page',
|
||||
'2',
|
||||
)
|
||||
expect(getPageSummaryButton(2, 3)).toBeInTheDocument()
|
||||
})
|
||||
|
||||
fireEvent.click(screen.getByTestId('status-enabled'))
|
||||
|
||||
await waitFor(() => {
|
||||
expect(screen.getByRole('navigation', { name: 'Pagination' })).toHaveAttribute(
|
||||
'data-page',
|
||||
'1',
|
||||
)
|
||||
expect(getPageSummaryButton(1, 3)).toBeInTheDocument()
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1207,28 +1201,6 @@ describe('Inline callback and hook initialization coverage', () => {
|
||||
})
|
||||
})
|
||||
|
||||
// Covers line 133-135: handlePageChange
|
||||
it('should handle multiple page changes', async () => {
|
||||
mockSegmentListData.total = 30
|
||||
render(<Completed {...defaultProps} />, { wrapper: createWrapper() })
|
||||
|
||||
fireEvent.click(screen.getByRole('button', { name: 'common.pagination.next' }))
|
||||
await waitFor(() => {
|
||||
expect(screen.getByRole('navigation', { name: 'Pagination' })).toHaveAttribute(
|
||||
'data-page',
|
||||
'2',
|
||||
)
|
||||
})
|
||||
|
||||
fireEvent.click(screen.getByRole('button', { name: 'common.pagination.next' }))
|
||||
await waitFor(() => {
|
||||
expect(screen.getByRole('navigation', { name: 'Pagination' })).toHaveAttribute(
|
||||
'data-page',
|
||||
'3',
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
it('should compute pagination pages from child chunk data in full-doc mode', () => {
|
||||
mockDocForm.current = ChunkingModeEnum.parentChild
|
||||
mockParentMode.current = 'full-doc'
|
||||
@@ -1236,10 +1208,7 @@ describe('Inline callback and hook initialization coverage', () => {
|
||||
|
||||
render(<Completed {...defaultProps} />, { wrapper: createWrapper() })
|
||||
|
||||
expect(screen.getByRole('navigation', { name: 'Pagination' })).toHaveAttribute(
|
||||
'data-totalpages',
|
||||
'5',
|
||||
)
|
||||
expect(getPageSummaryButton(1, 5)).toBeInTheDocument()
|
||||
})
|
||||
|
||||
// Covers search input change
|
||||
|
||||
Reference in New Issue
Block a user