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

Add Tests for components #3486

Closed
alitaheri opened this issue Feb 26, 2016 · 40 comments
Closed

Add Tests for components #3486

alitaheri opened this issue Feb 26, 2016 · 40 comments
Labels
test umbrella For grouping multiple issues to provide a holistic view

Comments

@alitaheri
Copy link
Member

After the great work done by @nathanmarks with the tests we should now go ahead and make unit tests for each component to ensure their integrity 👍

This is the list of all components that need unit tests:

Components:

  • [AppBar] app-bar: [Tests] Add unit tests for AppBar #3487 @pradel
  • [AutoComplete] auto-complete
  • [Avatar] avatar: Partial: ([tests] Updates to test setup and additional testing option for unit tests #3405 @nathanmarks)
  • [Badge] badge: [Tests] Badge unit tests #3427 @pradel
  • [FlatButtonLabel] buttons/flat-button-label
  • [Drawer] Drawer
  • [Card] card/card
  • [CardAction] card/card-actions
  • [CardExpandable] card/card-expandable
  • [CardHeader] card/card-header
  • [CardMedia] card/card-media
  • [CardText] card/card-text
  • [CardTitle] card/card-title
  • [Checkbox] checkbox
  • [CircularProgress] circular-progress
  • [Calendar] date-picker/calendar
  • [CalendarMonth] date-picker/calendar-month
  • [CalendarToolbar] date-picker/calendar-toolbar
  • [CalendarYear] date-picker/calendar-year
  • [DateDisplay] date-picker/date-display
  • [DatePicker] date-picker/date-picker
  • [DatePickerDialog] date-picker/date-picker-dialog
  • [DatePickerInline] date-picker/date-picker-inline
  • [DayButton] date-picker/day-button
  • [YearButton] date-picker/year-button
  • [Dialog] dialog
  • [Divider] divider
  • [DropDownMenu] DropDownMenu/DropDownMenu
  • [EnhancedButton] enhanced-button
  • [EnhancedSwitch] enhanced-switch
  • [EnhancedTextarea] enhanced-textarea
  • [FlatButton] flat-button
  • [FloatingActionButton] floating-action-button
  • [FontIcon] font-icon: [Tests] Add unit tests for FontIcon #3490 @pradel
  • [GridList] grid-list/grid-list: [Tests] Add unit tests for GridList #3488 @pradel
  • [GridTitle] grid-list/grid-tile
  • [IconButton] icon-button
  • [InkBar] ink-bar
  • [LinearProgress] linear-progress
  • [List] lists/list
  • [ListItem] lists/list-item
  • [NestedList] lists/nested-list
  • [IconMenu] menus/icon-menu
  • [Menu] menus/menu
  • [MenuItem] menus/menu-item
  • [Overlay] overlay
  • [Paper] paper
  • [Popover] popover/popover
  • [PopoverAnimationFromTop] popover/popover-animation-from-top
  • [PopoverDefaultAnimationp] popover/popover-default-animation
  • [RadioButton] radio-button
  • [RadioButtonGroup] radio-button-group
  • [RaisedButton] raised-button
  • [RefreshIndicator] refresh-indicator
  • [RenderToLayer] render-to-layer
  • [CircleRipple] ripples/circle-ripple
  • [FocusRipple] ripples/focus-ripple
  • [TouchRipple] ripples/touch-ripple
  • [SelectField] SelectField/SelectField
  • [Slider] slider
  • [SnackBar] snackbar
  • [Subheader] Subheader/Subheader
  • [SvgIcon] svg-icon: [Tests] Add unit tests for SvgIcon #3489 @pradel
  • [Table] table/table
  • [TableBody] table/table-body
  • [TableFooter] table/table-footer
  • [TableHeader] table/table-header
  • [TableHeaderColumn] table/table-header-column
  • [TableRow] table/table-row
  • [TableRowColumn] table/table-row-column
  • [Tab] tabs/tab
  • [Tabs] tabs/tabs
  • [TabTemplate] tabs/tabTemplate
  • [TextField] TextField/TextField
  • [TextFieldHint] TextField/TextFieldHint
  • [TextFieldLabel] TextField/TextFieldLabel
  • [TextFieldUnderline] TextField/TextFieldUnderline
  • [Clock] time-picker/clock
  • [ClockHours] time-picker/clock-hours
  • [ClockMinutes] time-picker/clock-minutes
  • [ClockNumber] time-picker/clock-number
  • [ClockPointer] time-picker/clock-pointer
  • [TimeDisplay] time-picker/time-display
  • [TimePicker] time-picker/time-picker
  • [TimePickerDialog] time-picker/time-picker-dialog
  • [Toggle] toggle
  • [Toolbar] toolbar/toolbar
  • [ToolbarGroup] toolbar/toolbar-group
  • [ToolbarSeparator] toolbar/toolbar-separator
  • [ToolbarTitle] toolbar/toolbar-title
  • [ToolTip] tooltip

Utility Components:

  • [ClickAwayListener] ClickAwayListener
  • [muiThemeable] muiThemeable
  • [MuiThemeProvider] MuiThemeProvider
  • [ScaleIn] transition-groups/scale-in
  • [ScaleInChild] transition-groups/scale-in-child
  • [SlideIn] transition-groups/slide-in
  • [SlideInChild] transition-groups/slide-in-child

Styles:

  • [getMuiTheme] styles/getMuiTheme.js
  • [AutoPrefixerTransformer] styles/transformers/autoprefixer.js
  • [RtlTransformer] styles/transformers/rtl.js
  • [Transitions] styles/transitions.js
@alitaheri alitaheri added umbrella For grouping multiple issues to provide a holistic view test labels Feb 26, 2016
@alitaheri alitaheri added this to the 0.16.0 Release milestone Feb 26, 2016
@newoga
Copy link
Contributor

newoga commented Feb 26, 2016

Since testing is an ongoing activity, my recommendation for this issue is that maybe we shoot for a general percentage of coverage for 0.15.0 and improved level of coverage for 0.16.0. Maybe like 70% in 0.15.0, 85% in 0.16.0. We'll see how much progress we make with @pradel's work.

@nathanmarks
Copy link
Member

@alitaheri BTW, the Avatar component could still do with a few more tests.

I don't want people to misinterpret the checked boxes as meaning, "this is perfectly tested", because at this stage the important thing is to get some basic test coverage on all the components rather than having perfect tests for half of them.

@newoga
Copy link
Contributor

newoga commented Feb 26, 2016

I don't want people to misinterpret the checked boxes as meaning, "this is perfectly tested", because at this stage the important thing is to get some basic test coverage on all the components rather than having perfect tests for half of them.

Yup, these are my thoughts exactly. Technically this task is never finished, but setting some internal goal would be good for all the components.

@nathanmarks
Copy link
Member

@newoga @alitaheri What do you want to test in terms of styling?

Additionally, just a side not, but it's important not to confuse 100% coverage with 100% bulletproof ;)

@newoga
Copy link
Contributor

newoga commented Feb 26, 2016

Additionally, just a side not, but it's important not to confuse 100% coverage with 100% bulletproof ;)

I agree, but it the numbers definitely help keep us accountable. 😄

@nathanmarks
Copy link
Member

And ensure that the components actually do something 💃

@nathanmarks
Copy link
Member

I will have more time after this week btw to contribute more, just one of those weeks at the office ;)

