Skip to content

Commit

Permalink
fix(pagination): correctly use 1-based pagination in createURL (#5798)
Browse files Browse the repository at this point in the history
* WIP

* tests
  • Loading branch information
Haroenv authored Aug 8, 2023
1 parent 6f136ec commit 69ec7de
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ const connectPagination: PaginationConnector = function connectPagination(
connectorState.createURL = (page) =>
createURL((uiState) => ({
...uiState,
page,
page: page + 1,
}));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2025,7 +2025,7 @@ describe('Pagination', () => {
});

test('renders with translations', async () => {
const { getByRole, findByRole, debug } = render(
const { getByRole, findByRole } = render(
<InstantSearchTestWrapper
searchClient={createMockedSearchClient({ nbPages: 3 })}
>
Expand Down Expand Up @@ -2066,8 +2066,6 @@ describe('Pagination', () => {
});
expect(firstPageLink).toHaveTextContent('First');

debug();

const previousPageLink = getByRole('link', {
name: 'Previous page',
});
Expand Down
12 changes: 6 additions & 6 deletions tests/common/connectors/pagination/routing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export function createRoutingTests(
// eslint-disable-next-line jest/no-conditional-expect
expect(link).toHaveAttribute(
'href',
router.createURL({ indexName: { page: 10 } })
router.createURL({ indexName: { page: 11 } })
);
}
}
Expand All @@ -80,7 +80,7 @@ export function createRoutingTests(
{
expect(screen.getByTestId('Pagination-link')).toHaveAttribute(
'href',
router.createURL({ indexName: { page: 10 } })
router.createURL({ indexName: { page: 11 } })
);
}

Expand All @@ -96,7 +96,7 @@ export function createRoutingTests(
// URL is still the same, as it overrides the current state
expect(screen.getByTestId('Pagination-link')).toHaveAttribute(
'href',
router.createURL({ indexName: { page: 10 } })
router.createURL({ indexName: { page: 11 } })
);
}

Expand All @@ -108,7 +108,7 @@ export function createRoutingTests(

expect(screen.getByTestId('Pagination-link')).toHaveAttribute(
'href',
router.createURL({ indexName: { page: 10 } })
router.createURL({ indexName: { page: 11 } })
);
}

Expand All @@ -124,7 +124,7 @@ export function createRoutingTests(
// URL is still the same, as it overrides the current state
expect(screen.getByTestId('Pagination-link')).toHaveAttribute(
'href',
router.createURL({ indexName: { page: 10 } })
router.createURL({ indexName: { page: 11 } })
);
}

Expand All @@ -137,7 +137,7 @@ export function createRoutingTests(

expect(screen.getByTestId('Pagination-link')).toHaveAttribute(
'href',
router.createURL({ indexName: { page: 10 } })
router.createURL({ indexName: { page: 11 } })
);
}
});
Expand Down
40 changes: 15 additions & 25 deletions tests/common/shared/routing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,7 @@ export function createRoutingTests(
// eslint-disable-next-line jest/no-conditional-expect
expect(paginationLink).toHaveAttribute(
'href',
router.createURL({
indexName: {
page: 10,
},
})
router.createURL({ indexName: { page: 11 } })
);
}
}
Expand All @@ -124,9 +120,7 @@ export function createRoutingTests(

expect(screen.getByTestId('Pagination-link')).toHaveAttribute(
'href',
router.createURL({
indexName: { page: 10 },
})
router.createURL({ indexName: { page: 11 } })
);
}

Expand All @@ -149,12 +143,12 @@ export function createRoutingTests(
})
);

// expect(screen.getByTestId('Pagination-link')).toHaveAttribute(
// 'href',
// router.createURL({
// indexName: { menu: { [attribute]: 'Apple' }, page: 10 },
// })
// );
expect(screen.getByTestId('Pagination-link')).toHaveAttribute(
'href',
router.createURL({
indexName: { menu: { [attribute]: 'Apple' }, page: 11 },
})
);
}

// Wait for new results to come in
Expand All @@ -173,7 +167,7 @@ export function createRoutingTests(
expect(screen.getByTestId('Pagination-link')).toHaveAttribute(
'href',
router.createURL({
indexName: { menu: { [attribute]: 'Apple' }, page: 10 },
indexName: { menu: { [attribute]: 'Apple' }, page: 11 },
})
);
}
Expand All @@ -199,9 +193,7 @@ export function createRoutingTests(

expect(screen.getByTestId('Pagination-link')).toHaveAttribute(
'href',
router.createURL({
indexName: { page: 10 },
})
router.createURL({ indexName: { page: 11 } })
);
}

Expand All @@ -220,9 +212,7 @@ export function createRoutingTests(

expect(screen.getByTestId('Pagination-link')).toHaveAttribute(
'href',
router.createURL({
indexName: { page: 10 },
})
router.createURL({ indexName: { page: 11 } })
);
}

Expand All @@ -238,7 +228,7 @@ export function createRoutingTests(
// URL is still the same, as it overrides the current state
expect(screen.getByTestId('Pagination-link')).toHaveAttribute(
'href',
router.createURL({ indexName: { page: 10 } })
router.createURL({ indexName: { page: 11 } })
);

expect(screen.getByTestId('Menu-link')).toHaveAttribute(
Expand All @@ -257,7 +247,7 @@ export function createRoutingTests(

expect(screen.getByTestId('Pagination-link')).toHaveAttribute(
'href',
router.createURL({ indexName: { page: 10 } })
router.createURL({ indexName: { page: 11 } })
);

expect(screen.getByTestId('Menu-link')).toHaveAttribute(
Expand All @@ -280,7 +270,7 @@ export function createRoutingTests(
// URL is still the same, as it overrides the current state
expect(screen.getByTestId('Pagination-link')).toHaveAttribute(
'href',
router.createURL({ indexName: { page: 10 } })
router.createURL({ indexName: { page: 11 } })
);

expect(screen.getByTestId('Menu-link')).toHaveAttribute(
Expand All @@ -300,7 +290,7 @@ export function createRoutingTests(

expect(screen.getByTestId('Pagination-link')).toHaveAttribute(
'href',
router.createURL({ indexName: { page: 10 } })
router.createURL({ indexName: { page: 11 } })
);

expect(screen.getByTestId('Menu-link')).toHaveAttribute(
Expand Down

0 comments on commit 69ec7de

Please sign in to comment.