From 303e364b9943481eaad6827bd6715f113107713d Mon Sep 17 00:00:00 2001 From: huykon225 Date: Wed, 14 Apr 2021 10:16:52 +0700 Subject: [PATCH 1/3] Fix browser back buttons isn't responsive --- .../lib/talons/SearchPage/__tests__/useSearchPage.spec.js | 4 +++- packages/peregrine/lib/talons/SearchPage/useSearchPage.js | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/peregrine/lib/talons/SearchPage/__tests__/useSearchPage.spec.js b/packages/peregrine/lib/talons/SearchPage/__tests__/useSearchPage.spec.js index 46dd7cd1cb..83cd849783 100644 --- a/packages/peregrine/lib/talons/SearchPage/__tests__/useSearchPage.spec.js +++ b/packages/peregrine/lib/talons/SearchPage/__tests__/useSearchPage.spec.js @@ -54,7 +54,9 @@ jest.mock('../../../hooks/usePagination', () => ({ { setCurrentPage: jest .fn() - .mockImplementation(() => mockSetCurrentPage()), + .mockImplementation((page, bool = false) => + mockSetCurrentPage(page, bool) + ), setTotalPages: jest.fn() } ]) diff --git a/packages/peregrine/lib/talons/SearchPage/useSearchPage.js b/packages/peregrine/lib/talons/SearchPage/useSearchPage.js index 5a8a53d524..885f41ee4c 100644 --- a/packages/peregrine/lib/talons/SearchPage/useSearchPage.js +++ b/packages/peregrine/lib/talons/SearchPage/useSearchPage.js @@ -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; From 14a9590c5622bdbdb197e64460e3ed5284e23f83 Mon Sep 17 00:00:00 2001 From: Anthoula Wojczak Date: Wed, 14 Apr 2021 14:50:48 -0500 Subject: [PATCH 2/3] PWA-1671: [bug]: browser back buttons isn't responsive on Search Page - add test coverage for setCurrentPage --- .../SearchPage/__tests__/useSearchPage.spec.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/packages/peregrine/lib/talons/SearchPage/__tests__/useSearchPage.spec.js b/packages/peregrine/lib/talons/SearchPage/__tests__/useSearchPage.spec.js index 83cd849783..4e3c05320a 100644 --- a/packages/peregrine/lib/talons/SearchPage/__tests__/useSearchPage.spec.js +++ b/packages/peregrine/lib/talons/SearchPage/__tests__/useSearchPage.spec.js @@ -154,6 +154,24 @@ 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(); + }); + + expect(mockSetCurrentPage).toHaveBeenCalledTimes(1); + expect(mockSetCurrentPage).toHaveBeenCalledWith(1, true); +}); + describe('searchCategory', () => { const log = jest.fn(); const Component = props => { From 72ce12c2fdde5e7f67729cc83d206b95b071dff5 Mon Sep 17 00:00:00 2001 From: Anthoula Wojczak Date: Wed, 14 Apr 2021 14:53:09 -0500 Subject: [PATCH 3/3] PWA-1671: [bug]: browser back buttons isn't responsive on Search Page - remove redundant assertion --- .../lib/talons/SearchPage/__tests__/useSearchPage.spec.js | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/peregrine/lib/talons/SearchPage/__tests__/useSearchPage.spec.js b/packages/peregrine/lib/talons/SearchPage/__tests__/useSearchPage.spec.js index 4e3c05320a..ccfa3f09b8 100644 --- a/packages/peregrine/lib/talons/SearchPage/__tests__/useSearchPage.spec.js +++ b/packages/peregrine/lib/talons/SearchPage/__tests__/useSearchPage.spec.js @@ -168,7 +168,6 @@ test('preserve history when search term changes on Search Page', () => { tree.update(); }); - expect(mockSetCurrentPage).toHaveBeenCalledTimes(1); expect(mockSetCurrentPage).toHaveBeenCalledWith(1, true); });