writing test for scriptLocation function, fixing non-removed query separator bug
This commit is contained in:
parent
5442af6e20
commit
80f7baa604
|
@ -259,7 +259,8 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) {
|
|||
var scriptLocation = window.location.href.substring(
|
||||
0,
|
||||
window.location.href.length - window.location.search.length - window.location.hash.length
|
||||
), hashIndex = scriptLocation.indexOf('#');
|
||||
),
|
||||
hashIndex = scriptLocation.indexOf('?');
|
||||
if (hashIndex !== -1)
|
||||
{
|
||||
scriptLocation = scriptLocation.substring(0, hashIndex);
|
||||
|
|
40
js/test.js
40
js/test.js
|
@ -1,22 +1,20 @@
|
|||
'use strict';
|
||||
var jsc = require('jsverify');
|
||||
|
||||
before(function () {
|
||||
this.jsdom = require('jsdom-global')();
|
||||
var jsc = require('jsverify'),
|
||||
jsdom = require('jsdom-global'),
|
||||
cleanup = jsdom();
|
||||
global.$ = global.jQuery = require('./jquery-3.1.1');
|
||||
global.sjcl = require('./sjcl-1.0.6');
|
||||
global.Base64 = require('./base64-2.1.9');
|
||||
global.RawDeflate = require('./rawdeflate-0.5');
|
||||
require('./rawinflate-0.3');
|
||||
require('./privatebin');
|
||||
})
|
||||
|
||||
after(function () {
|
||||
this.jsdom();
|
||||
})
|
||||
|
||||
describe('helper', function () {
|
||||
describe('secondsToHuman', function () {
|
||||
after(function () {
|
||||
cleanup();
|
||||
});
|
||||
|
||||
jsc.property('returns an array with a number and a word', 'integer', function (number) {
|
||||
var result = $.PrivateBin.helper.secondsToHuman(number);
|
||||
return Array.isArray(result) &&
|
||||
|
@ -56,5 +54,29 @@ describe('helper', function () {
|
|||
return $.PrivateBin.helper.secondsToHuman(number)[1] === 'month';
|
||||
});
|
||||
});
|
||||
|
||||
describe('scriptLocation', function () {
|
||||
after(function () {
|
||||
cleanup();
|
||||
});
|
||||
|
||||
var a2zString = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'],
|
||||
alnumString = a2zString.concat(['0','1','2','3','4','5','6','7','8','9']),
|
||||
queryString = alnumString.concat(['+','%','&','.','*','-','_']);
|
||||
jsc.property(
|
||||
'returns the URL without query & fragment',
|
||||
jsc.nearray(jsc.elements(a2zString)),
|
||||
jsc.nearray(jsc.elements(a2zString)),
|
||||
jsc.array(jsc.elements(queryString)),
|
||||
'string',
|
||||
function (schema, address, query, fragment) {
|
||||
var expected = schema.join('') + '://' + address.join('') + '/',
|
||||
clean = jsdom('', {url: expected + '?' + query.join('') + '#' + fragment}),
|
||||
result = $.PrivateBin.helper.scriptLocation();
|
||||
clean();
|
||||
return expected === result;
|
||||
}
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in New Issue