Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUGFIX] The browser back button wasn't responding #3078

Merged
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
])
Expand Down Expand Up @@ -179,7 +181,7 @@ test('resets the current page on error', () => {
createTestInstance(<Component {...mockProps} />);

expect(mockSetCurrentPage).toHaveBeenCalledTimes(1);
expect(mockSetCurrentPage).toHaveBeenCalledWith(1);
expect(mockSetCurrentPage).toHaveBeenCalledWith(1, false);
});

test('handles no filter type data available', () => {
Expand Down Expand Up @@ -256,7 +258,7 @@ test('sets current page to 1 if error, !loading, !data, and currentPage != 1', (

createTestInstance(<Component {...mockProps} />);

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

const testCases = [
Expand Down Expand Up @@ -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(<Component {...mockProps} />);

mockUseSort.mockReturnValueOnce([
{
sortText: 'Best Match',
sortAttribute: 'relevance',
sortDirection: 'Changed'
},
jest.fn()
]);
expect(mockSetCurrentPage).not.toHaveBeenCalledWith(1, true);
act(() => {
tree.update(<Component {...mockProps} />);
});
expect(mockSetCurrentPage).toHaveBeenCalledWith(1, true);
});
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down