summaryrefslogtreecommitdiffstats
path: root/core/js/tests
diff options
context:
space:
mode:
authorVincent Petry <pvince81@owncloud.com>2015-07-10 13:01:01 +0200
committerVincent Petry <pvince81@owncloud.com>2015-07-10 13:02:28 +0200
commit119e27166e69d70e7fee697fe1a6b7c2f0839ece (patch)
tree9380700fae62438dcdba02d7723a62cbd8e217b8 /core/js/tests
parent87f3500fda04f76d97754185a71f285e9770c66c (diff)
downloadnextcloud-server-119e27166e69d70e7fee697fe1a6b7c2f0839ece.tar.gz
nextcloud-server-119e27166e69d70e7fee697fe1a6b7c2f0839ece.zip
Add OC.joinPaths for convenient path joining
Diffstat (limited to 'core/js/tests')
-rw-r--r--core/js/tests/specs/coreSpec.js38
1 files changed, 38 insertions, 0 deletions
diff --git a/core/js/tests/specs/coreSpec.js b/core/js/tests/specs/coreSpec.js
index 6f7a34d21c8..5caaf109bf1 100644
--- a/core/js/tests/specs/coreSpec.js
+++ b/core/js/tests/specs/coreSpec.js
@@ -134,6 +134,44 @@ describe('Core base tests', function() {
expect(escapeHTML('This is a good string without HTML.')).toEqual('This is a good string without HTML.');
});
});
+ describe('joinPaths', function() {
+ it('returns empty string with no or empty arguments', function() {
+ expect(OC.joinPaths()).toEqual('');
+ expect(OC.joinPaths('')).toEqual('');
+ expect(OC.joinPaths('', '')).toEqual('');
+ });
+ it('returns joined path sections', function() {
+ expect(OC.joinPaths('abc')).toEqual('abc');
+ expect(OC.joinPaths('abc', 'def')).toEqual('abc/def');
+ expect(OC.joinPaths('abc', 'def', 'ghi')).toEqual('abc/def/ghi');
+ });
+ it('keeps leading slashes', function() {
+ expect(OC.joinPaths('/abc')).toEqual('/abc');
+ expect(OC.joinPaths('/abc', 'def')).toEqual('/abc/def');
+ expect(OC.joinPaths('/abc', 'def', 'ghi')).toEqual('/abc/def/ghi');
+ });
+ it('keeps trailing slashes', function() {
+ expect(OC.joinPaths('abc/')).toEqual('abc/');
+ expect(OC.joinPaths('abc', 'def/')).toEqual('abc/def/');
+ expect(OC.joinPaths('abc', 'def', 'ghi/')).toEqual('abc/def/ghi/');
+ });
+ it('splits paths in specified strings and discards extra slashes', function() {
+ expect(OC.joinPaths('//abc//')).toEqual('/abc/');
+ expect(OC.joinPaths('//abc//def//')).toEqual('/abc/def/');
+ expect(OC.joinPaths('//abc//', '//def//')).toEqual('/abc/def/');
+ expect(OC.joinPaths('//abc//', '//def//', '//ghi//')).toEqual('/abc/def/ghi/');
+ expect(OC.joinPaths('//abc//def//', '//ghi//jkl/mno/', '//pqr//'))
+ .toEqual('/abc/def/ghi/jkl/mno/pqr/');
+ });
+ it('discards empty sections', function() {
+ expect(OC.joinPaths('abc', '', 'def')).toEqual('abc/def');
+ });
+ it('returns root if only slashes', function() {
+ expect(OC.joinPaths('//')).toEqual('/');
+ expect(OC.joinPaths('/', '/')).toEqual('/');
+ expect(OC.joinPaths('/', '//', '/')).toEqual('/');
+ });
+ });
describe('filePath', function() {
beforeEach(function() {
OC.webroot = 'http://localhost';