diff options
author | Vincent Petry <pvince81@owncloud.com> | 2014-01-24 12:44:31 +0100 |
---|---|---|
committer | Vincent Petry <pvince81@owncloud.com> | 2014-01-24 12:44:31 +0100 |
commit | 41b6d4b702e8ed32f7ea51edffd0005639f77138 (patch) | |
tree | 23b3ffa6bcb16115f4eed84680f5962c5b3484da /core/js/tests | |
parent | 9fa788c452403646cc5c2a7c0fe875879e7082fa (diff) | |
download | nextcloud-server-41b6d4b702e8ed32f7ea51edffd0005639f77138.tar.gz nextcloud-server-41b6d4b702e8ed32f7ea51edffd0005639f77138.zip |
Added OC.buidQueryString() utility function
Makes it possible to create query strings by passing a JavaScript hash
map and automatically encodes the keys and values.
Diffstat (limited to 'core/js/tests')
-rw-r--r-- | core/js/tests/specs/coreSpec.js | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/core/js/tests/specs/coreSpec.js b/core/js/tests/specs/coreSpec.js index 827669f270b..28c20a0642e 100644 --- a/core/js/tests/specs/coreSpec.js +++ b/core/js/tests/specs/coreSpec.js @@ -67,4 +67,41 @@ describe('Core base tests', function() { }); }); }); + describe('Query string building', function() { + it('Returns empty string when empty params', function() { + expect(OC.buildQueryString()).toEqual(''); + expect(OC.buildQueryString({})).toEqual(''); + }); + it('Encodes regular query strings', function() { + expect(OC.buildQueryString({ + a: 'abc', + b: 'def' + })).toEqual('a=abc&b=def'); + }); + it('Encodes special characters', function() { + expect(OC.buildQueryString({ + unicode: '汉字', + })).toEqual('unicode=%E6%B1%89%E5%AD%97'); + expect(OC.buildQueryString({ + b: 'spaace value', + 'space key': 'normalvalue', + 'slash/this': 'amp&ersand' + })).toEqual('b=spaace%20value&space%20key=normalvalue&slash%2Fthis=amp%26ersand'); + }); + it('Encodes data types and empty values', function() { + expect(OC.buildQueryString({ + 'keywithemptystring': '', + 'keywithnull': null, + 'keywithundefined': null, + something: 'else' + })).toEqual('keywithemptystring=&keywithnull&keywithundefined&something=else'); + expect(OC.buildQueryString({ + 'booleanfalse': false, + 'booleantrue': true + })).toEqual('booleanfalse=false&booleantrue=true'); + expect(OC.buildQueryString({ + 'number': 123, + })).toEqual('number=123'); + }); + }); }); |