-
Notifications
You must be signed in to change notification settings - Fork 2k
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 #1358 from Automattic/update/search-gridicon
Framework: Update search component (and instances) to use gridicons
- Loading branch information
Showing
11 changed files
with
138 additions
and
120 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
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
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 |
---|---|---|
@@ -1,89 +1,108 @@ | ||
var assert = require( 'chai' ).assert, | ||
sinon = require( 'sinon' ), | ||
React = require( 'react/addons' ), | ||
mockery = require( 'mockery' ), | ||
TestUtils = React.addons.TestUtils, | ||
SectionNav; | ||
|
||
var EMPTY_COMPONENT = React.createClass( { | ||
render: function() { | ||
return <div />; | ||
} | ||
} ); | ||
|
||
require( 'lib/react-test-env-setup' )( '<html><body><script></script><div id="container"></div></body></html>' ); | ||
require( 'react-tap-event-plugin' )(); | ||
|
||
SectionNav = require( '../' ); | ||
|
||
function createComponent( component, props, children ) { | ||
var shallowRenderer = React.addons.TestUtils.createRenderer(); | ||
shallowRenderer.render( | ||
React.createElement( component, props, children ) | ||
); | ||
return shallowRenderer.getRenderOutput(); | ||
} | ||
|
||
describe( 'Section-Nav rendering', function() { | ||
describe( 'section-nav', function() { | ||
before( function() { | ||
var selectedText = 'test'; | ||
var children = ( <p>mmyellow</p> ); | ||
mockery.registerMock( 'components/gridicon', EMPTY_COMPONENT ); | ||
mockery.enable(); | ||
mockery.warnOnUnregistered( false ); | ||
|
||
this.sectionNav = createComponent( SectionNav, { | ||
selectedText: selectedText | ||
}, children ); | ||
SectionNav = require( '../' ); | ||
} ), | ||
|
||
this.panelElem = this.sectionNav.props.children[ 1 ]; | ||
this.headerElem = this.sectionNav.props.children[ 0 ]; | ||
this.headerTextElem = this.headerElem.props.children; | ||
this.text = this.headerTextElem.props.children; | ||
} ); | ||
after( function() { | ||
mockery.deregisterMock( 'components/gridicon' ); | ||
mockery.disable(); | ||
} ), | ||
|
||
it( 'should render a header and a panel', function() { | ||
assert.equal( this.headerElem.props.className, 'section-nav__mobile-header' ); | ||
assert.equal( this.panelElem.props.className, 'section-nav__panel' ); | ||
assert.equal( this.headerTextElem.props.className, 'section-nav__mobile-header-text' ); | ||
} ); | ||
describe( 'rendering', function() { | ||
before( function() { | ||
var selectedText = 'test'; | ||
var children = ( <p>mmyellow</p> ); | ||
|
||
it( 'should render selectedText within mobile header', function() { | ||
assert.equal( this.text, 'test' ); | ||
} ); | ||
this.sectionNav = createComponent( SectionNav, { | ||
selectedText: selectedText | ||
}, children ); | ||
|
||
it( 'should render children', function( done ) { | ||
//React.Children.only should work here but gives an error about not being the only child | ||
React.Children.map( this.panelElem.props.children, function( obj ) { | ||
if ( obj.type === 'p' ) { | ||
assert.equal( obj.props.children, 'mmyellow' ); | ||
done(); | ||
} | ||
this.panelElem = this.sectionNav.props.children[ 1 ]; | ||
this.headerElem = this.sectionNav.props.children[ 0 ]; | ||
this.headerTextElem = this.headerElem.props.children; | ||
this.text = this.headerTextElem.props.children; | ||
} ); | ||
} ); | ||
} ); | ||
|
||
describe( 'Section-Nav interaction', function() { | ||
it( 'should call onMobileNavPanelOpen function passed as a prop when tapped', function( done ) { | ||
var elem = React.createElement( SectionNav, { | ||
selectedText: 'placeholder', | ||
onMobileNavPanelOpen: function() { | ||
done(); | ||
} | ||
}, ( <p>placeholder</p> ) ); | ||
var tree = TestUtils.renderIntoDocument( elem ); | ||
assert( ! tree.state.mobileOpen ); | ||
TestUtils.Simulate.touchTap( React.findDOMNode( TestUtils.findRenderedDOMComponentWithClass( tree, 'section-nav__mobile-header' ) ) ); | ||
assert( tree.state.mobileOpen ); | ||
it( 'should render a header and a panel', function() { | ||
assert.equal( this.headerElem.props.className, 'section-nav__mobile-header' ); | ||
assert.equal( this.panelElem.props.className, 'section-nav__panel' ); | ||
assert.equal( this.headerTextElem.props.className, 'section-nav__mobile-header-text' ); | ||
} ); | ||
|
||
it( 'should render selectedText within mobile header', function() { | ||
assert.equal( this.text, 'test' ); | ||
} ); | ||
|
||
it( 'should render children', function( done ) { | ||
//React.Children.only should work here but gives an error about not being the only child | ||
React.Children.map( this.panelElem.props.children, function( obj ) { | ||
if ( obj.type === 'p' ) { | ||
assert.equal( obj.props.children, 'mmyellow' ); | ||
done(); | ||
} | ||
} ); | ||
} ); | ||
} ); | ||
|
||
it( 'should call onMobileNavPanelOpen function passed as a prop twice when tapped three times', function( done ) { | ||
var spy = sinon.spy(); | ||
var elem = React.createElement( SectionNav, { | ||
selectedText: 'placeholder', | ||
onMobileNavPanelOpen: spy | ||
}, ( <p>placeholder</p> ) ); | ||
var tree = TestUtils.renderIntoDocument( elem ); | ||
describe( 'interaction', function() { | ||
it( 'should call onMobileNavPanelOpen function passed as a prop when tapped', function( done ) { | ||
var elem = React.createElement( SectionNav, { | ||
selectedText: 'placeholder', | ||
onMobileNavPanelOpen: function() { | ||
done(); | ||
} | ||
}, ( <p>placeholder</p> ) ); | ||
var tree = TestUtils.renderIntoDocument( elem ); | ||
assert( ! tree.state.mobileOpen ); | ||
TestUtils.Simulate.touchTap( React.findDOMNode( TestUtils.findRenderedDOMComponentWithClass( tree, 'section-nav__mobile-header' ) ) ); | ||
assert( tree.state.mobileOpen ); | ||
} ); | ||
|
||
it( 'should call onMobileNavPanelOpen function passed as a prop twice when tapped three times', function( done ) { | ||
var spy = sinon.spy(); | ||
var elem = React.createElement( SectionNav, { | ||
selectedText: 'placeholder', | ||
onMobileNavPanelOpen: spy | ||
}, ( <p>placeholder</p> ) ); | ||
var tree = TestUtils.renderIntoDocument( elem ); | ||
|
||
assert( ! tree.state.mobileOpen ); | ||
TestUtils.Simulate.touchTap( React.findDOMNode( TestUtils.findRenderedDOMComponentWithClass( tree, 'section-nav__mobile-header' ) ) ); | ||
assert( tree.state.mobileOpen ); | ||
TestUtils.Simulate.touchTap( React.findDOMNode( TestUtils.findRenderedDOMComponentWithClass( tree, 'section-nav__mobile-header' ) ) ); | ||
assert( ! tree.state.mobileOpen ); | ||
TestUtils.Simulate.touchTap( React.findDOMNode( TestUtils.findRenderedDOMComponentWithClass( tree, 'section-nav__mobile-header' ) ) ); | ||
assert( tree.state.mobileOpen ); | ||
assert( ! tree.state.mobileOpen ); | ||
TestUtils.Simulate.touchTap( React.findDOMNode( TestUtils.findRenderedDOMComponentWithClass( tree, 'section-nav__mobile-header' ) ) ); | ||
assert( tree.state.mobileOpen ); | ||
TestUtils.Simulate.touchTap( React.findDOMNode( TestUtils.findRenderedDOMComponentWithClass( tree, 'section-nav__mobile-header' ) ) ); | ||
assert( ! tree.state.mobileOpen ); | ||
TestUtils.Simulate.touchTap( React.findDOMNode( TestUtils.findRenderedDOMComponentWithClass( tree, 'section-nav__mobile-header' ) ) ); | ||
assert( tree.state.mobileOpen ); | ||
|
||
assert( spy.calledTwice ); | ||
done(); | ||
assert( spy.calledTwice ); | ||
done(); | ||
} ); | ||
} ); | ||
} ); |
Oops, something went wrong.