Allow searching by gitmoji description (#641)

*  Allow searching by description

* 💬  Change the search placeholder

* 📸 Update snapshots

* 👌 Fix the test label

Co-authored-by: Vinícius Hoyer <contact@vhoyer.dev>

* 👌 Refactor duplicate .toLowercase, as suggested by @johannchopin

* 👌 Change the search placeholder as suggested by @johannchopin

Co-authored-by: Vinícius Hoyer <contact@vhoyer.dev>
This commit is contained in:
ilyasmez 2020-12-08 19:26:00 +01:00 committed by GitHub
parent dfea930196
commit a869e5357e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 27 additions and 9 deletions

View File

@ -473,7 +473,7 @@ exports[`Pages Index should render the page 1`] = `
className="searchInput"
name="searchInput"
onChange={[Function]}
placeholder="Search a Gitmoji by :code:"
placeholder="Search your gitmoji..."
type="text"
value={null}
/>

View File

@ -14,7 +14,7 @@ const Toolbar = (props: Props): Element<'div'> => (
className={styles.searchInput}
name="searchInput"
onChange={(event) => props.setSearchInput(event.target.value)}
placeholder="Search a Gitmoji by :code:"
placeholder="Search your gitmoji..."
type="text"
value={props.searchInput}
/>

View File

@ -18,7 +18,7 @@ exports[`GitmojiList should render the component 1`] = `
className="searchInput"
name="searchInput"
onChange={[Function]}
placeholder="Search a Gitmoji by :code:"
placeholder="Search your gitmoji..."
type="text"
value={null}
/>

View File

@ -9,15 +9,28 @@ describe('GitmojiList', () => {
expect(wrapper).toMatchSnapshot()
})
describe('when user search the bug gitmoji', () => {
it('should filter the GitmojiList and find the bug gitmoji', () => {
describe('when user search the fire gitmoji', () => {
it('should filter the GitmojiList and find the fire gitmoji by code', () => {
const wrapper = renderer.create(<GitmojiList {...stubs.props} />)
const instance = wrapper.root
renderer.act(() => {
instance
.findByType('input')
.props.onChange({ target: { value: 'Bug' } })
.props.onChange({ target: { value: 'Fire' } })
})
expect(instance.findAllByType('article').length).toEqual(1)
})
it('should filter the GitmojiList and find the fire gitmoji by description', () => {
const wrapper = renderer.create(<GitmojiList {...stubs.props} />)
const instance = wrapper.root
renderer.act(() => {
instance
.findByType('input')
.props.onChange({ target: { value: 'remove' } })
})
expect(instance.findAllByType('article').length).toEqual(1)

View File

@ -18,9 +18,14 @@ type Props = {
const GitmojiList = (props: Props): Element<'div'> => {
const [searchInput, setSearchInput] = React.useState(null)
const gitmojis = searchInput
? props.gitmojis.filter((gitmoji) =>
gitmoji.code.includes(searchInput.toLowerCase())
)
? props.gitmojis.filter(({ code, description }) => {
const lowerCasedSearch = searchInput.toLowerCase()
return (
code.includes(lowerCasedSearch) ||
description.toLowerCase().includes(lowerCasedSearch)
)
})
: props.gitmojis
React.useEffect(() => {