From c615be3ef07739613ea60991edd68b3e33a871db Mon Sep 17 00:00:00 2001 From: Jordan Date: Mon, 22 Mar 2021 10:22:05 +0100 Subject: [PATCH 1/2] [BUGFIX] Fixed issue where clicking the backbutton wouldn't respond the first time --- .../peregrine/lib/talons/RootComponents/Category/useCategory.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/peregrine/lib/talons/RootComponents/Category/useCategory.js b/packages/peregrine/lib/talons/RootComponents/Category/useCategory.js index ff420b33b9..58205502df 100644 --- a/packages/peregrine/lib/talons/RootComponents/Category/useCategory.js +++ b/packages/peregrine/lib/talons/RootComponents/Category/useCategory.js @@ -192,7 +192,7 @@ export const useCategory = props => { currentSort.sortDirection.toString() ) { // The search term changed. - setCurrentPage(1); + setCurrentPage(1, true); // And update the ref. previousSearch.current = search; previousSort.current = currentSort; From 9e030de517a9066016d6003514ef3b296108945e Mon Sep 17 00:00:00 2001 From: Anthoula Wojczak Date: Mon, 12 Apr 2021 13:57:42 -0500 Subject: [PATCH 2/2] PWA-1594: [bug]: browser back buttons isn't responsive - add test coverage for setCurrentPage --- .../Category/__tests__/useCategory.spec.js | 29 +++++++++++++++++-- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/packages/peregrine/lib/talons/RootComponents/Category/__tests__/useCategory.spec.js b/packages/peregrine/lib/talons/RootComponents/Category/__tests__/useCategory.spec.js index acd6c19968..8d14df825e 100644 --- a/packages/peregrine/lib/talons/RootComponents/Category/__tests__/useCategory.spec.js +++ b/packages/peregrine/lib/talons/RootComponents/Category/__tests__/useCategory.spec.js @@ -45,7 +45,9 @@ jest.mock('../../../../hooks/usePagination', () => ({ { setCurrentPage: jest .fn() - .mockImplementation(page => mockSetCurrentPage(page)), + .mockImplementation((page, bool = false) => + mockSetCurrentPage(page, bool) + ), setTotalPages: jest.fn() } ]) @@ -179,7 +181,7 @@ test('resets the current page on error', () => { createTestInstance(); expect(mockSetCurrentPage).toHaveBeenCalledTimes(1); - expect(mockSetCurrentPage).toHaveBeenCalledWith(1); + expect(mockSetCurrentPage).toHaveBeenCalledWith(1, false); }); test('handles no filter type data available', () => { @@ -256,7 +258,7 @@ test('sets current page to 1 if error, !loading, !data, and currentPage != 1', ( createTestInstance(); - expect(mockSetCurrentPage).toHaveBeenCalledWith(1); + expect(mockSetCurrentPage).toHaveBeenCalledWith(1, false); }); const testCases = [ @@ -305,3 +307,24 @@ test.each(testCases)( expect(mockSetCurrentPage).toHaveBeenCalledTimes(expected); } ); + +test('preserve history when search term changes', () => { + useQuery.mockReturnValue(mockPageSizeData); + useLazyQuery.mockReturnValue([mockRunQuery, mockCategoryData]); + + const tree = createTestInstance(); + + mockUseSort.mockReturnValueOnce([ + { + sortText: 'Best Match', + sortAttribute: 'relevance', + sortDirection: 'Changed' + }, + jest.fn() + ]); + expect(mockSetCurrentPage).not.toHaveBeenCalledWith(1, true); + act(() => { + tree.update(); + }); + expect(mockSetCurrentPage).toHaveBeenCalledWith(1, true); +});