forked from mui/material-ui
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request mui#4035 from nathanmarks/raisedbutton-hover-icon
[RaisedButton] fix hover overlay for icon only buttons, fixes mui#3815
- Loading branch information
Showing
4 changed files
with
116 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/* eslint-env mocha */ | ||
import React from 'react'; | ||
import {shallow} from 'enzyme'; | ||
import {assert} from 'chai'; | ||
import RaisedButton from './RaisedButton'; | ||
import getMuiTheme from '../styles/getMuiTheme'; | ||
|
||
describe('<RaisedButton />', () => { | ||
const muiTheme = getMuiTheme(); | ||
const shallowWithContext = (node) => shallow(node, {context: {muiTheme}}); | ||
const testChildren = <span className="unique">Hello World</span>; | ||
|
||
it('renders an enhanced button inside paper', () => { | ||
const wrapper = shallowWithContext( | ||
<RaisedButton>Button</RaisedButton> | ||
); | ||
assert.ok(wrapper.is('Paper')); | ||
assert.ok(wrapper.childAt(0).is('EnhancedButton')); | ||
}); | ||
|
||
it('renders children', () => { | ||
const wrapper = shallowWithContext( | ||
<RaisedButton>{testChildren}</RaisedButton> | ||
); | ||
assert.ok(wrapper.contains(testChildren), 'should contain the children'); | ||
}); | ||
|
||
it('passes props to the enhanced button', () => { | ||
const props = { | ||
ariaLabel: 'Say hello world', | ||
disabled: true, | ||
href: 'http://google.com', | ||
linkButton: true, | ||
name: 'Hello World', | ||
}; | ||
|
||
const wrapper = shallowWithContext( | ||
<RaisedButton {...props}>Button</RaisedButton> | ||
); | ||
|
||
assert.ok(wrapper.childAt(0).is('EnhancedButton')); | ||
assert.ok(wrapper.childAt(0).is(props)); | ||
}); | ||
|
||
it('renders a label with an icon before', () => { | ||
const wrapper = shallowWithContext( | ||
<RaisedButton | ||
icon={<span className="test-icon" />} | ||
label={<span className="test-label">Hello</span>} | ||
/> | ||
); | ||
const icon = wrapper.find('.test-icon'); | ||
const label = wrapper.find('.test-label'); | ||
assert.ok(icon.is('span')); | ||
assert.strictEqual(label.children().node, 'Hello', 'says hello'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import React from 'react'; | ||
import ReactDOM from 'react-dom'; | ||
import TestUtils from 'react-addons-test-utils'; | ||
import RaisedButton from 'material-ui/RaisedButton'; | ||
import ActionAndroid from 'material-ui/svg-icons/action/android'; | ||
import {assert} from 'chai'; | ||
import mount from 'enzyme/mount'; | ||
import getMuiTheme from 'styles/getMuiTheme'; | ||
|
||
describe('<RaisedButton />', () => { | ||
const muiTheme = getMuiTheme(); | ||
const container = document.createElement('div'); | ||
document.body.appendChild(container); | ||
const mountWithContext = (node) => | ||
mount(node, { | ||
attachTo: container, | ||
context: {muiTheme}, | ||
}); | ||
|
||
it('renders a hover overlay of equal height to the button', () => { | ||
const wrappers = [ | ||
() => mountWithContext( | ||
<RaisedButton>Hello World</RaisedButton> | ||
), | ||
() => mountWithContext( | ||
<RaisedButton | ||
backgroundColor="#a4c639" | ||
icon={<ActionAndroid />} | ||
/> | ||
), | ||
]; | ||
|
||
wrappers.forEach((createWrapper) => { | ||
const wrapper = createWrapper(); | ||
wrapper.simulate('mouseEnter'); | ||
|
||
const overlay = wrapper.ref('overlay'); | ||
const button = ReactDOM.findDOMNode( | ||
TestUtils.findRenderedDOMComponentWithTag( | ||
wrapper.instance(), | ||
'button' | ||
) | ||
); | ||
|
||
assert.strictEqual( | ||
overlay.node.clientHeight, | ||
button.clientHeight, | ||
'overlay height should match the button height' | ||
); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters