Skip to content

Commit

Permalink
fix: DiffScene Page Displays Accurate Number of Diff Entries (#1163)
Browse files Browse the repository at this point in the history
* Bug fix to DiffScene displayed diff entries with unit test

* Additional test validating page display on following page
  • Loading branch information
patnir41 authored Aug 23, 2022
1 parent 23b3dbf commit ee46932
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,61 @@ describe('DocDiff', () => {
).toBeInTheDocument()
})
})

it('paginates with correct number of entries per page', async () => {
const delta = diffSpecs(leftApi, rightApi, standardDiffToggles)
const pageSize = 5
renderWithReduxProvider(
<DocDiff
leftKey={leftKey}
leftSpec={leftApi}
rightKey={rightKey}
rightSpec={rightApi}
delta={delta}
pageSize={pageSize}
/>
)

for (let i = 0; i < pageSize; i++) {
const row = delta[i]
expect(screen.getByText(row.name)).toBeInTheDocument()
expect(screen.getByText(row.id)).toBeInTheDocument()
expect(
screen.getByText(rightApi.methods[row.name].summary)
).toBeInTheDocument()
}
const notDisplayedRow = delta[pageSize]
expect(screen.queryByText(notDisplayedRow.name)).not.toBeInTheDocument()
})

it('final diff entry of one page does not appear in next page', async () => {
const delta = diffSpecs(leftApi, rightApi, standardDiffToggles)
const pageSize = 5
renderWithReduxProvider(
<DocDiff
leftKey={leftKey}
leftSpec={leftApi}
rightKey={rightKey}
rightSpec={rightApi}
delta={delta}
pageSize={pageSize}
/>
)
const lastPageEntry = delta[pageSize - 1]
expect(screen.getByText(lastPageEntry.name)).toBeInTheDocument()
expect(screen.getByText(lastPageEntry.id)).toBeInTheDocument()
expect(
screen.getByText(rightApi.methods[lastPageEntry.name].summary)
).toBeInTheDocument()

// go to page 2
userEvent.click(
screen.getByRole('button', { name: 'Next page of results' })
)

await waitFor(() => {
expect(screen.queryByText(lastPageEntry.name)).not.toBeInTheDocument()
expect(screen.queryByText(lastPageEntry.id)).not.toBeInTheDocument()
})
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export const DocDiff: FC<DocDiffProps> = ({
if (delta.length === 0) return <Text>{'No differences found'}</Text>

const pageCount = Math.round((delta.length - 1) / pageSize)
const pageItemData = delta.slice((page - 1) * pageSize, page * pageSize + 1)
const pageItemData = delta.slice((page - 1) * pageSize, page * pageSize)

return (
<>
Expand Down

0 comments on commit ee46932

Please sign in to comment.