Merge branch 'master' into jsrefactor and fixing baseUri unit test

This commit is contained in:
El RIDO
2017-03-05 12:11:55 +01:00
13 changed files with 195 additions and 51 deletions

View File

@@ -36,11 +36,9 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) {
/**
* static Helper methods
*
* @param {object} window
* @param {object} document
* @class
*/
var Helper = (function (window, document) {
var Helper = (function () {
var me = {};
/**
@@ -278,14 +276,19 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) {
return baseUri;
}
// get official base uri string, from base tag in head of HTML
baseUri = document.baseURI;
// window.baseURI isn't emulated by JSdom
var loc = window.location;
baseUri = loc.href.substring(
0,
loc.href.length - loc.search.length - loc.hash.length
);
// if base uri contains query string (when no base tag is present),
// it is unwanted
if (baseUri.indexOf('?')) {
var queryIndex = baseUri.indexOf('?');
if (queryIndex !== -1) {
// so we built our own baseuri
baseUri = window.location.origin + window.location.pathname;
baseUri = baseUri.substring(0, queryIndex);
}
return baseUri;
@@ -307,8 +310,19 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) {
});
}
/**
* resets state, used for unit testing
*
* @name Model.reset
* @function
*/
me.reset = function()
{
baseUri = null;
}
return me;
})(window, document);
})();
/**
* internationalization module
@@ -336,7 +350,7 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) {
* @prop {string[]}
* @readonly
*/
var supportedLanguages = ['de', 'es', 'fr', 'it', 'no', 'pl', 'oc', 'ru', 'sl', 'zh'];
var supportedLanguages = ['de', 'es', 'fr', 'it', 'no', 'pl', 'pt', 'oc', 'ru', 'sl', 'zh'];
/**
* built in language
@@ -491,7 +505,7 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) {
return (n % 10 === 1 && n % 100 !== 11 ? 0 : (n % 10 >= 2 && n % 10 <= 4 && (n % 100 < 10 || n % 100 >= 20) ? 1 : 2));
case 'sl':
return (n % 100 === 1 ? 1 : (n % 100 === 2 ? 2 : (n % 100 === 3 || n % 100 === 4 ? 3 : 0)));
// de, en, es, it, no
// de, en, es, it, no, pt
default:
return (n !== 1 ? 1 : 0);
}

View File

@@ -67,6 +67,10 @@ describe('Helper', function () {
});
describe('baseUri', function () {
before(function () {
$.PrivateBin.Helper.reset();
});
jsc.property(
'returns the URL without query & fragment',
jsc.nearray(jsc.elements(a2zString)),
@@ -77,6 +81,7 @@ describe('Helper', function () {
var expected = schema.join('') + '://' + address.join('') + '/',
clean = jsdom('', {url: expected + '?' + query.join('') + '#' + fragment}),
result = $.PrivateBin.Helper.baseUri();
$.PrivateBin.Helper.reset();
clean();
return expected === result;
}
@@ -101,6 +106,10 @@ describe('Helper', function () {
describe('Model', function () {
describe('getPasteId', function () {
before(function () {
$.PrivateBin.Model.reset();
});
jsc.property(
'returns the query string without separator, if any',
jsc.nearray(jsc.elements(a2zString)),