Commit f6d41d50 authored by Ryan Herbert's avatar Ryan Herbert Committed by marc duez

url_test.js refactor windowMock

In order to test the url parameters and positional parameters, we need a
more functional windowMock, that will have a slightly closer
functionality to the real thing.
parent 29d69e50
......@@ -3,16 +3,37 @@ QUnit.module("Url", {
});
/* ------------------------------------ */
var current_url = "mock://"
var initial_url = "mock://";
var current_url = initial_url;
function getSearch(url) {
var search = url.split('?')[1] ;
return (search == "" ? "" : '?' + search)
}
function getPathname(url) {
// remove protocol
var pathname = url.split('//');
pathname = pathname[1];
// remove search
pathname = pathname.split('?')[0];
// remove hostname
pathname = pathname.split('/');
return '/' + pathname.slice(1).join('/');
}
var windowMock = {
mocked: true,
location: {
search: {
toString: function() { var search = (current_url + '?').split('?')[1] ;
return (search == "" ? "" : '?' + search) }
}},
search: "",
pathname: ""
},
history: {
pushState: function(x, y, url) { current_url = url }
pushState: function(x, y, url) {
current_url = url;
windowMock.location.search = getSearch(url);
windowMock.location.pathname = getPathname(url);
}
}
};
windowMock.window = windowMock
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment