Skip to content

Commit

Permalink
Fix browser back buttons isn't responsive on Search Page (#3119)
Browse files Browse the repository at this point in the history
* Fix browser back buttons isn't responsive

* PWA-1671: [bug]: browser back buttons isn't responsive on Search Page

- add test coverage for setCurrentPage

* PWA-1671: [bug]: browser back buttons isn't responsive on Search Page

- remove redundant assertion

Co-authored-by: Anthoula Wojczak <awojczak@adobe.com>
  • Loading branch information
huykon and anthoula authored Apr 15, 2021
1 parent a7dbffe commit 9383ae7
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ jest.mock('../../../hooks/usePagination', () => ({
{
setCurrentPage: jest
.fn()
.mockImplementation(() => mockSetCurrentPage()),
.mockImplementation((page, bool = false) =>
mockSetCurrentPage(page, bool)
),
setTotalPages: jest.fn()
}
])
Expand Down Expand Up @@ -152,6 +154,23 @@ test.each(testCases)(
}
);

test('preserve history when search term changes on Search Page', () => {
mockUseSort.mockReturnValueOnce([
{
sortText: 'Best Match',
sortAttribute: 'Changed',
sortDirection: 'DESC'
},
jest.fn()
]);
expect(mockSetCurrentPage).not.toHaveBeenCalledWith(1, true);
act(() => {
tree.update(<Component {...mockProps} />);
});

expect(mockSetCurrentPage).toHaveBeenCalledWith(1, true);
});

describe('searchCategory', () => {
const log = jest.fn();
const Component = props => {
Expand Down
2 changes: 1 addition & 1 deletion packages/peregrine/lib/talons/SearchPage/useSearchPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ export const useSearchPage = (props = {}) => {
currentSort.sortDirection.toString()
) {
// The search term changed.
setCurrentPage(1);
setCurrentPage(1, true);
// And update the ref.
previousSearch.current = search;
previousSort.current = currentSort;
Expand Down

0 comments on commit 9383ae7

Please sign in to comment.