11var assert = require ( 'assert' ) ;
2+ var expect = require ( 'expect' ) ;
23var React = require ( 'react/addons' ) ;
34var ReactTestUtils = React . addons . TestUtils ;
5+ var Routes = require ( '../../components/Routes' ) ;
46var Route = require ( '../../components/Route' ) ;
5- var ActiveContext = require ( '../ActiveContext' ) ;
67
78describe ( 'ActiveContext' , function ( ) {
89
910 var App = React . createClass ( {
10- mixins : [ ActiveContext ] ,
1111 render : function ( ) {
1212 return null ;
1313 }
1414 } ) ;
1515
1616 describe ( 'when a route is active' , function ( ) {
17- var route ;
18- beforeEach ( function ( ) {
19- route = Route ( { name : 'products' , handler : App } ) ;
20- } ) ;
21-
2217 describe ( 'and it has no params' , function ( ) {
2318 var component ;
24- beforeEach ( function ( ) {
19+ beforeEach ( function ( done ) {
2520 component = ReactTestUtils . renderIntoDocument (
26- App ( {
27- initialActiveRoutes : [ route ]
28- } )
21+ Routes ( { location : 'none' } ,
22+ Route ( { name : 'home' , handler : App } )
23+ )
2924 ) ;
25+
26+ component . dispatch ( '/home' , function ( error , abortReason , nextState ) {
27+ expect ( error ) . toBe ( null ) ;
28+ expect ( abortReason ) . toBe ( null ) ;
29+ component . setState ( nextState , done ) ;
30+ } ) ;
3031 } ) ;
3132
3233 afterEach ( function ( ) {
3334 React . unmountComponentAtNode ( component . getDOMNode ( ) ) ;
3435 } ) ;
3536
3637 it ( 'is active' , function ( ) {
37- assert ( component . isActive ( 'products ' ) ) ;
38+ assert ( component . isActive ( 'home ' ) ) ;
3839 } ) ;
3940 } ) ;
4041
4142 describe ( 'and the right params are given' , function ( ) {
4243 var component ;
43- beforeEach ( function ( ) {
44+ beforeEach ( function ( done ) {
4445 component = ReactTestUtils . renderIntoDocument (
45- App ( {
46- initialActiveRoutes : [ route ] ,
47- initialActiveParams : { id : '123' , show : 'true' , variant : 456 } ,
48- initialActiveQuery : { search : 'abc' , limit : 789 }
49- } )
46+ Routes ( { location : 'none' } ,
47+ Route ( { name : 'products' , path : '/products/:id/:variant' , handler : App } )
48+ )
5049 ) ;
50+
51+ component . dispatch ( '/products/123/456?search=abc&limit=789' , function ( error , abortReason , nextState ) {
52+ expect ( error ) . toBe ( null ) ;
53+ expect ( abortReason ) . toBe ( null ) ;
54+ component . setState ( nextState , done ) ;
55+ } ) ;
5156 } ) ;
5257
5358 afterEach ( function ( ) {
@@ -62,26 +67,31 @@ describe('ActiveContext', function () {
6267
6368 describe ( 'and a matching query is used' , function ( ) {
6469 it ( 'is active' , function ( ) {
65- assert ( component . isActive ( 'products' , { id : 123 } , { search : 'abc' , limit : '789' } ) ) ;
70+ assert ( component . isActive ( 'products' , { id : 123 } , { search : 'abc' } ) ) ;
6671 } ) ;
6772 } ) ;
6873
6974 describe ( 'but the query does not match' , function ( ) {
7075 it ( 'is not active' , function ( ) {
71- assert ( component . isActive ( 'products' , { id : 123 } , { search : 'def' , limit : '123' } ) === false ) ;
76+ assert ( component . isActive ( 'products' , { id : 123 } , { search : 'def' } ) === false ) ;
7277 } ) ;
7378 } ) ;
7479 } ) ;
7580
7681 describe ( 'and the wrong params are given' , function ( ) {
7782 var component ;
78- beforeEach ( function ( ) {
83+ beforeEach ( function ( done ) {
7984 component = ReactTestUtils . renderIntoDocument (
80- App ( {
81- initialActiveRoutes : [ route ] ,
82- initialActiveParams : { id : 123 }
83- } )
85+ Routes ( { location : 'none' } ,
86+ Route ( { name : 'products' , path : '/products/:id' , handler : App } )
87+ )
8488 ) ;
89+
90+ component . dispatch ( '/products/123' , function ( error , abortReason , nextState ) {
91+ expect ( error ) . toBe ( null ) ;
92+ expect ( abortReason ) . toBe ( null ) ;
93+ component . setState ( nextState , done ) ;
94+ } ) ;
8595 } ) ;
8696
8797 afterEach ( function ( ) {
0 commit comments