Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Nicolas Goutay
committed
Feb 27, 2016
1 parent
8550a95
commit cc97354
Showing
3 changed files
with
52 additions
and
0 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,24 @@ | ||
import React from 'react'; | ||
import PureRenderMixin from 'react-addons-pure-render-mixin'; | ||
|
||
export default React.createClass({ | ||
mixins: [PureRenderMixin], | ||
_handleKeyPress: function(e) { | ||
if (e.key === 'Enter' && this.refs.addTodoInput.value !== '') { | ||
return this.props.addItem( | ||
this.refs.addTodoInput.value | ||
); | ||
} | ||
}, | ||
render: function () { | ||
return <header className="header"> | ||
<h1>todos</h1> | ||
<input className="new-todo" | ||
ref="addTodoInput" | ||
autofocus | ||
autoComplete="off" | ||
placeholder="What needs to be done?" | ||
onKeyPress = {this._handleKeyPress} /> | ||
</header> | ||
} | ||
}); |
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,26 @@ | ||
import React from 'react'; | ||
import TestUtils from 'react-addons-test-utils'; | ||
import TodoHeader from '../../src/components/TodoHeader'; | ||
import {expect} from 'chai'; | ||
|
||
const {renderIntoDocument, | ||
scryRenderedDOMComponentsWithTag, | ||
Simulate} = TestUtils; | ||
|
||
describe('TodoHeader', () => { | ||
it('calls a callback on submit', () => { | ||
var addedItem = '' | ||
const addItem = (item) => addedItem = item; | ||
const component = renderIntoDocument( | ||
<TodoHeader addItem={addItem} /> | ||
); | ||
|
||
const input = component.refs.addTodoInput; | ||
input.value = 'This is a new item'; | ||
Simulate.change(input); | ||
Simulate.keyPress(input, {key: "Enter", keyCode: 13, which: 13}); | ||
|
||
expect(addedItem).to.equal('This is a new item'); | ||
}); | ||
|
||
}); |