forked from stakwork/sphinx-tribes-frontend
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix search box is clear when click back button
- Loading branch information
1 parent
14319bb
commit e91b688
Showing
2 changed files
with
47 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import '@testing-library/jest-dom'; | ||
import { fireEvent, render } from '@testing-library/react'; | ||
import { createMemoryHistory } from 'history'; | ||
import React from 'react'; | ||
import { Router } from 'react-router-dom'; | ||
import { useStores } from '../../../../store'; | ||
import { PeopleList } from '../../peopleList'; | ||
|
||
jest.mock('store', () => ({ | ||
useStores: jest.fn() | ||
})); | ||
|
||
jest.mock('react-router-dom', () => ({ | ||
...jest.requireActual('react-router-dom'), | ||
useHistory: () => ({ | ||
replace: jest.fn() | ||
}) | ||
})); | ||
|
||
describe('PeopleList Component', () => { | ||
it('clears the search bar when back arrow button is clicked', async () => { | ||
const mockSetSearchText = jest.fn(); | ||
(useStores as jest.Mock).mockReturnValue({ | ||
ui: { | ||
searchText: 'John Doe', | ||
setSearchText: mockSetSearchText, | ||
setSelectingPerson: jest.fn(), | ||
setSelectedPerson: jest.fn() | ||
}, | ||
main: { | ||
getPeople: jest.fn(), | ||
people: [] | ||
} | ||
}); | ||
|
||
const history = createMemoryHistory(); | ||
const { getByText, getByPlaceholderText } = render( | ||
<Router history={history}> | ||
<PeopleList /> | ||
</Router> | ||
); | ||
expect(getByPlaceholderText('Search')).toHaveValue('John Doe'); | ||
fireEvent.click(getByText('Back')); | ||
expect(mockSetSearchText).toHaveBeenCalledWith(''); | ||
}); | ||
}); |