1
- describe ( '$transition:' , function ( ) {
1
+ describe ( 'transition' , function ( ) {
2
+
3
+ var transitionProvider , root = { name : "" , path : [ ] } , matcher , matchStates = {
4
+ "" : root ,
5
+ "first" : { name : "first" , path : [ root ] } ,
6
+ "second" : { name : "second" , path : [ root ] } ,
7
+ "third" : { name : "third" , path : [ root ] }
8
+ } ;
9
+
10
+ describe ( 'provider' , function ( ) {
11
+
12
+ beforeEach ( module ( 'ui.router' , function ( $transitionProvider ) {
13
+ transitionProvider = $transitionProvider ;
14
+ } ) ) ;
15
+
16
+ beforeEach ( inject ( function ( $transition ) {
17
+ matcher = new StateMatcher ( matchStates ) ;
18
+
19
+ $transition . init ( root , { } , function ( ref , options ) {
20
+ return matcher . find ( ref , options . relative ) ;
21
+ } ) ;
22
+ } ) ) ;
23
+
24
+ describe ( 'events' , function ( ) {
25
+
26
+ it ( 'should fire matching "on" events regardless of outcome' , inject ( function ( $transition ) {
27
+ var t = null ;
28
+
29
+ transitionProvider . on ( { from : "first" , to : "second" } , function ( $transition$ ) {
30
+ t = $transition$ ;
31
+ } ) ;
32
+
33
+ $transition . init ( matchStates . first , { } , function ( ref , options ) {
34
+ return matcher . find ( ref , options . relative ) ;
35
+ } ) ;
36
+
37
+ $transition . start ( "third" ) ;
38
+ expect ( t ) . toBeNull ( ) ;
39
+
40
+ $transition . start ( "second" ) ;
41
+ expect ( t ) . not . toBeNull ( ) ;
42
+ } ) ) ;
43
+
44
+ } ) ;
45
+ } ) ;
46
+
47
+
2
48
var statesTree , statesMap = { } ;
3
49
var emptyPath ;
4
50
var counts ;
5
51
var asyncCount ;
6
52
7
-
8
-
9
53
beforeEach ( module ( 'ui.router' , function ( $stateProvider , $locationProvider ) {
10
54
locationProvider = $locationProvider ;
11
55
$locationProvider . html5Mode ( false ) ;
@@ -74,10 +118,42 @@ describe('$transition:', function () {
74
118
return new Path ( map ( names , function ( name ) { return statesMap [ name ] ; } ) ) ;
75
119
}
76
120
77
- describe ( 'Transition().runAsync' , function ( ) {
78
- it ( 'should resolve all resolves in a PathElement' , inject ( function ( $q , $state ) {
79
- $state . go ( "B" ) ;
80
- $q . flush ( ) ;
121
+ describe ( 'instance' , function ( ) {
122
+ beforeEach ( inject ( function ( $transition ) {
123
+ matcher = new StateMatcher ( matchStates ) ;
124
+
125
+ $transition . init ( root , { } , function ( ref , options ) {
126
+ return matcher . find ( ref , options . relative ) ;
127
+ } ) ;
81
128
} ) ) ;
129
+
130
+ describe ( 'is' , function ( ) {
131
+ it ( 'should match rules' , inject ( function ( $transition ) {
132
+ var t = $transition . start ( "first" ) ;
133
+
134
+ expect ( t . is ( { to : "first" } ) ) . toBe ( true ) ;
135
+ expect ( t . is ( { from : "" } ) ) . toBe ( true ) ;
136
+ expect ( t . is ( { to : "first" , from : "" } ) ) . toBe ( true ) ;
137
+
138
+ expect ( t . is ( { to : [ "first" , "second" ] } ) ) . toBe ( true ) ;
139
+ expect ( t . is ( { to : [ "first" , "second" ] , from : [ "" , "third" ] } ) ) . toBe ( true ) ;
140
+ expect ( t . is ( { to : "first" , from : "**" } ) ) . toBe ( true ) ;
141
+
142
+ expect ( t . is ( { to : "second" } ) ) . toBe ( false ) ;
143
+ expect ( t . is ( { from : "first" } ) ) . toBe ( false ) ;
144
+ expect ( t . is ( { to : "first" , from : "second" } ) ) . toBe ( false ) ;
145
+
146
+ expect ( t . is ( { to : [ "" , "third" ] } ) ) . toBe ( false ) ;
147
+ expect ( t . is ( { to : "**" , from : "first" } ) ) . toBe ( false ) ;
148
+ } ) ) ;
149
+ } ) ;
150
+
151
+ describe ( 'runAsync' , function ( ) {
152
+ it ( 'should resolve all resolves in a PathElement' , inject ( function ( $q , $state ) {
153
+ $state . go ( "B" ) ;
154
+ $q . flush ( ) ;
155
+ } ) ) ;
156
+ } ) ;
82
157
} ) ;
158
+
83
159
} ) ;
0 commit comments