@@ -6,43 +6,7 @@ import {compose} from 'ramda';
66import Most , { connect } from '../react-most' ;
77import { sync , hold } from 'most-subject'
88import { 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- }
45-
9+ import { dispatch , stateHistoryOf , intentHistoryOf , Engine } from 'react-most-spec'
4610const CounterView = React . createClass ( {
4711 render ( ) {
4812 return (
@@ -87,7 +51,7 @@ const Counter = counterWrapper(CounterView)
8751
8852describe ( 'react-most' , ( ) => {
8953 describe ( 'actions' , ( ) => {
90- it . only ( 'add intent to intent$ and go through sink$' , ( ) => {
54+ it ( 'add intent to intent$ and go through sink$' , ( ) => {
9155 let counterWrapper = TestUtils . renderIntoDocument (
9256 < Most engine = { Engine } >
9357 < Counter history = { true } />
@@ -97,10 +61,10 @@ describe('react-most', () => {
9761 counter . actions . inc ( )
9862 counter . actions . inc ( )
9963 counter . actions . inc ( )
100- expect ( historyStreamOf ( counter ) [ 2 ] . count ) . toBe ( 3 )
64+ expect ( stateHistoryOf ( counter ) [ 2 ] . count ) . toBe ( 3 )
10165 } )
10266
103- it . only ( 'sink can also generate intent' , ( ) => {
67+ it ( 'sink can also generate intent' , ( ) => {
10468 let counterWrapper = TestUtils . renderIntoDocument (
10569 < Most engine = { Engine } >
10670 < Counter history = { true } />
@@ -109,21 +73,18 @@ describe('react-most', () => {
10973 let counter = TestUtils . findRenderedComponentWithType ( counterWrapper , Counter )
11074
11175 counter . actions . dec ( )
112- return intentStreamOf ( counter ) . reduce ( ( acc , x ) => ( acc . push ( x ) , acc ) , [ ] )
113- . then ( intent => expect ( intent [ 1 ] . type ) . toEqual ( 'dec triggered' ) )
76+ expect ( intentHistoryOf ( counter ) [ 1 ] . type ) . toBe ( 'dec triggered' )
11477 } )
11578
11679 it ( 'props will overwirte components default props' , ( ) => {
11780 let counterWrapper = TestUtils . renderIntoDocument (
118- < Most >
81+ < Most engine = { Engine } >
11982 < Counter count = { 9 } history = { true } />
12083 </ Most >
12184 )
12285 let counter = TestUtils . findRenderedComponentWithType ( counterWrapper , Counter )
123-
124- return run ( historyStreamOf ( counter ) ,
125- dispatch ( [ { type :'inc' } ] , counter ) ,
126- [ ( value ) => expect ( value . count ) . toBe ( 10 ) ] )
86+ counter . actions . inc ( ) ;
87+ expect ( stateHistoryOf ( counter ) [ 0 ] . count ) . toBe ( 10 )
12788 } )
12889
12990 it ( 'props that not overlap with views defaultProps can not be changed' , ( ) => {
@@ -142,73 +103,57 @@ describe('react-most', () => {
142103 overwritedProps = { this . state . overwritedProps }
143104 history = { true } />
144105 }
145-
146106 } )
147107 let counterMostWrapper = TestUtils . renderIntoDocument (
148- < Most >
108+ < Most engine = { Engine } >
149109 < CounterWrapper />
150110 </ Most >
151111 )
152112 let counterWrapper = TestUtils . findRenderedComponentWithType ( counterMostWrapper , CounterWrapper )
153113 let counter = TestUtils . findRenderedComponentWithType ( counterWrapper , Counter )
154-
155- return do$ ( [
156- ( ) => counter . actions . changeWrapperProps ( 'miao' ) ,
157- ( ) => counter . actions . changeDefaultProps ( 19 )
158- ] ) . then ( ( ) => {
159- let wrapperProps = TestUtils . findRenderedDOMComponentWithClass ( counter , 'wrapperProps' )
160- let overwritedProps = TestUtils . findRenderedDOMComponentWithClass ( counter , 'overwritedProps' )
161- let count = TestUtils . findRenderedDOMComponentWithClass ( counter , 'count' )
162- expect ( counter . props . wrapperProps ) . toBe ( 'heheda' )
163- expect ( wrapperProps . textContent ) . toBe ( 'miao' )
164- expect ( overwritedProps . textContent ) . toBe ( 'miao' )
165- expect ( count . textContent ) . toBe ( '19' )
166- return do$ ( [
167- ( ) => counterWrapper . setState ( { overwritedProps : 'wrapper' , count : 1 } )
168- ] )
169- } ) . then ( ( ) => {
170- let overwritedProps = TestUtils . findRenderedDOMComponentWithClass ( counter , 'overwritedProps' )
171- let count = TestUtils . findRenderedDOMComponentWithClass ( counter , 'count' )
172- expect ( overwritedProps . textContent ) . toBe ( 'wrapper' )
173- expect ( count . textContent ) . toBe ( '1' )
174- } )
114+ counter . actions . changeWrapperProps ( 'miao' )
115+ counter . actions . changeDefaultProps ( 19 )
116+ let wrapperProps = TestUtils . findRenderedDOMComponentWithClass ( counter , 'wrapperProps' )
117+ let overwritedProps = TestUtils . findRenderedDOMComponentWithClass ( counter , 'overwritedProps' )
118+ let count = TestUtils . findRenderedDOMComponentWithClass ( counter , 'count' )
119+ expect ( counter . props . wrapperProps ) . toBe ( 'heheda' )
120+ expect ( wrapperProps . textContent ) . toBe ( 'miao' )
121+ expect ( overwritedProps . textContent ) . toBe ( 'miao' )
122+ expect ( count . textContent ) . toBe ( '19' )
123+ counterWrapper . setState ( { overwritedProps : 'wrapper' , count : 1 } )
124+ overwritedProps = TestUtils . findRenderedDOMComponentWithClass ( counter , 'overwritedProps' )
125+ count = TestUtils . findRenderedDOMComponentWithClass ( counter , 'count' )
126+ expect ( overwritedProps . textContent ) . toBe ( 'wrapper' )
127+ expect ( count . textContent ) . toBe ( '1' )
175128 } )
176129 } ) ;
177130
178131 describe ( 'history' , ( ) => {
179132 it ( 'can undo' , ( ) => {
180133 let counterWrapper = TestUtils . renderIntoDocument (
181- < Most >
134+ < Most engine = { Engine } >
182135 < Counter history = { true } />
183136 </ Most >
184137 )
185138 let counter = TestUtils . findRenderedComponentWithType ( counterWrapper , Counter )
186- return do$ ( [
187- ( ) => counter . actions . inc ( ) ,
188- ( ) => counter . actions . inc ( ) ,
189- ( ) => counter . actions . inc ( )
190- ] ) . then ( ( ) => {
191- let backward = TestUtils . findRenderedDOMComponentWithClass ( counterWrapper , 'backward' )
192- TestUtils . Simulate . click ( backward )
193- TestUtils . Simulate . click ( backward )
194- TestUtils . Simulate . click ( backward )
195- } ) . then ( ( ) => {
196- let count = TestUtils . findRenderedDOMComponentWithClass ( counterWrapper , 'count' )
197- expect ( count . textContent ) . toBe ( '1' )
198- } ) . then ( ( ) => {
199- let forward = TestUtils . findRenderedDOMComponentWithClass ( counterWrapper , 'forward' )
200- TestUtils . Simulate . click ( forward )
201- } ) . then ( ( ) => {
202- let count = TestUtils . findRenderedDOMComponentWithClass ( counterWrapper , 'count' )
203- expect ( count . textContent ) . toBe ( '2' )
204- } ) . then ( ( ) => {
205- let forward = TestUtils . findRenderedDOMComponentWithClass ( counterWrapper , 'forward' )
206- TestUtils . Simulate . click ( forward )
207- TestUtils . Simulate . click ( forward )
208- } ) . then ( ( ) => {
209- let count = TestUtils . findRenderedDOMComponentWithClass ( counterWrapper , 'count' )
210- expect ( count . textContent ) . toBe ( '3' )
211- } )
139+ counter . actions . inc ( )
140+ counter . actions . inc ( )
141+ counter . actions . inc ( )
142+ let backward = TestUtils . findRenderedDOMComponentWithClass ( counterWrapper , 'backward' )
143+ TestUtils . Simulate . click ( backward )
144+ TestUtils . Simulate . click ( backward )
145+ TestUtils . Simulate . click ( backward )
146+ let count = TestUtils . findRenderedDOMComponentWithClass ( counterWrapper , 'count' )
147+ expect ( count . textContent ) . toBe ( '1' )
148+ let forward = TestUtils . findRenderedDOMComponentWithClass ( counterWrapper , 'forward' )
149+ TestUtils . Simulate . click ( forward )
150+ count = TestUtils . findRenderedDOMComponentWithClass ( counterWrapper , 'count' )
151+ expect ( count . textContent ) . toBe ( '2' )
152+ forward = TestUtils . findRenderedDOMComponentWithClass ( counterWrapper , 'forward' )
153+ TestUtils . Simulate . click ( forward )
154+ TestUtils . Simulate . click ( forward )
155+ count = TestUtils . findRenderedDOMComponentWithClass ( counterWrapper , 'count' )
156+ expect ( count . textContent ) . toBe ( '3' )
212157 } )
213158 } )
214159
@@ -233,17 +178,16 @@ describe('react-most', () => {
233178 const Counter2 = counterWrapper21 ( CounterView )
234179 it ( 'counter add inc2, dec2' , ( ) => {
235180 let counterWrapper = TestUtils . renderIntoDocument (
236- < Most >
181+ < Most engine = { Engine } >
237182 < Counter2 history = { true } />
238183 </ Most >
239184 )
185+ let counterView = TestUtils . findRenderedComponentWithType ( counterWrapper , CounterView )
240186 let counter = TestUtils . findRenderedComponentWithType ( counterWrapper , Counter2 )
241- dispatch ( [ { type :'inc' } ,
242- { type : 'inc2' } ,
243- { type :'dec' } ] , counter )
244- return historyStreamOf ( counter )
245- . take$ ( 3 )
246- . then ( state => expect ( state . count ) . toEqual ( 2 ) )
187+ counterView . props . actions . inc ( )
188+ counterView . props . actions . inc2 ( )
189+ counterView . props . actions . dec ( )
190+ expect ( stateHistoryOf ( counter ) [ 2 ] . count ) . toBe ( 2 )
247191 } )
248192 } )
249193
@@ -266,18 +210,14 @@ describe('react-most', () => {
266210
267211 it ( 'counter inc 3' , ( ) => {
268212 let counterWrapper = TestUtils . renderIntoDocument (
269- < Most >
213+ < Most engine = { Engine } >
270214 < Counter history = { true } />
271215 </ Most >
272216 )
273217 let counter = TestUtils . findRenderedComponentWithType ( counterWrapper , Counter )
274- do$ ( [
275- counter . actions . inc3 ,
276- counter . actions . inc3 ,
277- ] )
278- return historyStreamOf ( counter )
279- . take$ ( 2 )
280- . then ( state => expect ( state . count ) . toEqual ( 6 ) )
218+ counter . actions . inc3 ( )
219+ counter . actions . inc3 ( )
220+ expect ( stateHistoryOf ( counter ) [ 1 ] . count ) . toBe ( 6 )
281221 } )
282222 } )
283223
@@ -301,16 +241,13 @@ describe('react-most', () => {
301241 it ( 'should recover to identity stream and log exception' , ( ) => {
302242 spyOn ( console , 'error' )
303243 let counterWrapper = TestUtils . renderIntoDocument (
304- < Most >
244+ < Most engine = { Engine } >
305245 < Counter history = { true } />
306246 </ Most >
307247 )
308248 let counter = TestUtils . findRenderedComponentWithType ( counterWrapper , Counter )
309- return do$ ( [
310- counter . actions . throwExeption ,
311- ] ) . then ( ( ) => {
312- expect ( console . error ) . toHaveBeenCalled ( )
313- } )
249+ counter . actions . throwExeption ( )
250+ expect ( console . error ) . toHaveBeenCalled ( )
314251 } )
315252 } )
316253
@@ -346,7 +283,7 @@ describe('react-most', () => {
346283 } )
347284 spyOn ( console , 'error' )
348285 let counterWrapper = TestUtils . renderIntoDocument (
349- < Most >
286+ < Most engine = { Engine } >
350287 < TogglableMount />
351288 </ Most >
352289 )
0 commit comments