-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(search/filter): Users can search and/or filter Articles
-Search by title, author, tag -Filter by title, author, tag -Search/Filter by any two, or all three above [Finishes #161348769]
- Loading branch information
Bruce Allan Makaaru
authored and
Bruce Allan Makaaru
committed
Dec 21, 2018
1 parent
d330a9d
commit 3af51ab
Showing
32 changed files
with
2,119 additions
and
137 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,7 @@ | ||
engines: | ||
duplication: | ||
enabled: true | ||
config: | ||
languages: | ||
javascript: | ||
mass_threshold: 75 |
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
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,25 @@ | ||
import axios from 'axios'; | ||
import ACTION_TYPE from './actionTypes'; | ||
|
||
const saveSearchQueryAction = payload => ({ | ||
type: ACTION_TYPE.SAVE_SEARCH_QUERY, | ||
payload, | ||
}); | ||
|
||
const saveSearchResultsAction = payload => ({ | ||
type: ACTION_TYPE.SAVE_SEARCH_RESULTS, | ||
payload, | ||
}); | ||
|
||
export const updateFilterFieldAction = payload => ({ | ||
type: ACTION_TYPE.UPDATE_FILTER_FIELD, | ||
payload, | ||
}); | ||
|
||
export const fetchSearchArticlesThunk = url => dispatch => axios.get(url) | ||
.then((response) => { | ||
dispatch(saveSearchResultsAction(response.data.results)); | ||
}) | ||
.catch(() => {}); | ||
|
||
export default saveSearchQueryAction; |
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,39 @@ | ||
import moxios from 'moxios'; | ||
import configureMockStore from 'redux-mock-store'; | ||
import reduxThunk from 'redux-thunk'; | ||
import { fetchSearchArticlesThunk } from '../searchActions'; | ||
import APP_URL from '../../utils/constants'; | ||
import ACTION_TYPE from '../actionTypes'; | ||
import { sampleListOfArticles } from '../../commons/initialStates'; | ||
|
||
describe('Search Actions', () => { | ||
let store; | ||
let url; | ||
|
||
beforeEach(() => { | ||
moxios.install(); | ||
const mockStore = configureMockStore([reduxThunk]); | ||
store = mockStore({}); | ||
url = `${APP_URL}/articles?title=dragon`; | ||
}); | ||
|
||
afterEach(() => { | ||
moxios.uninstall(); | ||
}); | ||
|
||
test('search articles thunk', () => { | ||
moxios.stubRequest(url, { | ||
status: 200, | ||
responseText: sampleListOfArticles, | ||
}); | ||
const expectedActions = [{ | ||
type: ACTION_TYPE.SAVE_SEARCH_RESULTS, | ||
payload: sampleListOfArticles, | ||
}]; | ||
store.dispatch((fetchSearchArticlesThunk(url))) | ||
.then(() => { | ||
expect(store.getActions()).toEqual(expectedActions); | ||
}) | ||
.catch(() => {}); | ||
}); | ||
}); |
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,3 @@ | ||
import { createBrowserHistory } from 'history'; | ||
|
||
export default createBrowserHistory(); |
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
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,49 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`<Filter /> component should render correctly 1`] = ` | ||
<Filter | ||
onChange={[MockFunction]} | ||
onClick={[MockFunction]} | ||
searchQuery="test" | ||
> | ||
<div | ||
className="container filter-box pt-3 text-center" | ||
> | ||
<h6> | ||
Search or Filter by: | ||
</h6> | ||
<input | ||
className="p-1 m-1" | ||
id="title" | ||
name="title" | ||
onChange={[MockFunction]} | ||
placeholder="Title" | ||
type="text" | ||
/> | ||
<input | ||
className="p-1 m-1" | ||
id="tag" | ||
name="tag" | ||
onChange={[MockFunction]} | ||
placeholder="Tag" | ||
type="text" | ||
/> | ||
<input | ||
className="p-1 m-1" | ||
id="author" | ||
name="author" | ||
onChange={[MockFunction]} | ||
placeholder="Author" | ||
type="text" | ||
/> | ||
<button | ||
className="btn btn-primary btn-sm" | ||
id="btFilter" | ||
onClick={[MockFunction]} | ||
type="button" | ||
> | ||
Filter | ||
</button> | ||
</div> | ||
</Filter> | ||
`; |
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,40 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
|
||
const Filter = ({ searchQuery, onChange, onClick }) => { | ||
const renderInputElement = (id, placeholder) => ( | ||
<input | ||
type="text" | ||
name={id} | ||
id={id} | ||
placeholder={placeholder} | ||
className="p-1 m-1" | ||
onChange={onChange} | ||
/> | ||
); | ||
|
||
return ( | ||
<div className="container filter-box pt-3 text-center"> | ||
<h6>Search or Filter by:</h6> | ||
{renderInputElement('title', 'Title', searchQuery)} | ||
{renderInputElement('tag', 'Tag')} | ||
{renderInputElement('author', 'Author')} | ||
<button | ||
type="button" | ||
id="btFilter" | ||
onClick={onClick} | ||
className="btn btn-primary btn-sm" | ||
> | ||
Filter | ||
</button> | ||
</div> | ||
); | ||
}; | ||
|
||
Filter.propTypes = { | ||
searchQuery: PropTypes.string.isRequired, | ||
onChange: PropTypes.func.isRequired, | ||
onClick: PropTypes.func.isRequired, | ||
}; | ||
|
||
export default Filter; |
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,12 @@ | ||
import React from 'react'; | ||
import { mount } from 'enzyme'; | ||
import Filter from '.'; | ||
|
||
describe('<Filter /> component', () => { | ||
it('should render correctly', () => { | ||
const wrapper = mount( | ||
<Filter searchQuery="test" onChange={jest.fn()} onClick={jest.fn()} />, | ||
); | ||
expect(wrapper).toMatchSnapshot(); | ||
}); | ||
}); |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.