@@ -6,8 +6,11 @@ import Intent from '../../intent'
66import MainSection from '../MainSection.jsx'
77import Footer , { FILTER_FUNC } from '../Footer.jsx'
88import TodoItem from '../TodoItem.jsx'
9- import Most from '../../../../../lib/react-most'
10- import { do$ , historyStreamOf } from '../../../../../lib/test-utils'
9+ import Most from 'react-most'
10+ import { stateStreamOf , stateHistoryOf ,
11+ intentStreamOf , intentHistoryOf ,
12+ run , dispatch ,
13+ Engine } from 'react-most-spec' ;
1114import TestUtils from 'react-addons-test-utils'
1215
1316describe ( 'MainSection' , ( ) => {
@@ -66,87 +69,59 @@ describe('MainSection', ()=>{
6669
6770 describe ( 'Behavior' , ( ) => {
6871 let mainSectionWrapper , mainSection , send
69- beforeEach ( ( ) => {
70- mainSectionWrapper = TestUtils . renderIntoDocument (
71- < Most >
72- < MainSection history = { true } />
73- </ Most >
74- )
75- mainSection = TestUtils . findRenderedComponentWithType ( mainSectionWrapper , MainSection ) ;
76- send = intent => mainSection . actions . fromPromise ( when ( intent ) )
77- } )
72+
7873 describe ( 'data sink' , ( ) => {
74+ beforeEach ( ( ) => {
75+ mainSectionWrapper = TestUtils . renderIntoDocument (
76+ < Most >
77+ < MainSection history = { true } />
78+ </ Most >
79+ )
80+ mainSection = TestUtils . findRenderedComponentWithType ( mainSectionWrapper , MainSection ) ;
81+ } )
7982 it ( 'should render default state' , ( ) => {
8083 expect ( mainSection . state . todos ) . toEqual ( [
8184 { id :0 , text :'Loading...dadada' , done :false } ,
8285 ] )
8386 } )
8487 it ( 'should get data from rest response to MainSection' , ( ) => {
85- return historyStreamOf ( mainSection ) . take$ ( 1 ) . then ( state => expect ( state . todos ) . toEqual ( JSON . parse ( RESPONSE ) ) )
88+ return run ( stateStreamOf ( mainSection ) ,
89+ dispatch ( [ ] , mainSection ) ,
90+ [
91+ state => expect ( state . todos ) . toEqual ( JSON . parse ( RESPONSE ) )
92+ ] )
8693 } )
8794 } ) ;
8895
89- describe ( 'edit' , ( ) => {
90- it ( 'should update todo id 0 item text' , ( ) => {
91- do$ ( [
92- ( ) => send ( Intent . Edit ( { id :0 , text :'hehedayo' } , 0 ) ) ,
93- ] )
94- return historyStreamOf ( mainSection ) . take$ ( 2 ) . then ( state => expect ( state . todos [ 0 ] ) . toEqual ( { "id" : 0 , "text" : "hehedayo" } ) )
95- } )
96- } ) ;
97-
98- describe ( 'clear' , ( ) => {
99- it ( 'should remove all done todos' , ( ) => {
100- do$ ( [
101- ( ) => send ( Intent . Edit ( { id :0 , text :'done' , done :true } , 0 ) ) ,
102- ( ) => send ( Intent . Clear ( ) ) ,
103- ] )
104- return historyStreamOf ( mainSection )
105- . take$ ( 3 )
106- . then ( state => {
107- expect ( state . todos ) . toEqual ( [ { "done" : false , "id" : 1 , "text" : "Give it a Star on Github" } ] )
108- } )
109- } )
110- } )
111-
112- describe ( 'delete' , ( ) => {
113- it ( 'should remove todos id 0' , ( ) => {
114- do$ ( [
115- ( ) => send ( Intent . Delete ( 0 ) ) ,
116- ] )
117- return historyStreamOf ( mainSection )
118- . take$ ( 2 )
119- . then ( state => {
120- expect ( state . todos ) . toEqual ( [ { "done" : false , "id" : 1 , "text" : "Give it a Star on Github" } ] )
121- } )
96+ describe ( 'sync' , ( ) => {
97+ beforeEach ( ( ) => {
98+ mainSectionWrapper = TestUtils . renderIntoDocument (
99+ < Most engine = { Engine } >
100+ < MainSection history = { true } />
101+ </ Most >
102+ )
103+ mainSection = TestUtils . findRenderedComponentWithType ( mainSectionWrapper , MainSection ) ;
122104 } )
123- } )
124-
125- describe ( 'done' , ( ) => {
126- it ( 'should complete todo 0' , ( ) => {
127- do$ ( [
128- ( ) => send ( Intent . Done ( 0 ) ) ,
129- ] )
130- return historyStreamOf ( mainSection )
131- . take$ ( 2 )
132- . then ( state => {
133- expect ( state . todos ) . toEqual ( [ { "done" : true , "id" : 0 , "text" : "Try React Most" } , { "done" : false , "id" : 1 , "text" : "Give it a Star on Github" } ] )
105+ describe ( 'edit' , ( ) => {
106+ it ( 'should update todo id 0 item text' , ( ) => {
107+ return dispatch ( [
108+ Intent . Edit ( { id :0 , text :'heheda0' } , 0 ) ,
109+ Intent . Done ( 0 ) ,
110+ Intent . Clear ( ) ,
111+ Intent . Add ( { text :'heheda1' } ) ,
112+ Intent . Delete ( 0 ) ,
113+ Intent . Filter ( FILTER_FUNC [ 'SHOW_COMPLETED' ] ) ,
114+ ] , mainSection ) . then ( ( ) => {
115+ let state = stateHistoryOf ( mainSection )
116+ expect ( state [ 0 ] . todos [ 0 ] ) . toEqual ( { "id" : 0 , "text" : "heheda0" } )
117+ expect ( state [ 1 ] . todos [ 0 ] ) . toEqual ( { "id" : 0 , "text" : "heheda0" , "done" : true } )
118+ expect ( state [ 2 ] . todos ) . toEqual ( [ ] )
119+ expect ( state [ 3 ] . todos [ 0 ] ) . toEqual ( { "id" : 0 , "text" : "heheda1" } )
120+ expect ( state [ 4 ] . todos ) . toEqual ( [ ] )
121+ expect ( state [ 5 ] . filter ) . toEqual ( FILTER_FUNC [ 'SHOW_COMPLETED' ] )
134122 } )
135- } )
136- } )
137-
138- describe ( 'click filter completed' , ( ) => {
139- it ( 'should only use SHOW_COMPLETED filter' , ( ) => {
140- do$ ( [
141- ( ) => send ( Intent . Edit ( { id :0 , done :true } , 0 ) ) ,
142- ( ) => send ( Intent . Filter ( FILTER_FUNC [ 'SHOW_COMPLETED' ] ) ) ,
143- ] )
144- return historyStreamOf ( mainSection )
145- . take$ ( 3 )
146- . then ( state => {
147- expect ( state . filter ) . toEqual ( FILTER_FUNC [ 'SHOW_COMPLETED' ] )
148- } )
149- } )
123+ } )
124+ } ) ;
150125 } )
151126 } )
152127} ) ;
0 commit comments