Skip to content

Commit

Permalink
join url tests written
Browse files Browse the repository at this point in the history
  • Loading branch information
keattang committed Sep 30, 2015
1 parent 583b449 commit 45b93fb
Show file tree
Hide file tree
Showing 2 changed files with 101 additions and 13 deletions.
2 changes: 1 addition & 1 deletion Source/Core/joinUrls.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ define(['../ThirdParty/Uri'],
*/
var joinUrls = function(first, second, appendSlash) {

appendSlash = typeof addSlash !== 'undefined' ? appendSlash : true;
appendSlash = typeof appendSlash !== 'undefined' ? appendSlash : true;

if (!(first instanceof URI)) {
first = new URI(first);
Expand Down
112 changes: 100 additions & 12 deletions Specs/Core/joinUrlsSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,31 +8,119 @@ defineSuite([
"use strict";
/*global jasmine,describe,xdescribe,it,xit,expect,beforeEach,afterEach,beforeAll,afterAll,spyOn*/

var qulifiedUrl = "http://www.url.com";
var qulifiedUrlWithPath= "http://www.url.com/some/path";
var queryString = "a=some&b=query";

var qualifiedUrl = "http://www.url.com";
var qualifiedUrlWithQueryString = "http://www.url.com" + "?" + queryString;
var qualifiedUrlWithPath = "http://www.url.com/some/path";

var absolutePath = "/some/path";
var absolutePathWithQueryString = absolutePath + "?" + queryString;
var relativePath = "some/path";

var absoluteFileUrl = "/file.extension";
var relativeFileUrl = "file.extension";
var expectedQualifiedUrl = qualifiedUrl + absolutePath;

var expectedRelativePath = relativePath + absolutePath;
var expectedAbsolutePath = absolutePath + absolutePath;

var expectedQualifiedUrlWithQueryString = expectedQualifiedUrl + "?" + queryString;
var expectedAbsolutePathWithQueryString = expectedAbsolutePath + "?" + queryString;

var qualifiedUri = new URI(qualifiedUrl);
var pathUri = new URI(absolutePath);

it('appends slash by default', function() {
expect(joinUrls(qualifiedUrl, absolutePath)).toEqual(expectedQualifiedUrl);
});

it('does not append slash when appendSlash is false', function() {
expect(joinUrls(absolutePath, relativePath, false)).toEqual(absolutePath+relativePath);
});

it('appends absolute path correctly to qualified url', function() {
expect(joinUrls(qualifiedUrl, absolutePath)).toEqual(expectedQualifiedUrl);
});

it('appends relative path correctly to qualified url', function() {
expect(joinUrls(qualifiedUrl, absolutePath)).toEqual(expectedQualifiedUrl);
});

it('appends absolute path correctly to qualified url with path', function() {
expect(joinUrls(qualifiedUrlWithPath, absolutePath))
.toEqual(qualifiedUrlWithPath+absolutePath);
});

it('appends relative path correctly to qualified url with path', function() {
expect(joinUrls(qualifiedUrlWithPath, relativePath))
.toEqual(qualifiedUrlWithPath+absolutePath);
});

it('appendes relative path correctly to relative path', function() {
expect(joinUrls(relativePath, relativePath)).toEqual(expectedRelativePath);
});

it('appendes absolute path correctly to relative path', function() {
expect(joinUrls(relativePath, absolutePath)).toEqual(expectedRelativePath);
});

it('appendes relative path correctly to absolute path', function() {
expect(joinUrls(absolutePath, relativePath)).toEqual(expectedAbsolutePath);
});

it('appendes absolute path correctly to absolute path', function() {
expect(joinUrls(absolutePath, absolutePath)).toEqual(expectedAbsolutePath);
});

it('appendes qualfied url correctly to qualified url', function() {
expect(joinUrls(qualifiedUrl, qualifiedUrl)).toEqual(qualifiedUrl+"/");
});

it('appendes qualfied url correctly to qualified url with path', function() {
expect(joinUrls(qualifiedUrl, qualifiedUrlWithPath)).toEqual(expectedQualifiedUrl);
});

it('appendes qualfied url with path correctly to qualified url', function() {
expect(joinUrls(qualifiedUrl, qualifiedUrlWithPath)).toEqual(expectedQualifiedUrl);
});

it('appends correctly to qulified url', function() {
expect(joinUrls(goodFirstUrl1, goodSecondUrl2, false)).toEqual(goodFirstUrl1+goodSecondUrl2);
it('appendes qualfied url with path correctly to qualified url with path', function() {
expect(joinUrls(qualifiedUrlWithPath, qualifiedUrlWithPath))
.toEqual(qualifiedUrlWithPath+absolutePath);
});

it('appendes correctly to url path', function() {
expect(joinUrls(goodFirstUrl2, goodSecondUrl2, false)).toEqual(goodFirstUrl2+goodSecondUrl2);
it('appends absolute path correctly to qualified url with query string', function() {
expect(joinUrls(qualifiedUrlWithQueryString, absolutePath))
.toEqual(expectedQualifiedUrlWithQueryString);
});

it('works when appendSlash is undefined', function() {
expect(joinUrls(goodFirstUrl1, goodSecondUrl2)).toEqual(true);
it('appends relative path correctly to qualified url with query string', function() {
expect(joinUrls(qualifiedUrlWithQueryString, relativePath)).
toEqual(expectedQualifiedUrlWithQueryString);
});

it('appendes correctly when both urls are qualified', function() {
expect(joinUrls(goodFirstUrl2, goodSecondUrl2, false)).toEqual(goodFirstUrl1+goodSecondUrl2);
it('appends absolute path correctly to absolute path with query string', function() {
expect(joinUrls(absolutePathWithQueryString, absolutePath))
.toEqual(expectedAbsolutePathWithQueryString);
});

it('appends relative path correctly to absolute path with query string', function() {
expect(joinUrls(absolutePathWithQueryString, relativePath))
.toEqual(expectedAbsolutePathWithQueryString);
});

it('appends absolute path with query string correctly to absolute path with query string', function() {
expect(joinUrls(absolutePathWithQueryString, absolutePathWithQueryString))
.toEqual(expectedAbsolutePathWithQueryString + "&" + queryString);
});

it('accepts URIs', function() {
expect(joinUrls(qualifiedUri, pathUri))
.toEqual(expectedQualifiedUrl);
});

it('accepts URIs and strings', function() {
expect(joinUrls(qualifiedUri, absolutePath))
.toEqual(expectedQualifiedUrl);
});

});

0 comments on commit 45b93fb

Please sign in to comment.