File tree Expand file tree Collapse file tree 3 files changed +52
-0
lines changed Expand file tree Collapse file tree 3 files changed +52
-0
lines changed Original file line number Diff line number Diff line change 1
1
import React from 'react' ;
2
2
import TodoList from './TodoList'
3
+ import TodoHeader from './TodoHeader'
3
4
4
5
export default React . createClass ( {
5
6
render : function ( ) {
6
7
return < div >
7
8
< section className = "todoapp" >
9
+ < TodoHeader />
8
10
< TodoList todos = { this . props . todos } filter = { this . props . filter } />
9
11
</ section >
10
12
</ div >
Original file line number Diff line number Diff line change
1
+ import React from 'react' ;
2
+ import PureRenderMixin from 'react-addons-pure-render-mixin' ;
3
+
4
+ export default React . createClass ( {
5
+ mixins : [ PureRenderMixin ] ,
6
+ _handleKeyPress : function ( e ) {
7
+ if ( e . key === 'Enter' && this . refs . addTodoInput . value !== '' ) {
8
+ return this . props . addItem (
9
+ this . refs . addTodoInput . value
10
+ ) ;
11
+ }
12
+ } ,
13
+ render : function ( ) {
14
+ return < header className = "header" >
15
+ < h1 > todos</ h1 >
16
+ < input className = "new-todo"
17
+ ref = "addTodoInput"
18
+ autofocus
19
+ autoComplete = "off"
20
+ placeholder = "What needs to be done?"
21
+ onKeyPress = { this . _handleKeyPress } />
22
+ </ header >
23
+ }
24
+ } ) ;
Original file line number Diff line number Diff line change
1
+ import React from 'react' ;
2
+ import TestUtils from 'react-addons-test-utils' ;
3
+ import TodoHeader from '../../src/components/TodoHeader' ;
4
+ import { expect } from 'chai' ;
5
+
6
+ const { renderIntoDocument,
7
+ scryRenderedDOMComponentsWithTag,
8
+ Simulate} = TestUtils ;
9
+
10
+ describe ( 'TodoHeader' , ( ) => {
11
+ it ( 'calls a callback on submit' , ( ) => {
12
+ var addedItem = ''
13
+ const addItem = ( item ) => addedItem = item ;
14
+ const component = renderIntoDocument (
15
+ < TodoHeader addItem = { addItem } />
16
+ ) ;
17
+
18
+ const input = component . refs . addTodoInput ;
19
+ input . value = 'This is a new item' ;
20
+ Simulate . change ( input ) ;
21
+ Simulate . keyPress ( input , { key : "Enter" , keyCode : 13 , which : 13 } ) ;
22
+
23
+ expect ( addedItem ) . to . equal ( 'This is a new item' ) ;
24
+ } ) ;
25
+
26
+ } ) ;
You can’t perform that action at this time.
0 commit comments