feat(Slider): Add Slider component, storybook and tests - #280
Conversation
Pull Request Test Coverage Report for Build 991
💛 - Coveralls |
Pull Request Test Coverage Report for Build 1200
💛 - Coveralls |
|
Hey @serenamarie125 and @jgiardino, I reopened this branch due to some issues with the old one, |
3e2322b to
dbf780b
Compare
serenamarie125
left a comment
There was a problem hiding this comment.
@LaViro this looks great! Thanks for your contribution!
| import React from 'react'; | ||
| import Enzyme, { mount } from 'enzyme'; | ||
| import Adapter from 'enzyme-adapter-react-16'; | ||
| import toJSON from 'enzyme-to-json'; |
There was a problem hiding this comment.
No longer require tojson, snapshot serializer is built in 😋
| import { Slider } from './index'; | ||
| import BootstrapSlider from './BootstrapSlider'; | ||
|
|
||
| Enzyme.configure({ adapter: new Adapter() }); |
There was a problem hiding this comment.
Unsure if we need this also, I suspect not...
dmiller9911
left a comment
There was a problem hiding this comment.
I do have some concerns about the jQuery issues. It might be nice to either try to contribute to the lib or find another that does not have the jQuery workaround. From a consumer standpoint, I would not like to have to work around it. Additionally, this will be a breaking change and will require a major version since it will throw an error at import for any consumer without jQuery.
| } | ||
| } | ||
|
|
||
| _onSlide = value => { |
There was a problem hiding this comment.
Judging by other methods in this repo I do not believe we are prefixing "private" methods with a _ @michaelkro or @priley86 might have better insight into that though.
There was a problem hiding this comment.
that's correct - we have not been prefixing with _ here. I don't see that as necessary, but i'm open to ideas on this.
There was a problem hiding this comment.
removed the private prefix
| this._slider = new Slider(this.sliderDiv, { | ||
| ...this.props | ||
| }); | ||
| this._slider.on('slide', value => that._onSlide(value)); |
There was a problem hiding this comment.
this can be written as this._slider.on('slide', this._onSlide) anything written like classMethod = () => {} are essentially be autobound to the instance.
There was a problem hiding this comment.
@sharvit can you remind me why we chose to use bindMethods syntax for binding class functions? It has been a long time since that was discussed...
to @dmiller9911 's point, I believe many communities have moved to the classMethod = () => {} syntax for auto binding...
| } | ||
|
|
||
| componentDidMount() { | ||
| const that = this; |
There was a problem hiding this comment.
Arrow functions remove the need for doing this.
There was a problem hiding this comment.
@dmiller9911 I am using it because the function is being called in bootstrap-slider's context.
this._slider.on('slide', value => that._onSlide(value));
There was a problem hiding this comment.
@dmiller9911,
I moved the onSlide function into componentDidMount
| this._slider.setAttribute('formatter', nextProps.formatter); | ||
| // Adjust the tooltip to "sit" ontop of the slider's handle. #LibraryBug | ||
| // check | ||
| if (this.props.orientation === 'horizontal') { |
There was a problem hiding this comment.
Creating constants for orientation similar to alerts and referencing the variable here will make it easier to maintain than using a string here.
| // Instead of rendering the slider element again and again, | ||
| // we took advantage of the bootstrap-slider library | ||
| // and only update the new value or format when new props arrive. | ||
| componentWillUpdate(nextProps, nextState) { |
There was a problem hiding this comment.
move this to componentDidUpdate. willUpdate will be deprecated in the next major react release, and the warning will be starting the next minor.
There was a problem hiding this comment.
@dmiller9911 Moved it to componentWillReceiveProps
| } | ||
| } | ||
|
|
||
| const slider = children[0]; |
There was a problem hiding this comment.
it is usually bad practice to assume children's data structure in React. React exports tools for this. Wou will want to run children through this: https://reactjs.org/docs/react-api.html#reactchildrentoarray before referencing the array positions. That said for this scenario is might be better to have a slider Prop and a form Prop or slider and then use children for form.
<Bounderies slider={<BSSlider />} >form goes here</Bounderies>| ); | ||
| } | ||
|
|
||
| const inputElement = this.props.input ? ( |
There was a problem hiding this comment.
This can be written as !!this.props.input && () React will render false the same as null.
| dropdownList: ['MB', 'GB'], | ||
| dropup: true | ||
| }; | ||
| const wrapper = mount(<Slider {...props} />); |
There was a problem hiding this comment.
any way to use shallow here and mock out bootstap-slider to return a mock instance/methods?
| 'componentWillUpdate' | ||
| ); | ||
| innerSlider.setProps({ value: 60 }); | ||
| expect(componentWillUpdate).toHaveBeenCalled(); |
There was a problem hiding this comment.
This doesn't really test much since it is kind of just exercising enzyme/react's lifecycle. A better test would be to verify the changes we make to slider after an update. You would need to get Slider mocked though. If you need help with that let me know. I can probably help out with that.
There was a problem hiding this comment.
@dmiller9911, I was also thinking about it, but it seems that Coverall's rate reduced when I didn't test it.
| dropup: true | ||
| }; | ||
| const wrapper = mount(<Slider {...props} />); | ||
| expect(toJSON(wrapper)).toMatchSnapshot(); |
There was a problem hiding this comment.
This snapshot is too big if we can't get shallow working. It would be better to verify values/method calls. It is best to try and keep snapshots around 20 lines or below.
|
@dmiller9911 @priley86 @AllenBW Thank you for your review guys! |
|
@LaViro this looks great! I do agree with @dmiller9911 however, about the jQuery issue... We definitely don't want consumers of this repo to have to think about jQuery whatsoever. Having to make an exception around jQuery or get a jQuery based warning... Both are no good. It would be nice to find a way to cut jQuery out of the picture entirely-- even if we need to target our own new fork of the slider or something. |
|
@mturley @dmiller9911 Thanks, I am going to try to figure this out.. Tell me if you got any idea |
dbf780b to
1ca0d99
Compare
|
@dmiller9911 @mturley I hacked the 'bootstrap-slider' package and published a new package called 'bootstrap-slider-without-jquery' which is jQuery-free. |
|
Need to add |
|
@jeff-phillips-18 It's the most important thing :) |
…brary, add storybook and tests. BREAKING CHANGE: Although jQuery is optional to this library, when it is not being used, an error will be raised. In order to fix this error, we need to set jquery to null in webpack. Please check the library repo on github for more information about this issue. fix patternfly#183
-Delete constructor. -Add orientation enums. -Change moved onSlide into componentDidMount and change the syntax of the binded call. -Change componentWillUpdate, as it is deprecated, to componentWillRecieveProps. -Change the private _ convention. -Add formatter props validation. ------------------------------------------------------------------------ Change Boundaries.js: -Add slider prop. -Delete avoid use of children index. ------------------------------------------------------------------------ Change Slider.js: -Add implementation to Boundaries slider prop. -Change moved BSSlider to const. ------------------------------------------------------------------------ Change Slider.test.js: -Delete unnecessary imports and configurations. -Change props to inline props.
- Change snapshot was decreased from 360 lines to 100. - Add test for slide and slideStop
81a86d6 to
2a6a3ef
Compare
-Change the import source of Dropdown and MenuItem to '../../index'.
eb860db to
cfdebfc
Compare
jQuery is no longer an issue since I have published the npm module 'bootstrap-slider-without-jquery'.
Storybook
fix #183
re #263