From 858dcaf92dba470366c6ba0a0a5f6ecc11ecdda8 Mon Sep 17 00:00:00 2001 From: Nathan Marks Date: Tue, 19 Apr 2016 00:13:16 -0400 Subject: [PATCH] [RaisedButton] Add browser for #3815 and a couple of starting unit tests --- src/RaisedButton/RaisedButton.spec.js | 57 +++++++++++++++++++++++++++ test/browser/RaisedButton.spec.js | 52 ++++++++++++++++++++++++ test/karma.conf.js | 2 + 3 files changed, 111 insertions(+) create mode 100644 src/RaisedButton/RaisedButton.spec.js create mode 100644 test/browser/RaisedButton.spec.js diff --git a/src/RaisedButton/RaisedButton.spec.js b/src/RaisedButton/RaisedButton.spec.js new file mode 100644 index 00000000000000..8ed197bfb054ac --- /dev/null +++ b/src/RaisedButton/RaisedButton.spec.js @@ -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('', () => { + const muiTheme = getMuiTheme(); + const shallowWithContext = (node) => shallow(node, {context: {muiTheme}}); + const testChildren = Hello World; + + it('renders an enhanced button inside paper', () => { + const wrapper = shallowWithContext( + Button + ); + assert.ok(wrapper.is('Paper')); + assert.ok(wrapper.childAt(0).is('EnhancedButton')); + }); + + it('renders children', () => { + const wrapper = shallowWithContext( + {testChildren} + ); + 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( + Button + ); + + 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( + } + label={Hello} + /> + ); + 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'); + }); +}); diff --git a/test/browser/RaisedButton.spec.js b/test/browser/RaisedButton.spec.js new file mode 100644 index 00000000000000..8e740a5f039eb0 --- /dev/null +++ b/test/browser/RaisedButton.spec.js @@ -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('', () => { + 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( + Hello World + ), + () => mountWithContext( + } + /> + ), + ]; + + 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' + ); + }); + }); +}); diff --git a/test/karma.conf.js b/test/karma.conf.js index a7cb18cf850df3..eafbf26c142529 100644 --- a/test/karma.conf.js +++ b/test/karma.conf.js @@ -1,3 +1,4 @@ +const path = require('path'); const argv = process.argv.slice(2); const opts = { coverage: true, @@ -83,6 +84,7 @@ module.exports = function(config) { }, resolve: { alias: { + 'material-ui': path.resolve(__dirname, '../src'), sinon: 'sinon/pkg/sinon.js', }, extensions: ['', '.js', '.jsx', '.json'],