@@ -4,7 +4,44 @@ import TestUtils from 'react-addons-test-utils';
44import * as most from 'most' ;
55import { compose } from 'ramda' ;
66import Most , { connect } from '../react-most' ;
7- import { do$ , historyStreamOf , intentStreamOf , dispatch } from '../test-utils'
7+ import { sync , hold } from 'most-subject'
8+ import { from } from 'most'
9+ import { INTENT_STREAM , HISTORY_STREAM } from '../react-most'
10+ function getStreamOf ( component , name ) {
11+ return component . context [ name ] ;
12+ }
13+
14+ function historyStreamOf ( component ) {
15+ return getStreamOf ( component , HISTORY_STREAM )
16+ }
17+
18+ function intentStreamOf ( component ) {
19+ return getStreamOf ( component , INTENT_STREAM )
20+ }
21+ function Engine ( ) {
22+ const intentStream = hold ( 2 , sync ( ) ) ,
23+ historyStream = [ ] ,
24+ travelStream = sync ( ) ;
25+ intentStream . send = intentStream . next . bind ( intentStream ) ;
26+ historyStream . send = historyStream . push . bind ( historyStream ) ;
27+ travelStream . send = travelStream . next . bind ( travelStream ) ;
28+ setTimeout ( ( ) => intentStream . complete ( ) )
29+
30+ function mergeObserve ( actionsSinks , f ) {
31+ let subscriptions = most . mergeArray ( actionsSinks )
32+ . recoverWith ( e => {
33+ console . error ( 'There is Error in your reducer:' , e , e . stack )
34+ return of ( x => x )
35+ } )
36+ . subscribe ( {
37+ next :f ,
38+ error : ( e ) => console . error ( 'Something is Wrong:' , e , e . stack ) ,
39+ } ) ;
40+ return subscriptions ;
41+ }
42+ historyStream . travel = travelStream ;
43+ return { intentStream, mergeObserve, historyStream}
44+ }
845
946const CounterView = React . createClass ( {
1047 render ( ) {
@@ -50,36 +87,30 @@ const Counter = counterWrapper(CounterView)
5087
5188describe ( 'react-most' , ( ) => {
5289 describe ( 'actions' , ( ) => {
53- it ( 'add intent to intent$ and go through sink$' , ( ) => {
90+ it . only ( 'add intent to intent$ and go through sink$' , ( ) => {
5491 let counterWrapper = TestUtils . renderIntoDocument (
55- < Most >
92+ < Most engine = { Engine } >
5693 < Counter history = { true } />
5794 </ Most >
5895 )
5996 let counter = TestUtils . findRenderedComponentWithType ( counterWrapper , Counter )
60-
61- do$ ( [ ( ) => counter . actions . inc ( ) ,
62- ( ) => counter . actions . fromPromise ( Promise . resolve ( { type :'inc' } ) ) ,
63- ( ) => counter . actions . fromEvent ( { type :'inc' } ) ] )
64-
65- return historyStreamOf ( counter )
66- . take$ ( 3 )
67- . then ( state => expect ( state . count ) . toEqual ( 3 ) )
97+ counter . actions . inc ( )
98+ counter . actions . inc ( )
99+ counter . actions . inc ( )
100+ expect ( historyStreamOf ( counter ) [ 2 ] . count ) . toBe ( 3 )
68101 } )
69102
70- it ( 'sink can also generate intent' , ( ) => {
103+ it . only ( 'sink can also generate intent' , ( ) => {
71104 let counterWrapper = TestUtils . renderIntoDocument (
72- < Most >
105+ < Most engine = { Engine } >
73106 < Counter history = { true } />
74107 </ Most >
75108 )
76109 let counter = TestUtils . findRenderedComponentWithType ( counterWrapper , Counter )
77110
78- do$ ( [ ( ) => counter . actions . dec ( ) ] )
79-
80- return intentStreamOf ( counter )
81- . take ( 2 ) . observe ( _ => _ )
82- . then ( intent => expect ( intent . type ) . toEqual ( 'dec triggered' ) )
111+ counter . actions . dec ( )
112+ return intentStreamOf ( counter ) . reduce ( ( acc , x ) => ( acc . push ( x ) , acc ) , [ ] )
113+ . then ( intent => expect ( intent [ 1 ] . type ) . toEqual ( 'dec triggered' ) )
83114 } )
84115
85116 it ( 'props will overwirte components default props' , ( ) => {
@@ -90,10 +121,9 @@ describe('react-most', () => {
90121 )
91122 let counter = TestUtils . findRenderedComponentWithType ( counterWrapper , Counter )
92123
93- do$ ( [ ( ) => counter . actions . inc ( ) ] )
94- return historyStreamOf ( counter )
95- . take$ ( 1 )
96- . then ( state => expect ( state . count ) . toBe ( 10 ) )
124+ return run ( historyStreamOf ( counter ) ,
125+ dispatch ( [ { type :'inc' } ] , counter ) ,
126+ [ ( value ) => expect ( value . count ) . toBe ( 10 ) ] )
97127 } )
98128
99129 it ( 'props that not overlap with views defaultProps can not be changed' , ( ) => {
0 commit comments