Skip to content

Commit

Permalink
Change tests to meet our goals by checking the case when region is no…
Browse files Browse the repository at this point in the history
…t set and search button is clicked. Fix region query parameter in SearchPanel
  • Loading branch information
grabinskij committed Dec 9, 2024
1 parent b1bf126 commit 346aba7
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/components/SearchPanel/SearchPanel.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const SearchPanel = () => {
// Search handler for desktop
const handleAirbnbSearch = ({ location: region, checkIn, checkOut, adults, children, infants, pets }) => {
const searchQueries = {
region,
...(region && { region }),
checkIn,
checkOut,
adults,
Expand Down
7 changes: 5 additions & 2 deletions src/components/SearchPanel/SearchPanel.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,16 @@ describe('SearchPanel Component', () => {
});


it('should not call navigate when region is not set and search button is clicked ', () => {
it('should navigate to root with search params when region is not set and search button is clicked', () => {
//given
const searchButton = screen.getByText('Search');
//when
fireEvent.click(searchButton);
//then
expect(navigate).not.toHaveBeenCalled();
expect(navigate).toHaveBeenCalledWith({
pathname: '/',
search: 'checkIn=2023-01-01&checkOut=2023-01-07&adults=4&children=3&infants=2&pets=1'
});
});

it('should call navigate with correct parameters when region is set and search button is clicked', () => {
Expand Down

0 comments on commit 346aba7

Please sign in to comment.