@@ -142,12 +142,12 @@ describe('UrlMatcher', function() {
142
142
} ) ;
143
143
144
144
it ( 'should work with empty default value' , function ( ) {
145
- const m = $umf . compile ( '/foo/:str' , { params : { str : { value : '' } } } ) ;
145
+ const m = $umf . compile ( '/foo/:str' , { state : { params : { str : { value : '' } } } } ) ;
146
146
expect ( m . exec ( '/foo/' , { } ) ) . toEqual ( { str : '' } ) ;
147
147
} ) ;
148
148
149
149
it ( 'should work with empty default value for regex' , function ( ) {
150
- const m = $umf . compile ( '/foo/{param:(?:foo|bar|)}' , { params : { param : { value : '' } } } ) ;
150
+ const m = $umf . compile ( '/foo/{param:(?:foo|bar|)}' , { state : { params : { param : { value : '' } } } } ) ;
151
151
expect ( m . exec ( '/foo/' , { } ) ) . toEqual ( { param : '' } ) ;
152
152
} ) ;
153
153
@@ -212,9 +212,9 @@ describe('UrlMatcher', function() {
212
212
} ) ;
213
213
214
214
it ( 'should trim trailing slashes when the terminal value is optional' , function ( ) {
215
- const config = { params : { id : { squash : true , value : '123' } } } ,
216
- m = $umf . compile ( '/users/:id' , config ) ,
217
- params = { id : '123' } ;
215
+ const config = { state : { params : { id : { squash : true , value : '123' } } } } ;
216
+ const m = $umf . compile ( '/users/:id' , config ) ;
217
+ const params = { id : '123' } ;
218
218
219
219
expect ( m . format ( params ) ) . toEqual ( '/users' ) ;
220
220
} ) ;
@@ -343,7 +343,7 @@ describe('UrlMatcher', function() {
343
343
} ) ;
344
344
345
345
it ( 'should be wrapped in an array if array: true' , function ( ) {
346
- const m = $umf . compile ( '/foo?param1' , { params : { param1 : { array : true } } } ) ;
346
+ const m = $umf . compile ( '/foo?param1' , { state : { params : { param1 : { array : true } } } } ) ;
347
347
348
348
// empty array [] is treated like "undefined"
349
349
expect ( m . format ( { param1 : undefined } ) ) . toBe ( '/foo' ) ;
@@ -394,14 +394,16 @@ describe('UrlMatcher', function() {
394
394
// Test for issue #2222
395
395
it ( 'should return default value, if query param is missing.' , function ( ) {
396
396
const m = $umf . compile ( '/state?param1¶m2¶m3¶m5' , {
397
- params : {
398
- param1 : 'value1' ,
399
- param2 : { array : true , value : [ 'value2' ] } ,
400
- param3 : { array : true , value : [ ] } ,
401
- param5 : {
402
- array : true ,
403
- value : function ( ) {
404
- return [ ] ;
397
+ state : {
398
+ params : {
399
+ param1 : 'value1' ,
400
+ param2 : { array : true , value : [ 'value2' ] } ,
401
+ param3 : { array : true , value : [ ] } ,
402
+ param5 : {
403
+ array : true ,
404
+ value : function ( ) {
405
+ return [ ] ;
406
+ } ,
405
407
} ,
406
408
} ,
407
409
} ,
@@ -429,7 +431,7 @@ describe('UrlMatcher', function() {
429
431
} ) ;
430
432
431
433
it ( 'should not be wrapped by ui-router into an array if array: false' , function ( ) {
432
- const m = $umf . compile ( '/foo?param1' , { params : { param1 : { array : false } } } ) ;
434
+ const m = $umf . compile ( '/foo?param1' , { state : { params : { param1 : { array : false } } } } ) ;
433
435
434
436
expect ( m . exec ( '/foo' ) ) . toEqualData ( { } ) ;
435
437
@@ -456,7 +458,7 @@ describe('UrlMatcher', function() {
456
458
} ) ;
457
459
458
460
it ( 'should be split on - in url and wrapped in an array if array: true' , function ( ) {
459
- const m = $umf . compile ( '/foo/:param1' , { params : { param1 : { array : true } } } ) ;
461
+ const m = $umf . compile ( '/foo/:param1' , { state : { params : { param1 : { array : true } } } } ) ;
460
462
461
463
expect ( m . exec ( '/foo/' ) ) . toEqual ( { param1 : undefined } ) ;
462
464
expect ( m . exec ( '/foo/bar' ) ) . toEqual ( { param1 : [ 'bar' ] } ) ;
@@ -661,15 +663,17 @@ describe('urlMatcherFactory', function() {
661
663
expect ( m . exec ( '/1138' ) ) . toEqual ( { foo : 1138 } ) ;
662
664
expect ( m . format ( { foo : null } ) ) . toBe ( null ) ;
663
665
664
- m = $umf . compile ( '/{foo:int}' , { params : { foo : { value : 1 } } } ) ;
666
+ m = $umf . compile ( '/{foo:int}' , { state : { params : { foo : { value : 1 } } } } ) ;
665
667
expect ( m . format ( { foo : null } ) ) . toBe ( '/1' ) ;
666
668
} ) ;
667
669
668
670
it ( 'should match types named only in params' , function ( ) {
669
671
const m = $umf . compile ( '/{foo}/{flag}' , {
670
- params : {
671
- foo : { type : 'int' } ,
672
- flag : { type : 'bool' } ,
672
+ state : {
673
+ params : {
674
+ foo : { type : 'int' } ,
675
+ flag : { type : 'bool' } ,
676
+ } ,
673
677
} ,
674
678
} ) ;
675
679
expect ( m . exec ( '/1138/1' ) ) . toEqual ( { foo : 1138 , flag : true } ) ;
@@ -679,8 +683,10 @@ describe('urlMatcherFactory', function() {
679
683
it ( 'should throw an error if a param type is declared twice' , function ( ) {
680
684
expect ( function ( ) {
681
685
$umf . compile ( '/{foo:int}' , {
682
- params : {
683
- foo : { type : 'int' } ,
686
+ state : {
687
+ params : {
688
+ foo : { type : 'int' } ,
689
+ } ,
684
690
} ,
685
691
} ) ;
686
692
} ) . toThrow ( new Error ( "Param 'foo' has two type configurations." ) ) ;
@@ -747,7 +753,7 @@ describe('urlMatcherFactory', function() {
747
753
is : isArray ,
748
754
} as any ) ;
749
755
750
- const m = $umf . compile ( '/foo?{bar:custArray}' , { params : { bar : { array : false } } } ) ;
756
+ const m = $umf . compile ( '/foo?{bar:custArray}' , { state : { params : { bar : { array : false } } } } ) ;
751
757
752
758
$location . url ( '/foo?bar=fox' ) ;
753
759
expect ( m . exec ( $location . path ( ) , $location . search ( ) ) ) . toEqual ( { bar : [ 'fox' ] } ) ;
@@ -762,7 +768,7 @@ describe('urlMatcherFactory', function() {
762
768
describe ( 'optional parameters' , function ( ) {
763
769
it ( 'should match with or without values' , function ( ) {
764
770
const m = $umf . compile ( '/users/{id:int}' , {
765
- params : { id : { value : null , squash : true } } ,
771
+ state : { params : { id : { value : null , squash : true } } } ,
766
772
} ) ;
767
773
expect ( m . exec ( '/users/1138' ) ) . toEqual ( { id : 1138 } ) ;
768
774
expect ( m . exec ( '/users1138' ) ) . toBeNull ( ) ;
@@ -772,7 +778,7 @@ describe('urlMatcherFactory', function() {
772
778
773
779
it ( 'should correctly match multiple' , function ( ) {
774
780
const m = $umf . compile ( '/users/{id:int}/{state:[A-Z]+}' , {
775
- params : { id : { value : null , squash : true } , state : { value : null , squash : true } } ,
781
+ state : { params : { id : { value : null , squash : true } , state : { value : null , squash : true } } } ,
776
782
} ) ;
777
783
expect ( m . exec ( '/users/1138' ) ) . toEqual ( { id : 1138 , state : null } ) ;
778
784
expect ( m . exec ( '/users/1138/NY' ) ) . toEqual ( { id : 1138 , state : 'NY' } ) ;
@@ -789,15 +795,15 @@ describe('urlMatcherFactory', function() {
789
795
790
796
it ( 'should correctly format with or without values' , function ( ) {
791
797
const m = $umf . compile ( '/users/{id:int}' , {
792
- params : { id : { value : null } } ,
798
+ state : { params : { id : { value : null } } } ,
793
799
} ) ;
794
800
expect ( m . format ( ) ) . toBe ( '/users/' ) ;
795
801
expect ( m . format ( { id : 1138 } ) ) . toBe ( '/users/1138' ) ;
796
802
} ) ;
797
803
798
804
it ( 'should correctly format multiple' , function ( ) {
799
805
const m = $umf . compile ( '/users/{id:int}/{state:[A-Z]+}' , {
800
- params : { id : { value : null , squash : true } , state : { value : null , squash : true } } ,
806
+ state : { params : { id : { value : null , squash : true } , state : { value : null , squash : true } } } ,
801
807
} ) ;
802
808
803
809
expect ( m . format ( ) ) . toBe ( '/users' ) ;
@@ -808,7 +814,7 @@ describe('urlMatcherFactory', function() {
808
814
809
815
it ( 'should match in between static segments' , function ( ) {
810
816
const m = $umf . compile ( '/users/{user:int}/photos' , {
811
- params : { user : { value : 5 , squash : true } } ,
817
+ state : { params : { user : { value : 5 , squash : true } } } ,
812
818
} ) ;
813
819
expect ( m . exec ( '/users/photos' ) [ 'user' ] ) . toBe ( 5 ) ;
814
820
expect ( m . exec ( '/users/6/photos' ) [ 'user' ] ) . toBe ( 6 ) ;
@@ -818,9 +824,11 @@ describe('urlMatcherFactory', function() {
818
824
819
825
it ( 'should correctly format with an optional followed by a required parameter' , function ( ) {
820
826
const m = $umf . compile ( '/home/:user/gallery/photos/:photo' , {
821
- params : {
822
- user : { value : null , squash : true } ,
823
- photo : undefined ,
827
+ state : {
828
+ params : {
829
+ user : { value : null , squash : true } ,
830
+ photo : undefined ,
831
+ } ,
824
832
} ,
825
833
} ) ;
826
834
expect ( m . format ( { photo : 12 } ) ) . toBe ( '/home/gallery/photos/12' ) ;
@@ -830,7 +838,7 @@ describe('urlMatcherFactory', function() {
830
838
describe ( 'default values' , function ( ) {
831
839
it ( 'should populate if not supplied in URL' , function ( ) {
832
840
const m = $umf . compile ( '/users/{id:int}/{test}' , {
833
- params : { id : { value : 0 , squash : true } , test : { value : 'foo' , squash : true } } ,
841
+ state : { params : { id : { value : 0 , squash : true } , test : { value : 'foo' , squash : true } } } ,
834
842
} ) ;
835
843
expect ( m . exec ( '/users' ) ) . toEqual ( { id : 0 , test : 'foo' } ) ;
836
844
expect ( m . exec ( '/users/2' ) ) . toEqual ( { id : 2 , test : 'foo' } ) ;
@@ -841,7 +849,7 @@ describe('urlMatcherFactory', function() {
841
849
842
850
it ( 'should populate even if the regexp requires 1 or more chars' , function ( ) {
843
851
const m = $umf . compile ( '/record/{appId}/{recordId:[0-9a-fA-F]{10,24}}' , {
844
- params : { appId : null , recordId : null } ,
852
+ state : { params : { appId : null , recordId : null } } ,
845
853
} ) ;
846
854
expect ( m . exec ( '/record/546a3e4dd273c60780e35df3/' ) ) . toEqual ( {
847
855
appId : '546a3e4dd273c60780e35df3' ,
@@ -851,15 +859,15 @@ describe('urlMatcherFactory', function() {
851
859
852
860
it ( 'should allow shorthand definitions' , function ( ) {
853
861
const m = $umf . compile ( '/foo/:foo' , {
854
- params : { foo : 'bar' } ,
862
+ state : { params : { foo : 'bar' } } ,
855
863
} ) ;
856
864
expect ( m . exec ( '/foo/' ) ) . toEqual ( { foo : 'bar' } ) ;
857
865
} ) ;
858
866
859
867
it ( 'should populate query params' , function ( ) {
860
868
const defaults = { order : 'name' , limit : 25 , page : 1 } ;
861
869
const m = $umf . compile ( '/foo?order&{limit:int}&{page:int}' , {
862
- params : defaults ,
870
+ state : { params : defaults } ,
863
871
} ) ;
864
872
expect ( m . exec ( '/foo' ) ) . toEqual ( defaults ) ;
865
873
} ) ;
@@ -869,17 +877,17 @@ describe('urlMatcherFactory', function() {
869
877
return 'Value from bar()' ;
870
878
}
871
879
let m = $umf . compile ( '/foo/:bar' , {
872
- params : { bar : barFn } ,
880
+ state : { params : { bar : barFn } } ,
873
881
} ) ;
874
882
expect ( m . exec ( '/foo/' ) [ 'bar' ] ) . toBe ( 'Value from bar()' ) ;
875
883
876
884
m = $umf . compile ( '/foo/:bar' , {
877
- params : { bar : { value : barFn , squash : true } } ,
885
+ state : { params : { bar : { value : barFn , squash : true } } } ,
878
886
} ) ;
879
887
expect ( m . exec ( '/foo' ) [ 'bar' ] ) . toBe ( 'Value from bar()' ) ;
880
888
881
889
m = $umf . compile ( '/foo?bar' , {
882
- params : { bar : barFn } ,
890
+ state : { params : { bar : barFn } } ,
883
891
} ) ;
884
892
expect ( m . exec ( '/foo' ) [ 'bar' ] ) . toBe ( 'Value from bar()' ) ;
885
893
} ) ;
@@ -901,7 +909,7 @@ describe('urlMatcherFactory', function() {
901
909
902
910
xit ( 'should match when used as prefix' , function ( ) {
903
911
const m = $umf . compile ( '/{lang:[a-z]{2}}/foo' , {
904
- params : { lang : 'de' } ,
912
+ state : { params : { lang : 'de' } } ,
905
913
} ) ;
906
914
expect ( m . exec ( '/de/foo' ) ) . toEqual ( { lang : 'de' } ) ;
907
915
expect ( m . exec ( '/foo' ) ) . toEqual ( { lang : 'de' } ) ;
@@ -911,14 +919,16 @@ describe('urlMatcherFactory', function() {
911
919
const Session = { username : 'loggedinuser' } ;
912
920
function getMatcher ( squash ) {
913
921
return $umf . compile ( '/user/:userid/gallery/:galleryid/photo/:photoid' , {
914
- params : {
915
- userid : {
916
- squash : squash ,
917
- value : function ( ) {
918
- return Session . username ;
922
+ state : {
923
+ params : {
924
+ userid : {
925
+ squash : squash ,
926
+ value : function ( ) {
927
+ return Session . username ;
928
+ } ,
919
929
} ,
930
+ galleryid : { squash : squash , value : 'favorites' } ,
920
931
} ,
921
- galleryid : { squash : squash , value : 'favorites' } ,
922
932
} ,
923
933
} ) ;
924
934
}
@@ -991,8 +1001,10 @@ describe('urlMatcherFactory', function() {
991
1001
it ( 'should match when defined with parameters' , function ( ) {
992
1002
const m = $umf . compile ( '/users/{name}' , {
993
1003
strict : false ,
994
- params : {
995
- name : { value : null } ,
1004
+ state : {
1005
+ params : {
1006
+ name : { value : null } ,
1007
+ } ,
996
1008
} ,
997
1009
} ) ;
998
1010
expect ( m . exec ( '/users/' ) ) . toEqual ( { name : null } ) ;