when 4 equals 5
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
decribe('NumberOfGuestsSelectBoxWrapper', () => { | |
it('should use value provided by flux store', => { | |
const { getPropsFromFluxState } = require('../NumberOfGuestsSelectBox'); | |
const mockFluxState = { | |
enquiryForm: { | |
numberOfGuests: 5 | |
} | |
}; | |
assert.equal(getPropsFromFluxState(mockFluxState).value, 5); | |
}); | |
it('should handle falsey', => { | |
const { getPropsFromFluxState } = require('../NumberOfGuestsSelectBox'); | |
const mockFluxState = { | |
enquiryForm: { | |
numberOfGuests: 0 | |
} | |
}; | |
assert.equal(getPropsFromFluxState(mockFluxState).value, 1); | |
}); | |
it('should handle falsey', => { | |
const { getPropsFromFluxState } = require('../NumberOfGuestsSelectBox'); | |
const mockFluxState = { | |
enquiryForm: {} | |
}; | |
assert.equal(getPropsFromFluxState(mockFluxState).value, 1); | |
}); | |
}); |
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
import React from 'react'; | |
import NumberOfGuestsSelectBox from './NumberOfGuestsSelectBox'; | |
import createContainer from '../../flux/utils'; | |
class GuestsSelectorWrapper extends React.Component { | |
render() { | |
const { value } = this.props; | |
return ( | |
<NumberOfGuestsSelectBox | |
value={value} | |
name='number_of_guests' | |
className='ofs-enquiry-form-field' | |
/> | |
); | |
} | |
} | |
GuestsSelectorWrapper.propTypes = { | |
value: React.PropTypes.string.isRequired, | |
}; | |
getPropsFromFluxState = state => ({ | |
value: state.enquiryForm.numberOfGuests | 1, | |
}); | |
export default createContainer(GuestsSelectorWrapper, getPropsFromFluxState); |
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
export createContainer (TargetComponent, getPropsFromFluxState) => { | |
const props = getPropsFromFluxState(fluxState); // fluxState is provided by flux framework | |
return (<TargetComponent ...props >); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment