Skip to content

Commit

Permalink
[DEV-6748] keeping history.replace() UX in place.
Browse files Browse the repository at this point in the history
I tried to do history.push() so you could reload previous
hashes, but it's not as straight forward as I thought it would
be, so I'm removing it from the scope of this PR and into
[DEV-6783](https://federal-spending-transparency.atlassian.net/browse/DEV-6783)
  • Loading branch information
MaxwellKendall committed Feb 5, 2021
1 parent de857f8 commit 74b5b93
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/js/containers/search/SearchContainer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ const SearchContainer = ({ history }) => {
request.current.promise
.then((res) => {
// update the URL with the received hash
history.push({
history.replace({
pathname: `/search/`,
search: `?${new URLSearchParams({ hash: res.data.hash }).toString()}`
});
Expand Down
10 changes: 5 additions & 5 deletions tests/containers/search/SearchContainer-test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ test('a hashed url makes a request to the api & sets loading state', async () =>
test('when filters change (a) hash is generated, (b) loading is set & (c) url is updated', async () => {
restoreUrlHash.mockClear();
const setLoading = jest.spyOn(appliedFilterActions, 'setAppliedFilterEmptiness');
const mockPush = jest.fn();
const { rerender } = render(<SearchContainer history={{ push: mockPush }} />, {});
const mockReplace = jest.fn();
const { rerender } = render(<SearchContainer history={{ replace: mockReplace }} />, {});

jest.spyOn(redux, 'useSelector').mockReturnValue({
...mockRedux,
Expand All @@ -112,12 +112,12 @@ test('when filters change (a) hash is generated, (b) loading is set & (c) url is
}
});

rerender(<SearchContainer history={{ push: mockPush }} />, {});
rerender(<SearchContainer history={{ replace: mockReplace }} />, {});

await waitFor(() => {
expect(generateUrlHash).toHaveBeenCalledTimes(1);
expect(mockPush).toHaveBeenCalledTimes(1);
expect(mockPush).toHaveBeenLastCalledWith({
expect(mockReplace).toHaveBeenCalledTimes(1);
expect(mockReplace).toHaveBeenLastCalledWith({
pathname: '/search/',
// not ?hash=str because we aren't mocking out new URLSearchParams
search: '?str'
Expand Down

0 comments on commit 74b5b93

Please sign in to comment.