diff --git a/src/js/components/award/contract/ContractDetails.jsx b/src/js/components/award/contract/ContractDetails.jsx index 29602ecf11..287468db88 100644 --- a/src/js/components/award/contract/ContractDetails.jsx +++ b/src/js/components/award/contract/ContractDetails.jsx @@ -46,7 +46,9 @@ export default class ContractDetails extends React.Component { } componentWillReceiveProps(nextProps) { - this.prepareValues(nextProps.selectedAward); + if (!Object.is(nextProps.selectedAward, this.props.selectedAward)) { + this.prepareValues(nextProps.selectedAward); + } } parsePlaceOfPerformance(award) { diff --git a/src/js/components/award/financialAssistance/FinancialAssistanceDetails.jsx b/src/js/components/award/financialAssistance/FinancialAssistanceDetails.jsx index 6e429cca2d..8b949e79a1 100644 --- a/src/js/components/award/financialAssistance/FinancialAssistanceDetails.jsx +++ b/src/js/components/award/financialAssistance/FinancialAssistanceDetails.jsx @@ -43,10 +43,16 @@ export default class FinancialAssistanceDetails extends React.Component { }; } - componentWillReceiveProps() { + componentDidMount() { this.prepareValues(this.props.selectedAward); } + componentWillReceiveProps(nextProps) { + if (!Object.is(nextProps.selectedAward, this.props.selectedAward)) { + this.prepareValues(nextProps.selectedAward); + } + } + parsePlaceOfPerformance(award) { // Location let popPlace = ''; @@ -94,11 +100,10 @@ export default class FinancialAssistanceDetails extends React.Component { return popPlace; } - prepareValues() { + prepareValues(award) { let yearRangeTotal = ""; let monthRangeTotal = ""; let description = null; - const award = this.props.selectedAward; const latestTransaction = award.latest_transaction; // Date Range diff --git a/src/js/components/search/SearchSidebarSubmit.jsx b/src/js/components/search/SearchSidebarSubmit.jsx index a7045b79e3..39c7abf9e0 100644 --- a/src/js/components/search/SearchSidebarSubmit.jsx +++ b/src/js/components/search/SearchSidebarSubmit.jsx @@ -10,7 +10,7 @@ const propTypes = { requestsComplete: PropTypes.bool, filtersChanged: PropTypes.bool, applyStagedFilters: PropTypes.func, - resetStagedFilters: PropTypes.func + resetFilters: PropTypes.func }; const SearchSidebarSubmit = (props) => { @@ -33,10 +33,10 @@ const SearchSidebarSubmit = (props) => { </button> <button className="reset-button" - aria-label="Reset filters" + aria-label="Reset search" disabled={!props.requestsComplete} - onClick={props.resetStagedFilters}> - Reset filters + onClick={props.resetFilters}> + Reset search </button> </div> ); diff --git a/src/js/containers/search/SearchSidebarSubmitContainer.jsx b/src/js/containers/search/SearchSidebarSubmitContainer.jsx index c629f4623c..9124272aa9 100644 --- a/src/js/containers/search/SearchSidebarSubmitContainer.jsx +++ b/src/js/containers/search/SearchSidebarSubmitContainer.jsx @@ -25,7 +25,8 @@ const propTypes = { requestsComplete: PropTypes.bool, applyStagedFilters: PropTypes.func, clearStagedFilters: PropTypes.func, - setAppliedFilterCompletion: PropTypes.func + setAppliedFilterCompletion: PropTypes.func, + resetAppliedFilters: PropTypes.func }; export class SearchSidebarSubmitContainer extends React.Component { @@ -36,6 +37,7 @@ export class SearchSidebarSubmitContainer extends React.Component { filtersChanged: false }; + this.resetFilters = this.resetFilters.bind(this); this.applyStagedFilters = this.applyStagedFilters.bind(this); } @@ -93,13 +95,18 @@ export class SearchSidebarSubmitContainer extends React.Component { }); } + resetFilters() { + this.props.clearStagedFilters(); + this.props.resetAppliedFilters(); + } + render() { return ( <SearchSidebarSubmit filtersChanged={this.state.filtersChanged} requestsComplete={this.props.requestsComplete} applyStagedFilters={this.applyStagedFilters} - resetStagedFilters={this.props.clearStagedFilters} /> + resetFilters={this.resetFilters} /> ); } } diff --git a/src/js/redux/actions/search/appliedFilterActions.js b/src/js/redux/actions/search/appliedFilterActions.js index d4b647ecb6..5ca67ce8d7 100644 --- a/src/js/redux/actions/search/appliedFilterActions.js +++ b/src/js/redux/actions/search/appliedFilterActions.js @@ -19,5 +19,5 @@ export const applyStagedFilters = (filters) => ({ }); export const resetAppliedFilters = () => ({ - type: 'CLEAR_APPLIED_FILTER' + type: 'CLEAR_APPLIED_FILTERS' }); diff --git a/tests/containers/search/SearchSidebarSubmitContainer-test.jsx b/tests/containers/search/SearchSidebarSubmitContainer-test.jsx index 54459381ac..57ac5b67b8 100644 --- a/tests/containers/search/SearchSidebarSubmitContainer-test.jsx +++ b/tests/containers/search/SearchSidebarSubmitContainer-test.jsx @@ -136,4 +136,34 @@ describe('SearchSidebarSubmitContainer', () => { expect(container.state().filtersChanged).toBeFalsy(); }); }); + describe('resetFilters', () => { + it('should reset all the staged filters to their initial states', () => { + const actions = Object.assign({}, mockActions, { + clearStagedFilters: jest.fn() + }); + + const container = shallow( + <SearchSidebarSubmitContainer + {...mockRedux} + {...actions} /> + ); + + container.instance().resetFilters(); + expect(actions.clearStagedFilters).toHaveBeenCalledTimes(1); + }); + it('should reset all the applied filters to their initial states', () => { + const actions = Object.assign({}, mockActions, { + resetAppliedFilters: jest.fn() + }); + + const container = shallow( + <SearchSidebarSubmitContainer + {...mockRedux} + {...actions} /> + ); + + container.instance().resetFilters(); + expect(actions.resetAppliedFilters).toHaveBeenCalledTimes(1); + }); + }); }); \ No newline at end of file diff --git a/tests/containers/search/mockSubmit.js b/tests/containers/search/mockSubmit.js index b5d67698f6..631483ce4d 100644 --- a/tests/containers/search/mockSubmit.js +++ b/tests/containers/search/mockSubmit.js @@ -10,5 +10,6 @@ export const mockRedux = { export const mockActions = { applyStagedFilters: jest.fn(), clearStagedFilters: jest.fn(), - setAppliedFilterCompletion: jest.fn() + setAppliedFilterCompletion: jest.fn(), + resetAppliedFilters: jest.fn() }; \ No newline at end of file