Skip to content

Commit

Permalink
Merge pull request #3257 from sagarbakhtar/reset-page-on-perPage-change
Browse files Browse the repository at this point in the history
[RFR] Reset page on per page count change
  • Loading branch information
djhi authored May 21, 2019
2 parents 26765f3 + 1c44b15 commit d04af4c
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -132,4 +132,31 @@ describe('Query Reducer', () => {
});
});
});
describe('SET_PER_PAGE action', () => {
it('should update per page count', () => {
const updatedState = queryReducer(
{
perPage: 10,
},
{
type: 'SET_PER_PAGE',
payload: 25,
}
);
assert.equal(updatedState.perPage, 25);
});
it('should reset page to 1', () => {
const updatedState = queryReducer(
{
page: 5,
perPage: 10,
},
{
type: 'SET_PER_PAGE',
payload: 25,
}
);
assert.equal(updatedState.page, 1);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const queryReducer: Reducer<ListParams> = (
return { ...previousState, page: payload };

case SET_PER_PAGE:
return { ...previousState, perPage: payload };
return { ...previousState, page: 1, perPage: payload };

case SET_FILTER: {
return { ...previousState, page: 1, filter: payload };
Expand Down

0 comments on commit d04af4c

Please sign in to comment.