Skip to content

Commit

Permalink
fix: rerendering issues on DiffScene options change (#1168)
Browse files Browse the repository at this point in the history
* Allow correct card to be rendered on rerender after toggling comparison options

* Fix for pageCount calculation to use ceil rather than round
  • Loading branch information
patnir41 authored Aug 30, 2022
1 parent b01770c commit a4ac3bc
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ describe('DocDiff', () => {
const rightKey = specs['4.0'].key
const leftApi = specs['3.1'].api!
const rightApi = specs['4.0'].api!
const delta = diffSpecs(leftApi, rightApi, standardDiffToggles)

it('renders', () => {
const delta = diffSpecs(leftApi, rightApi, standardDiffToggles)
renderWithReduxProvider(
<DocDiff
leftKey={leftKey}
Expand All @@ -61,6 +61,7 @@ describe('DocDiff', () => {
screen.getByRole('button', { name: 'Next page of results' })
).toBeInTheDocument()
})

it('renders when there is no delta', () => {
renderWithReduxProvider(
<DocDiff
Expand All @@ -75,7 +76,6 @@ describe('DocDiff', () => {
})

it('paginates', async () => {
const delta = diffSpecs(leftApi, rightApi, standardDiffToggles)
renderWithReduxProvider(
<DocDiff
leftKey={leftKey}
Expand Down Expand Up @@ -111,7 +111,6 @@ describe('DocDiff', () => {
})

it('paginates with correct number of entries per page', async () => {
const delta = diffSpecs(leftApi, rightApi, standardDiffToggles)
const pageSize = 5
renderWithReduxProvider(
<DocDiff
Expand All @@ -136,8 +135,23 @@ describe('DocDiff', () => {
expect(screen.queryByText(notDisplayedRow.name)).not.toBeInTheDocument()
})

it('paginates with correct total page count', async () => {
const pageSize = 5
renderWithReduxProvider(
<DocDiff
leftKey={leftKey}
leftSpec={leftApi}
rightKey={rightKey}
rightSpec={rightApi}
delta={delta}
pageSize={pageSize}
/>
)
const expectedPageCount = Math.ceil(delta.length / pageSize)
expect(screen.getByText(`of ${expectedPageCount}`)).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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,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 pageCount = Math.ceil(delta.length / pageSize)
const pageItemData = delta.slice((page - 1) * pageSize, page * pageSize)

return (
Expand All @@ -76,9 +76,9 @@ export const DocDiff: FC<DocDiffProps> = ({
<Heading as="h2">{`${delta.length} differences between ${leftKey} and ${rightKey}`}</Heading>
</Space>
<SpaceVertical mt="large" gap="xxsmall">
{pageItemData.map((item, index) => (
{pageItemData.map((item) => (
<DiffItem
key={`page-${page} item-${index}`}
key={item.name}
item={item}
leftKey={leftKey}
leftSpec={leftSpec}
Expand Down

0 comments on commit a4ac3bc

Please sign in to comment.