Skip to content

Commit

Permalink
fix(signals): fix change page size not working after second change on…
Browse files Browse the repository at this point in the history
… same page

Fix #100
  • Loading branch information
Gabriel Guerrero authored and gabrielguerrero committed Jun 7, 2024
1 parent 52e9976 commit fe18164
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ describe('withEntitiesRemotePagination', () => {

store.loadEntitiesPage({ pageIndex: 1, pageSize: 15 });
tick();
// check the second page
// check the first page on the new page size
expect(store.entitiesCurrentPage().entities.length).toEqual(15);
expect(store.entitiesCurrentPage().entities).toEqual(
mockProducts.slice(0, 15),
Expand All @@ -143,9 +143,27 @@ describe('withEntitiesRemotePagination', () => {
expect(store.entitiesCurrentPage().hasPrevious).toEqual(false);
expect(store.entitiesCurrentPage().hasNext).toEqual(true);

store.loadEntitiesPage({ pageIndex: 2 });
store.loadEntitiesPage({ pageIndex: 1, pageSize: 10 });
tick();

// check we can go back to the original page size
expect(store.entitiesCurrentPage().entities.length).toEqual(10);
expect(store.entitiesCurrentPage().entities).toEqual(
mockProducts.slice(0, 10),
);
expect(store.entitiesCurrentPage().pageIndex).toEqual(0);
expect(store.entitiesCurrentPage().pageSize).toEqual(10);
expect(store.entitiesCurrentPage().pagesCount).toEqual(4);
expect(store.entitiesCurrentPage().total).toEqual(40);
expect(store.entitiesCurrentPage().hasPrevious).toEqual(false);
expect(store.entitiesCurrentPage().hasNext).toEqual(true);

// switch back to the 15 page size
store.loadEntitiesPage({ pageIndex: 0, pageSize: 15 });
tick();
// check the third page
store.loadEntitiesPage({ pageIndex: 2 });
tick();
expect(store.entitiesCurrentPage().pageIndex).toEqual(2);
expect(store.entitiesCurrentPage().entities.length).toEqual(10);
expect(store.entitiesCurrentPage().entities).toEqual(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,9 @@ export function withEntitiesRemotePagination<
pipe(
distinctUntilChanged(
(previous, current) =>
!current.forceLoad && previous.pageIndex === current.pageIndex,
!current.forceLoad &&
previous.pageIndex === current.pageIndex &&
previous.pageSize === current.pageSize,
),
exhaustMap(({ pageIndex, forceLoad, pageSize }) =>
$loading.pipe(
Expand Down

0 comments on commit fe18164

Please sign in to comment.