had to introduce a mock function to test the historyChange state

This commit is contained in:
El RIDO 2017-10-22 09:56:44 +02:00
parent 379571d522
commit 6dbb098d7a
No known key found for this signature in database
GPG Key ID: 0F5C940A6BD81F92
4 changed files with 20 additions and 8 deletions

View File

@ -866,7 +866,7 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) {
{
var currentLocation = Helper.baseUri();
if (event.originalEvent.state === null && // no state object passed
event.originalEvent.target.location.href === currentLocation && // target location is home page
event.target.location.href === currentLocation && // target location is home page
window.location.href === currentLocation // and we are not already on the home page
) {
// redirect to home page
@ -958,6 +958,19 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) {
});
}
/**
* trigger a history (pop) state change
*
* used to test the UiHelper.historyChange private function
*
* @name UiHelper.mockHistoryChange
* @function
*/
me.mockHistoryChange = function()
{
historyChange($.Event('popstate', {originalEvent: new PopStateEvent('popstate', {state: null}), target: window}));
}
/**
* initialize
*

View File

@ -2,7 +2,6 @@
var jsc = require('jsverify'),
jsdom = require('jsdom-global'),
cleanup = jsdom(),
EventEmitter = require('events'),
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'],
@ -824,6 +823,8 @@ describe('UiHelper', function () {
$.PrivateBin.Helper.reset();
});
// TODO: As per https://github.com/tmpvar/jsdom/issues/1565 there is no navigation support in jsdom, yet.
// for now we use a mock function to trigger the event
jsc.property(
'returns the URL without query & fragment',
jsc.elements(schemas),
@ -832,11 +833,9 @@ describe('UiHelper', function () {
'string',
function (schema, address, query, fragment) {
var expected = schema + '://' + address.join('') + '/',
clean = jsdom('', {url: expected + '?' + query.join('') + '#' + fragment}),
emitter = new EventEmitter();
clean = jsdom('', {url: expected + '?' + query.join('') + '#' + fragment});
$.PrivateBin.UiHelper.init();
emitter.emit('popstate');
$.PrivateBin.UiHelper.mockHistoryChange();
var result = window.location.href;
clean();
console.log(expected, result);

View File

@ -69,7 +69,7 @@ if ($MARKDOWN):
<?php
endif;
?>
<script type="text/javascript" src="js/privatebin.js?<?php echo rawurlencode($VERSION); ?>" integrity="sha512-gTAGAlxWTLH1PaXA4q9l0kME8wPPWi2iub5uU7HZ3A2bisLtjMIsaZ/Ecu4+sawFvvedAzbh9Y4rR34Ct3oF5Q==" crossorigin="anonymous"></script>
<script type="text/javascript" src="js/privatebin.js?<?php echo rawurlencode($VERSION); ?>" integrity="sha512-08YP16cuZ9x9zHHsPLEnAQU2vD8xXFGD0KYfYZeRkje8hSUhf/j1F1ifWKZCVoZST2XXA1PJjnVHTcKxeWAGNA==" crossorigin="anonymous"></script>
<!--[if lt IE 10]>
<style type="text/css">body {padding-left:60px;padding-right:60px;} #ienotice {display:block;} #oldienotice {display:block;}</style>
<![endif]-->

View File

@ -47,7 +47,7 @@ if ($MARKDOWN):
<?php
endif;
?>
<script type="text/javascript" src="js/privatebin.js?<?php echo rawurlencode($VERSION); ?>" integrity="sha512-gTAGAlxWTLH1PaXA4q9l0kME8wPPWi2iub5uU7HZ3A2bisLtjMIsaZ/Ecu4+sawFvvedAzbh9Y4rR34Ct3oF5Q==" crossorigin="anonymous"></script>
<script type="text/javascript" src="js/privatebin.js?<?php echo rawurlencode($VERSION); ?>" integrity="sha512-08YP16cuZ9x9zHHsPLEnAQU2vD8xXFGD0KYfYZeRkje8hSUhf/j1F1ifWKZCVoZST2XXA1PJjnVHTcKxeWAGNA==" crossorigin="anonymous"></script>
<!--[if lt IE 10]>
<style type="text/css">body {padding-left:60px;padding-right:60px;} #ienotice {display:block;} #oldienotice {display:block;}</style>
<![endif]-->