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

Wc 24/gridlist components #75

Merged
merged 8 commits into from
Feb 24, 2017
Merged

Wc 24/gridlist components #75

merged 8 commits into from
Feb 24, 2017

Conversation

akdetrick
Copy link
Contributor

Related issues

Fixes https://meetup.atlassian.net/browse/WC-24

Description

Add GridList component

Screenshots (if applicable)

screen shot 2017-02-10 at 4 16 22 pm

@coveralls
Copy link

Coverage Status

Coverage increased (+0.4%) to 84.17% when pulling e29e872 on WC-24/gridlist_components into fc65369 on master.


beforeEach(() => {
gridList = TestUtils.renderIntoDocument(JSX_GridListResponsive);
gridListNode = ReactDOM.findDOMNode(gridList);

Choose a reason for hiding this comment

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

Instead of findDOMNode we've been trying to use these the TestUtils functions like https://facebook.github.io/react/docs/test-utils.html#findRenderedDOMComponentWithClass for these kinds of tests, where we can. There are definitely still instances where you can't get away from avoiding findDOMNode, but since we are testing the classes components directly applied to the component, this should work. You can do something like

const gridList = TestUtils.findRenderedDOMComponentWithClass(gridList, GridList);
const gridListClassList = gridList.props.className;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What are the advantages of using this TestUtils method over ReactDOM?

There are some convenience methods in ReactDOM that were nice, like node.classList.contains('someClass'), as opposed to component.props.className.indexOf('someClass') > -1

Copy link
Contributor

Choose a reason for hiding this comment

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

@eilinora shared a nice article in another PR related to this: http://reactkungfu.com/2015/07/approaches-to-testing-react-components-an-overview/

One of the principles is that you should 'maintain the component abstraction in your tests as long as possible, but no longer', i.e. you should definitely prefer TestUtils methods that scan the React tree, but if you really need to get details of the DOM, you can drop into the 'real' DOM for some tests. I think one of the challenges of working with React is breaking the mental connection between 'React component tree' and 'DOM tree', and then determining at each step of application development which of those abstractions you are desiging/testing.

The article is good, though - definitely worth your time.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was mistaken; Jest makes this easy...

expect(someClassList).toContain(aClass);

@coveralls
Copy link

Coverage Status

Coverage increased (+0.3%) to 86.242% when pulling c08cfaa on WC-24/gridlist_components into 2be2da6 on master.

@akdetrick
Copy link
Contributor Author

bump

Good to merge?

src/GridList.jsx Outdated
const classNames = cx(
'gridList',
{
[`gridList--has${columns.default}`]: typeof columns.default === 'number',
Copy link
Contributor

Choose a reason for hiding this comment

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

prefer to keep your 'type-enforcement' code in one place - since number is already 'enforced' by the proptypes, I recommend just checking for the existence of the prop rather than the type here

[`gridList--has${columns.default}`]: columns.default  // or Boolean(columns.default)

src/GridList.jsx Outdated
</div>
);
});
return this.gridListItems;
Copy link
Contributor

Choose a reason for hiding this comment

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

given how small the render method is for this component, I think it would be more direct to just put this renderItems method inside render directly rather than requiring engineers to jump up to this method when debugging a render error. The whole JSX block in render could be tightened up without obscuring things too much:

render() {
  // ...
  return (
    <ul className={classNames} {...other}>
      {items.map((item, key) =>
          <div key={key} className='gridList-item'>{item}</div>
      )}
    </ul>
  );
}

@coveralls
Copy link

Coverage Status

Coverage increased (+0.2%) to 86.149% when pulling ac449a7 on WC-24/gridlist_components into 1a5ffe7 on master.

Copy link

@eilinora eilinora left a comment

Choose a reason for hiding this comment

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

gonna approve but this would be nice :)

src/GridList.jsx Outdated
return (
<ul
className={classNames}
{...other}>

Choose a reason for hiding this comment

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

super obnoxious nitpick on my part can you do > on new line makes it easier to read

@coveralls
Copy link

Coverage Status

Coverage increased (+0.5%) to 86.379% when pulling 1acaba3 on WC-24/gridlist_components into 1a5ffe7 on master.

@akdetrick akdetrick merged commit 00fe66d into master Feb 24, 2017
@chenrui333 chenrui333 deleted the WC-24/gridlist_components branch September 16, 2019 22:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants