-
Notifications
You must be signed in to change notification settings - Fork 116
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
reorganize tests, use chrome until phantomjs works
- Loading branch information
Showing
19 changed files
with
384 additions
and
400 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
'use strict'; | ||
|
||
import React from 'react'; | ||
import { findDOMNode } from 'react-dom'; | ||
import createParent from '../../../../test/util/createParent'; | ||
import Login from '../Login'; | ||
|
||
import { | ||
createRenderer, | ||
renderIntoDocument, | ||
findRenderedDOMComponentWithTag | ||
} from 'react-addons-test-utils'; | ||
|
||
const userData = { | ||
username: 'echenley', | ||
md5hash: '7da6a19ef0b1a9b9794cf5c7cc7439f1' | ||
}; | ||
|
||
const errorMessage = 'uh oh'; | ||
|
||
const renderer = createRenderer(); | ||
|
||
describe('<Login />', () => { | ||
describe('DOM', () => { | ||
it('should render correctly WITH errorMessage prop', () => { | ||
// login with errorMessage prop | ||
renderer.render(<Login user={ userData } errorMessage={ errorMessage } />); | ||
const actualElement = renderer.getRenderOutput(); | ||
|
||
const expectedErrorMessage = ( | ||
<div className="error modal-form-error">{ errorMessage }</div> | ||
); | ||
|
||
expect(actualElement).to.includeJSX(expectedErrorMessage); | ||
}); | ||
|
||
it('should render correctly WITHOUT errorMessage prop', () => { | ||
// login without errorMessage prop | ||
renderer.render(<Login user={ userData } />); | ||
const actualElement = renderer.getRenderOutput(); | ||
const actualErrorMessage = actualElement.props.children[2]; | ||
|
||
expect(actualErrorMessage).to.not.exist; | ||
}); | ||
}); | ||
|
||
describe('Behavior', () => { | ||
let parent; | ||
let login; | ||
|
||
beforeEach(() => { | ||
let LoginParent = createParent(Login, 'login', { | ||
errorMessage: '', | ||
user: { isLoggedIn: false } | ||
}); | ||
|
||
parent = renderIntoDocument(<LoginParent />); | ||
login = parent.refs.login; | ||
}); | ||
|
||
it('should disable submit button until props update', () => { | ||
let submitButton = findDOMNode(findRenderedDOMComponentWithTag(login, 'button')); | ||
|
||
login.setState({ submitted: true }); | ||
expect(submitButton.disabled).to.equal(true); | ||
|
||
parent.setState({ errorMessage: 'invalid user' }); | ||
|
||
expect(login.state.submitted).to.equal(false); | ||
expect(submitButton.disabled).to.equal(false); | ||
}); | ||
|
||
it('should clear form when user prop updates', () => { | ||
login.clearForm = sinon.spy(); | ||
expect(login.clearForm).to.have.not.been.called; | ||
|
||
parent.setState({ user: { isLoggedIn: true } }); | ||
expect(login.clearForm).to.have.been.called; | ||
}); | ||
}); | ||
}); |
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,25 @@ | ||
'use strict'; | ||
|
||
import React from 'react'; | ||
import { createRenderer } from 'react-addons-test-utils'; | ||
|
||
import LoginLinks from '../LoginLinks'; | ||
|
||
describe('<LoginLinks />', () => { | ||
describe('DOM', function() { | ||
it('should render correctly', () => { | ||
const renderer = createRenderer(); | ||
renderer.render(<LoginLinks />); | ||
const actualElement = renderer.getRenderOutput(); | ||
|
||
const expectedElement = ( | ||
<span className="login-links"> | ||
<a onClick={ () => {} }>Sign In</a> | ||
<a onClick={ () => {} } className="register-link">Register</a> | ||
</span> | ||
); | ||
|
||
expect(actualElement).to.equalJSX(expectedElement); | ||
}); | ||
}); | ||
}); |
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,86 @@ | ||
'use strict'; | ||
|
||
import React from 'react'; | ||
import { findDOMNode } from 'react-dom'; | ||
import createParent from '../../../../test/util/createParent'; | ||
import Modal from '../Modal'; | ||
import Icon from '../Icon'; | ||
|
||
import { | ||
createRenderer, | ||
renderIntoDocument, | ||
findRenderedDOMComponentWithClass, | ||
Simulate | ||
} from 'react-addons-test-utils'; | ||
|
||
|
||
describe('<Modal />', () => { | ||
describe('DOM', () => { | ||
it('should render properly', () => { | ||
const childJSX = ( | ||
<div className="modal-child">hey</div> | ||
); | ||
|
||
const shallowRenderer = createRenderer(); | ||
shallowRenderer.render(<Modal>{ childJSX }</Modal>); | ||
const actualElement = shallowRenderer.getRenderOutput(); | ||
|
||
expect(actualElement).to.equalJSX(( | ||
<div className="modal-overlay" onClick={ () => {} }> | ||
<div className="modal-inner" onClick={ () => {} }> | ||
<a href="#" onClick={ () => {} } className="modal-close"> | ||
<Icon svg={ require('../../../svg/close.svg') } /> | ||
<span className="sr-only">Hide Modal</span> | ||
</a> | ||
{ childJSX } | ||
</div> | ||
</div> | ||
)); | ||
}); | ||
}); | ||
|
||
describe('Behavior', () => { | ||
let parent; | ||
let modal; | ||
let hideModalSpy; | ||
|
||
beforeEach(() => { | ||
hideModalSpy = sinon.spy(); | ||
|
||
let ModalParent = createParent(Modal, 'modal', { | ||
hideModal: hideModalSpy, | ||
children: <div /> | ||
}); | ||
|
||
parent = renderIntoDocument(<ModalParent />); | ||
modal = parent.refs.modal; | ||
}); | ||
|
||
it('should call props.hideModal when .modal-overlay is clicked', () => { | ||
expect(hideModalSpy).to.have.not.been.called; | ||
Simulate.click(findDOMNode(modal)); | ||
expect(hideModalSpy).to.have.been.called; | ||
}); | ||
|
||
it('should call props.hideModal when .modal-close is clicked', () => { | ||
const modalClose = findRenderedDOMComponentWithClass(modal, 'modal-close'); | ||
expect(hideModalSpy).to.have.not.been.called; | ||
Simulate.click(findDOMNode(modalClose)); | ||
expect(hideModalSpy).to.have.been.called; | ||
}); | ||
|
||
// TODO: figure out how to test this | ||
// it('should call props.hideModal when escape key is pressed', () => { | ||
// expect(hideModalSpy).to.have.not.been.called; | ||
// Simulate.keyPress(document, { keyCode: 27 }); | ||
// expect(hideModalSpy).to.have.been.called; | ||
// }); | ||
|
||
it('should not be removed when .modal-inner is clicked', () => { | ||
const modalInner = findRenderedDOMComponentWithClass(modal, 'modal-inner'); | ||
expect(hideModalSpy).to.have.not.been.called; | ||
Simulate.click(findDOMNode(modalInner)); | ||
expect(hideModalSpy).to.have.not.been.called; | ||
}); | ||
}); | ||
}); |
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,31 @@ | ||
'use strict'; | ||
|
||
import React from 'react'; | ||
import { createRenderer } from 'react-addons-test-utils'; | ||
|
||
import { Link } from 'react-router'; | ||
import ProfileLink from '../ProfileLink'; | ||
|
||
const userData = { | ||
username: 'echenley', | ||
md5hash: '7da6a19ef0b1a9b9794cf5c7cc7439f1' | ||
}; | ||
|
||
const renderer = createRenderer(); | ||
renderer.render(<ProfileLink user={ userData } />); | ||
const actualElement = renderer.getRenderOutput(); | ||
|
||
const expectedElement = ( | ||
<Link to={ `/user/${userData.username}` } className="profile-link"> | ||
<span className="username">{ userData.username }</span> | ||
<img src={ `http://www.gravatar.com/avatar/${userData.md5hash}?d=mm` } className="profile-pic" /> | ||
</Link> | ||
); | ||
|
||
describe('<ProfileLink />', () => { | ||
describe('DOM', function() { | ||
it('should render correctly', () => { | ||
expect(actualElement).to.equalJSX(expectedElement); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.