Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Slider: Convert to mergeStyles (Part #1) #4796

Merged
merged 12 commits into from
May 17, 2018

Conversation

KevinTCoughlin
Copy link
Member

@KevinTCoughlin KevinTCoughlin commented May 7, 2018

Pull request checklist

  • Include a change request file using $ npm run change

Description of changes

Part 1 of converting <Slider/> to mergeStyles, changes include:

I used the following as references (first time doing this type of refactor):

Focus areas to test

That the <Slider/> renders as expected w/ its styles.

renderedValue?: number;
}

export enum ValuePosition {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI - This seems to be unused and can be deprecated / removed in a subsequent PR.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@KevinTCoughlin
Copy link
Member Author

Hmm looks like a snapshot test is failing.. taking a look:

FAIL src/components/Slider/Slider.test.tsx (8.835s)
  ● Slider › renders Slider correctly
    expect(value).toMatchSnapshot()
    
    Received value does not match stored snapshot 1.
    
    - Snapshot
    + Received
    
    @@ -10,11 +10,11 @@
            aria-valuemin={0}
            aria-valuenow={0}
            aria-valuetext={undefined}
            className="ms-Slider-slideBox ms-Slider-showValue ms-Slider-showTransitions undefined"
            disabled={false}
    -       id="Slider0"
    +       id="Slider1"
            onKeyDown={[Function]}
            onMouseDown={[Function]}
            onTouchStart={[Function]}
            role="slider"
            type="button"
      
      at Object.<anonymous> (src/components/Slider/Slider.test.tsx:15:18)
          at new Promise (<anonymous>)
          at <anonymous>
  ● Slider › renders a slider
    TypeError: Cannot read property 'querySelector' of null
      
      at Object.<anonymous> (src/components/Slider/Slider.test.tsx:23:38)
          at new Promise (<anonymous>)
          at <anonymous>
  ● Slider › can slide to default min/max and execute onChange
    TypeError: Cannot read property 'querySelector' of null
      
      at Object.<anonymous> (src/components/Slider/Slider.test.tsx:40:36)
          at new Promise (<anonymous>)
          at <anonymous>
  ● Slider › has type=button on all buttons
    TypeError: Cannot read property 'querySelectorAll' of null
      
      at Object.<anonymous> (src/components/Slider/Slider.test.tsx:77:36)
          at new Promise (<anonymous>)
          at <anonymous>
  ● Slider › renders correct aria-valuetext
    TypeError: Cannot read property 'querySelector' of null
      
      at Object.<anonymous> (src/components/Slider/Slider.test.tsx:101:30)
          at new Promise (<anonymous>)
          at <anonymous>
 › 1 snapshot test failed.

@KevinTCoughlin
Copy link
Member Author

Thank you @oengusmacinog for the snapshots walk-thru!

@@ -16,8 +18,8 @@ describe('Slider', () => {
});

it('renders a slider', () => {
const component = ReactTestUtils.renderIntoDocument(
<Slider label='slider' />
const component = ReactTestUtils.renderIntoDocument<SliderBase>(
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: that I've refactored the tests to test <SliderBase/> as we did in 3626565

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really don't completely understand this. What is the reasoning?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was trying to follow a component's tests that followed the getStyles pattern and were passing. Seems inconsistent tho and perhaps I followed the wrong pattern. Prior to using <SliderBase/> the DOM wouldn't render, likely because I was omitting something that was causing <Slider/> to throw.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re: the type parameter changes those can be removed and won't affect anything, just happened to be the pattern that I followed from 3626565 but even that is inconsistent.

@KevinTCoughlin KevinTCoughlin requested a review from aditima May 7, 2018 21:16
Copy link
Contributor

@jordandrako jordandrako left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, a few comments.

}

export class SliderBase extends BaseComponent<ISliderProps, ISliderState> implements ISlider {
public static defaultProps: {} = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For next PR (assuming this PR won't contain transitioning from sass to mergeStyles in the base component file): Type of defaultProps should probably be ISliderProps instead of {}.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is a worthwhile change to make now since it could make for some hard to find bugs later. In general {} should never be used as a type.

* Theme provided by High-Order Component.
*/
theme?: ITheme;

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add className?: string; as well so consumers can add a class to the root component.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


return (
<div
className={ css('ms-Slider', styles.root, className, {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For next PR: Make sure all this logic is in the styles file, including the globalClassNames such as "ms-Slider-enabled" etc. There shouldn't be a need for the css() function anywhere.

@dzearing
Copy link
Member

dzearing commented May 15, 2018

@JasonGore Kevin is out on leave; can we get this merge conflict fixed and clean up? Not urgent but doesn't look too bad to help out.

@aditima aditima merged commit a437b08 into microsoft:master May 17, 2018
@KevinTCoughlin KevinTCoughlin deleted the keco/ms-slider-pt1 branch May 17, 2018 21:29
@microsoft microsoft locked as resolved and limited conversation to collaborators Aug 31, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants