Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
when 4 equals 5
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);
});
});
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);
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