@@ -11,11 +11,11 @@ describe("UrlUtility", function() {
1111 it ( "should add ? if not present" , function ( ) {
1212 UrlUtility . addQueryParam ( "url" , "foo" , "test" ) . should . equal ( "url?foo=test" ) ;
1313 } ) ;
14-
14+
1515 it ( "should not add ? if already present" , function ( ) {
1616 UrlUtility . addQueryParam ( "url?" , "foo" , "test" ) . should . equal ( "url?foo=test" ) ;
1717 } ) ;
18-
18+
1919 it ( "should add & if needed" , function ( ) {
2020 UrlUtility . addQueryParam ( "url?x=1" , "foo" , "test" ) . should . equal ( "url?x=1&foo=test" ) ;
2121 } ) ;
@@ -24,5 +24,38 @@ describe("UrlUtility", function() {
2424 UrlUtility . addQueryParam ( "url" , "#" , "#" ) . should . equal ( "url?%23=%23" ) ;
2525 } ) ;
2626 } ) ;
27-
27+
28+ describe ( "parseUrlFragment" , function ( ) {
29+
30+ it ( "should parse key/value pairs" , function ( ) {
31+ let result = UrlUtility . parseUrlFragment ( "a=apple&b=banana&c=carrot" ) ;
32+ result . should . deep . equal ( { a : "apple" , b : "banana" , c : "carrot" } ) ;
33+ } ) ;
34+
35+ it ( "should parse any order" , function ( ) {
36+ let result = UrlUtility . parseUrlFragment ( "b=banana&c=carrot&a=apple" ) ;
37+ result . should . deep . equal ( { a : "apple" , b : "banana" , c : "carrot" } ) ;
38+ } ) ;
39+
40+ it ( "should parse past host name and hash fragment" , function ( ) {
41+ let result = UrlUtility . parseUrlFragment ( "http://server?test1=xoxo&test2=xoxo/#a=apple&b=banana&c=carrot" ) ;
42+ result . should . deep . equal ( { a : "apple" , b : "banana" , c : "carrot" } ) ;
43+ } ) ;
44+
45+ it ( "should return error for long values" , function ( ) {
46+ let result = UrlUtility . parseUrlFragment ( "a=apple&a=apple&a=apple&a=apple&a=apple&a=apple&a=apple&a=apple&a=apple&a=apple&a=apple&a=apple&a=apple&a=apple&a=apple&a=apple&a=apple&a=apple&a=apple&a=apple&a=apple&a=apple&a=apple&a=apple&a=apple&a=apple&a=apple&a=apple&a=apple&a=apple&a=apple&a=apple&a=apple&a=apple&a=apple&a=apple&a=apple&a=apple&a=apple&a=apple&a=apple&a=apple&a=apple&a=apple&a=apple&a=apple&a=apple&a=apple&a=apple&a=apple&a=apple&a=apple&a=apple&a=apple&a=apple&a=apple&a=apple&a=apple&a=apple&a=apple&a=apple&a=apple&a=apple&a=apple&a=apple&a=apple&a=apple&a=apple&a=apple&a=apple&a=apple&a=apple&a=apple&a=apple&a=apple&a=apple&a=apple&a=apple&a=apple&a=apple&a=apple&a=apple&a=apple&a=apple&a=apple&a=apple&a=apple&a=apple&a=apple&a=apple&a=apple&a=apple&a=apple&a=apple&a=apple&a=apple&a=apple&a=apple&a=apple&a=apple&a=apple&a=apple&a=apple&a=apple&a=apple&a=apple&a=apple&a=apple&a=apple&a=apple&a=apple&a=apple&a=apple&a=apple&a=apple&a=apple&a=apple&a=apple&a=apple&a=apple" ) ;
47+ result . should . have . property ( 'error' ) ;
48+ } ) ;
49+
50+ it ( "should use window.location.hash when no value is passed" , function ( ) {
51+ let w = {
52+ location : {
53+ hash : "a=apple&b=banana&c=carrot"
54+ }
55+ } ;
56+ let result = UrlUtility . parseUrlFragment ( null , w ) ;
57+ result . should . deep . equal ( { a : "apple" , b : "banana" , c : "carrot" } ) ;
58+ } ) ;
59+ } ) ;
60+
2861} ) ;
0 commit comments