@newoga
Copy link
Contributor

newoga commented Feb 26, 2016

That's great, thanks much @nathanmarks! I've having one of those weeks as well.

@alitaheri
Copy link
Member Author

By styles I mostly refer to transformers working as expected. I'll try to come up with something to reflect goal coverage 😁

@nathanmarks
Copy link
Member

Awesome!

PS, is there a convention in place for the naming of exporting the plain components for those that have an HoC wrapping the default export?

@alitaheri
Copy link
Member Author

Not really, but it would be great if there was. How about exporting as Raw or the wrapped one as default and the raw one as itself, so like: TextField?

@nathanmarks
Copy link
Member

That was my initial thought, but I was wondering if it makes it too easy to export the wrong component by accident. Anyone else? @newoga @oliviertassinari?

import Component from 'material-ui/lib/Component';
import { Component } from 'material-ui/lib/Component';

@alitaheri
Copy link
Member Author

Yeah...

import Component from 'material-ui/lib/Component';
import { Raw as Component } from 'material-ui/lib/Component';

Might be harder to get wrong, right? wrong?

@nathanmarks
Copy link
Member

700% harder to get wrong.

@newoga
Copy link
Contributor

newoga commented Feb 26, 2016

Yeah I need to give this more thought. I haven't thought of something I'm completely happy with. Though maybe it will make sense when we reorganize.

import Component from 'material-ui/lib/Component';
import { Component } from 'material-ui/lib/Component';

I think the approach above shouldn't return differently, that could be confusing.

import Component from 'material-ui/lib/Component';
import { Raw as Component } from 'material-ui/lib/Component';

I think this is more explicit and much safer.

import Component from 'material-ui/lib/Component';
import RawComponent from 'material-ui/lib/Component/raw';

Just another idea.

@nathanmarks
Copy link
Member

I think the { Raw as Component } proposal by @alitaheri is the best of those 3.

@newoga
Copy link
Contributor

newoga commented Feb 26, 2016

I think if I had to pick one now, I'd go with:

import Component from 'material-ui/lib/Component';
import { Raw as Component } from 'material-ui/lib/Component';

Though I'm wondering raw isn't the right word.

@nathanmarks
Copy link
Member

There are only two hard things in Computer Science: cache invalidation and naming things.

-- Phil Karlton

@newoga
Copy link
Contributor

newoga commented Feb 26, 2016

and naming things.

That's the truth.

Out of curiosity, do we plan on supporting the exports of raw components to developers? While I do see some interesting use cases when that could be useful, I'd rather not make it available publically unless we were really sure we are ready to support it. Even if the raw exports are not documented, people will find out and use them anyway. I'd rather not have to worry about deprecating old raw named exports and paths if we ever decide we want to change or reorganize it.

