@@ -4,36 +4,69 @@ import React from 'react'
44import when from 'when'
55import Intent from '../../todo.action'
66import MainSection from '../MainSection.jsx'
7- import Footer from '../Footer.jsx'
7+ import Footer , { FILTER_FUNC } from '../Footer.jsx'
8+ import TodoItem from '../TodoItem.jsx'
89import Most from '../../../../../lib/react-most'
910import { do$ , historyStreamOf } from '../../../../../lib/test-utils'
1011import TestUtils from 'react-addons-test-utils'
11- describe ( 'MainSection' , ( ) => {
1212
13- describe ( 'display' , ( ) => {
14- it ( 'correct counts on footer' , ( ) => {
13+ describe ( 'MainSection' , ( ) => {
14+ const RESPONSE = '[{"text": "Try React Most","done": false,"id": 0},{"text": "Give it a Star on Github","done": false,"id": 1}]'
15+ beforeEach ( ( ) => {
16+ rest . __return ( RESPONSE )
17+ } )
18+ describe ( 'View' , ( ) => {
19+ const defaultTodos = [
20+ { id :0 , text :'Loading...dadada' , done :false } ,
21+ { id :1 , text :'dadada' , done :false } ,
22+ { id :2 , text :'yay' , done :true } ,
23+ ]
24+ it ( 'should show correct counts on footer' , ( ) => {
1525 let mainSection = TestUtils . renderIntoDocument (
1626 < Most >
1727 < MainSection
18- todos = { [
19- { id :0 , text :'Loading...dadada' , done :false } ,
20- { id :1 , text :'dadada' , done :false } ,
21- ] }
28+ todos = { defaultTodos }
2229 filter = { _ => _ }
2330 />
2431 </ Most >
2532 )
2633 let footer = TestUtils . findRenderedComponentWithType ( mainSection , Footer ) ;
27- expect ( footer . props . completedCount ) . toBe ( 0 )
34+ expect ( footer . props . completedCount ) . toBe ( 1 )
2835 expect ( footer . props . activeCount ) . toBe ( 2 )
2936 } )
37+
38+ it ( 'should show only active todos' , ( ) => {
39+ let mainSection = TestUtils . renderIntoDocument (
40+ < Most >
41+ < MainSection
42+ todos = { defaultTodos }
43+ filter = { FILTER_FUNC [ 'SHOW_ACTIVE' ] }
44+ />
45+ </ Most >
46+ )
47+ let todoItems = TestUtils . scryRenderedComponentsWithType ( mainSection , TodoItem ) ;
48+ expect ( todoItems . map ( item => item . props . todo . id ) ) . toEqual (
49+ [ 0 , 1 ] )
50+ } )
51+
52+ it ( 'should show only done todos' , ( ) => {
53+ let mainSection = TestUtils . renderIntoDocument (
54+ < Most >
55+ < MainSection
56+ todos = { defaultTodos }
57+ filter = { FILTER_FUNC [ 'SHOW_COMPLETED' ] }
58+ />
59+ </ Most >
60+ )
61+ let todoItems = TestUtils . scryRenderedComponentsWithType ( mainSection , TodoItem ) ;
62+ expect ( todoItems . map ( item => item . props . todo . id ) ) . toEqual (
63+ [ 2 ] )
64+ } )
3065 } )
3166
32- describe ( 'behavior ' , ( ) => {
67+ describe ( 'Behavior ' , ( ) => {
3368 let mainSectionWrapper , mainSection , send
34- let response = '[{"text": "Try React Most","completed": false,"id": 0},{"text": "Give it a Star on Github","completed": false,"id": 1}]'
3569 beforeEach ( ( ) => {
36- rest . __return ( response )
3770 mainSectionWrapper = TestUtils . renderIntoDocument (
3871 < Most >
3972 < MainSection history = { true } />
@@ -48,30 +81,30 @@ describe('MainSection', ()=>{
4881 { id :0 , text :'Loading...dadada' , done :false } ,
4982 ] )
5083 } )
51- it ( 'should get data from rest response to MainSection' , ( ) => {
52- return historyStreamOf ( mainSection ) . take$ ( 1 ) . then ( state => expect ( state . todos ) . toEqual ( JSON . parse ( response ) ) )
84+ it ( 'should get data from rest response to MainSection' , ( ) => {
85+ return historyStreamOf ( mainSection ) . take$ ( 1 ) . then ( state => expect ( state . todos ) . toEqual ( JSON . parse ( RESPONSE ) ) )
5386 } )
5487 } ) ;
5588
56- describe ( 'edit sink ' , ( ) => {
57- it ( 'should update todo 0 item text' , ( ) => {
89+ describe ( 'edit' , ( ) => {
90+ it ( 'should update todo id 0 item text' , ( ) => {
5891 do$ ( [
59- ( ) => send ( Intent . Edit ( { id :0 , text :'hehedayo' } ) ) ,
92+ ( ) => send ( Intent . Edit ( { id :0 , text :'hehedayo' } , 0 ) ) ,
6093 ] )
6194 return historyStreamOf ( mainSection ) . take$ ( 2 ) . then ( state => expect ( state . todos [ 0 ] ) . toEqual ( { "id" : 0 , "text" : "hehedayo" } ) )
6295 } )
6396 } ) ;
6497
65- describe ( 'clear sink ' , ( ) => {
98+ describe ( 'clear' , ( ) => {
6699 it ( 'should remove all done todos' , ( ) => {
67100 do$ ( [
68- ( ) => send ( Intent . Edit ( { id :0 , text :'done' , completed :true } ) ) ,
101+ ( ) => send ( Intent . Edit ( { id :0 , text :'done' , done :true } , 0 ) ) ,
69102 ( ) => send ( Intent . Clear ( ) ) ,
70103 ] )
71104 return historyStreamOf ( mainSection )
72105 . take$ ( 3 )
73106 . then ( state => {
74- expect ( state . todos ) . toEqual ( [ { "completed " : false , "id" : 1 , "text" : "Give it a Star on Github" } ] )
107+ expect ( state . todos ) . toEqual ( [ { "done " : false , "id" : 1 , "text" : "Give it a Star on Github" } ] )
75108 } )
76109 } )
77110 } )
0 commit comments