forked from octokatherine/readme.so
-
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.
Feature Request: Search box above section list octokatherine#277 (oct…
…okatherine#278) * Feature Request: Search box above section list octokatherine#277 Add new SectionFilter component to filter slugs based on section names Update SectionsColumn to display filtered sections Add units tests for SectionFilter component * Update filteredSlugs state on add action * Trim section query string before filtering with it * Move sections filter above custom section * Improve search filter UX Remove search input after selecting a section Move search filter logic to SectionsColumn component Update SectionFilter unit test * Remove unused filterSections function * Fix resetSearchFilter function call
- Loading branch information
Showing
3 changed files
with
107 additions
and
13 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
const SectionFilter = ({ searchFilter, setSearchFilter }) => { | ||
return ( | ||
<input | ||
type="text" | ||
placeholder="Search for a section" | ||
className="mb-3 space-y-3 w-full py-2 pl-3 pr-6 bg-white dark:bg-gray-200 rounded-md shadow cursor-pointer focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-emerald-400" | ||
data-testid="slugs-filter" | ||
value={searchFilter} | ||
onChange={(e) => setSearchFilter(e.target.value)} | ||
/> | ||
) | ||
} | ||
|
||
export default SectionFilter |
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,36 @@ | ||
import { render, screen } from '@testing-library/react' | ||
import userEvent from '@testing-library/user-event' | ||
|
||
import SectionFilter from '../SectionFilter' | ||
|
||
jest.mock('next-i18next', () => ({ | ||
useTranslation: () => ({ t: jest.fn() }), | ||
})) | ||
|
||
describe('<SectionFilter />', () => { | ||
const props = { | ||
searchFilter: '', | ||
setSearchFilter: jest.fn(), | ||
} | ||
|
||
it('should render', () => { | ||
const { container } = render(<SectionFilter {...props} />) | ||
expect(container).toBeInTheDocument() | ||
}) | ||
|
||
it('should call the callBack function with updated filter query', () => { | ||
render(<SectionFilter {...props} />) | ||
|
||
const input = screen.getByTestId('slugs-filter') | ||
expect(input).toBeInTheDocument() | ||
expect(input).toHaveAttribute('type', 'text') | ||
expect(input).toHaveAttribute('placeholder', 'Search for a section') | ||
|
||
userEvent.type(input, 'app') | ||
|
||
expect(props.setSearchFilter).toHaveBeenCalledTimes(3) | ||
expect(props.setSearchFilter).toHaveBeenNthCalledWith(1, 'a') | ||
expect(props.setSearchFilter).toHaveBeenNthCalledWith(2, 'p') | ||
expect(props.setSearchFilter).toHaveBeenNthCalledWith(3, 'p') | ||
}) | ||
}) |