Javascript isn't the best at helping us in this area. For example, see what Facebook had to do in the React source: https://github.com/facebook/react/blob/master/src/React.js#L25

I suppose the biggest difference in this case is that we only need the raw components for testing. So if we were clever, there might be a way to remove the exports when we do an actual release build. If the exports were removed, I'd be completely fine naming the exports raw or anything and not feeling bad if we need to switch it later.

Let me know if I'm being too paranoid. 😆

@nathanmarks
Copy link
Member

I think that they should stay undocumented. Stick /** @private */ above the export and call it a day 😉

I also feel weird naming them all Raw. Something doesn't sit right 😄

FWIW, in my own projects I use PlainComponent for Component where necessary. I like keeping the component name in the named export. Still not happy with it though.

@alitaheri
Copy link
Member Author

PlainComponent Seems a LOT better 👍 👍 👍 Raw was what my mind could spit out in milliseconds, I didn't give it hours to compute a better word, although knowing myself given the life span of universe it would still fail 😆 😆 😆

@mbrookes
Copy link
Member

I was having visions of rawTheme all over again. 😉

@alitaheri
Copy link
Member Author

I was having visions of rawTheme all over again. 😉

😆 😆 😆

@nathanmarks
Copy link
Member

Poll needed? LOL!

@alitaheri
Copy link
Member Author

👍 for PlainComponent

@nathanmarks
Copy link
Member

@alitaheri Just to confirm, by that are you thinking along the lines of PlainTextField for TextField, etc, not PlainComponent for all? Making sure I was clear when I mentioned it 👍

@alitaheri
Copy link
Member Author

Yes I was also referring to the pattern PlainXxx 👍

@newoga
Copy link
Contributor

newoga commented Feb 28, 2016

Sounds good to me too!

@nathanmarks
Copy link
Member

Are there any components we should hold off on unit testing that are scheduled for heavy refactoring?

@mbrookes
Copy link
Member

Are there any components [...] that are scheduled for heavy refactoring?

All of them. 😁

@nathanmarks
Copy link
Member

@mbrookes 😄 hahaha.

Let me refine my question then. There are some components with questionable behaviour (table composition issues spring to mind) that I imagine might require heavy refactoring to change. Therefore, creating tests in it's current state feels like asserting undesirable behaviour (and a semi-waste of time). For example, trying to add any click handlers except on the root <Table /> component is akin to a journey down the rabbit hole.

@newoga
Copy link
Contributor

newoga commented Feb 28, 2016

I'd have to look over everything again with a fresh perspective. I think some component APIs are closer than others, and some will likely require a complete redesign. The challenge is I don't think we're going to have anytime to do any of the major component API refactoring in the 0.15.0 release.

That being said, I think the two that came immediately to mind that I'd like to remove are Clearfix and BeforeAfterWrapper. I'd like to remove those for sure so I wouldn't bother writing tests for those. Maybe before writing tests for any new components, maybe we should quickly regroup and decide what we think our mid and longterm goals might be for the component.

@nathanmarks
Copy link
Member

What do you mean by "new components"?

@newoga
Copy link
Contributor

newoga commented Feb 28, 2016

Sorry, that was confusing. I meant existing components that don't currently have tests.

@nathanmarks
Copy link
Member

If that's the case, is there anything you can advise me to definitely not write unit tests for at this time?

@newoga
Copy link
Contributor

newoga commented Feb 28, 2016

I just noticed the two I mentioned before @alitaheri didn't even bother including on the list. Honestly other than that I'm not too sure. I'd love to see rewrites for one or two components, but it's just not on my radar at the moment.

My recommendation is if you start looking at a component that needs to be tested and you're seeing some major design flaws that maybe aren't worth testing and should be just fixed, let's discuss it on Gitter or Github and plan what we should do with it.

@nathanmarks
Copy link
Member

@newoga To continue the discussion from #3248

I think that the important thing, regardless of react-look is that we focus the unit test style assertions on styles controlled by the component, passed through the component to merge with root, and passed by the component to children. IE, making sure the prop primary looks for and applies the correct style from the theme. Asserting this internal component behaviour in the unit tests is much more useful than trying to assert the final styling applied in the DOM without a DOM. (which can be affected by the presence of stylesheets, such as with react-look)

@alitaheri
Copy link
Member Author

controlled by the component, passed through the component to merge with root, and passed by the component to children.

react-look is a game changer. we would probably move a lot of logic there. I plan on adding memoization to react-look, so we can have a single call to prepareStyles with each change of inputs. it's going to be all inside the react-look. but maybe we can test the functions that take theme, state, props, etc and see if they return some expected styles.

@nathanmarks
Copy link
Member

@alitaheri since this isn't being updated we may want to get rid of that check list and close the issue.

@mbrookes
Copy link
Member

Or start updating it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
test umbrella For grouping multiple issues to provide a holistic view
Projects
None yet
Development

No branches or pull requests

4 participants