introduce built in asserts, working on TopNav, correcting some docs

This commit is contained in:
El RIDO 2018-03-01 06:43:30 +01:00
parent cb2af8687e
commit ce6764e97d
No known key found for this signature in database
GPG Key ID: 0F5C940A6BD81F92
8 changed files with 183 additions and 17 deletions

View File

@ -1,6 +1,7 @@
'use strict'; 'use strict';
// testing prerequisites // testing prerequisites
global.assert = require('assert');
global.jsc = require('jsverify'); global.jsc = require('jsverify');
global.jsdom = require('jsdom-global'); global.jsdom = require('jsdom-global');
global.cleanup = global.jsdom(); global.cleanup = global.jsdom();

View File

@ -1290,7 +1290,7 @@ jQuery.PrivateBin = (function($, sjcl, Base64, RawDeflate) {
/** /**
* hides the remaining time and successful upload notification * hides the remaining time and successful upload notification
* *
* @name PasteStatus.hideRemainingTime * @name PasteStatus.hideMessages
* @function * @function
*/ */
me.hideMessages = function() me.hideMessages = function()
@ -2884,6 +2884,9 @@ jQuery.PrivateBin = (function($, sjcl, Base64, RawDeflate) {
// get default value from template or fall back to set value // get default value from template or fall back to set value
pasteExpiration = Model.getExpirationDefault() || pasteExpiration; pasteExpiration = Model.getExpirationDefault() || pasteExpiration;
createButtonsDisplayed = false;
viewButtonsDisplayed = false;
}; };
return me; return me;

View File

@ -141,8 +141,10 @@ describe('Alert', function () {
$('body').addClass('loading'); $('body').addClass('loading');
$.PrivateBin.Alert.init(); $.PrivateBin.Alert.init();
$.PrivateBin.Alert.hideLoading(); $.PrivateBin.Alert.hideLoading();
return !$('body').hasClass('loading') && assert.ok(
$('#loadingindicator').hasClass('hidden'); !$('body').hasClass('loading') &&
$('#loadingindicator').hasClass('hidden')
);
} }
); );
}); });
@ -165,8 +167,10 @@ describe('Alert', function () {
); );
$.PrivateBin.Alert.init(); $.PrivateBin.Alert.init();
$.PrivateBin.Alert.hideMessages(); $.PrivateBin.Alert.hideMessages();
return $('#statusmessage').hasClass('hidden') && assert.ok(
$('#errormessage').hasClass('hidden'); $('#status').hasClass('hidden') &&
$('#errormessage').hasClass('hidden')
);
} }
); );
}); });

View File

@ -87,9 +87,10 @@ describe('CryptTool', function () {
'MZtmnYpGAtAPg7AUG"}' 'MZtmnYpGAtAPg7AUG"}'
); );
if (!paste1.includes('securely packed in iron') || !paste2.includes('Sol is right')) { assert.ok(
throw Error('v1 (SJCL based) pastes could not be deciphered'); paste1.includes('securely packed in iron') &&
} paste2.includes('Sol is right')
);
} }
); );
@ -152,9 +153,10 @@ describe('CryptTool', function () {
jsdom(); jsdom();
delete require.cache[require.resolve('../privatebin')]; delete require.cache[require.resolve('../privatebin')];
require('../privatebin'); require('../privatebin');
if (!paste1.includes('securely packed in iron') || !paste2.includes('Sol is right')) { assert.ok(
throw Error('v1 (SJCL based) pastes could not be deciphered'); paste1.includes('securely packed in iron') &&
} paste2.includes('Sol is right')
);
} }
); );
}); });

View File

@ -96,8 +96,10 @@ describe('PasteStatus', function () {
); );
$.PrivateBin.PasteStatus.init(); $.PrivateBin.PasteStatus.init();
$.PrivateBin.PasteStatus.hideMessages(); $.PrivateBin.PasteStatus.hideMessages();
return $('#remainingtime').hasClass('hidden') && assert.ok(
$('#pastesuccess').hasClass('hidden'); $('#remainingtime').hasClass('hidden') &&
$('#pastesuccess').hasClass('hidden')
);
} }
); );
}); });

View File

@ -52,7 +52,7 @@ describe('TopNav', function () {
$('#qrcodelink').hasClass('hidden') $('#qrcodelink').hasClass('hidden')
); );
cleanup(); cleanup();
return results.every(element => element); assert.ok(results.every(element => element));
} }
); );
}); });
@ -113,7 +113,161 @@ describe('TopNav', function () {
$('#attach').hasClass('hidden') $('#attach').hasClass('hidden')
); );
cleanup(); cleanup();
return results.every(element => element); assert.ok(results.every(element => element));
}
);
});
describe('showNewPasteButton', function () {
before(function () {
cleanup();
});
it(
'displays the button for creating a paste',
function () {
var results = [];
$('body').html(
'<nav><div id="navbar"><ul><li><button id="newbutton" type=' +
'"button" class="hidden">New</button></li></ul></div></nav>'
);
$.PrivateBin.TopNav.init();
results.push(
$('#newbutton').hasClass('hidden')
);
$.PrivateBin.TopNav.showNewPasteButton();
results.push(
!$('#newbutton').hasClass('hidden')
);
cleanup();
assert.ok(results.every(element => element));
}
);
});
describe('hideCloneButton', function () {
before(function () {
cleanup();
});
it(
'hides the button for cloning a paste',
function () {
var results = [];
$('body').html(
'<nav><div id="navbar"><ul><li><button id="clonebutton" ' +
'type="button" class="btn btn-warning navbar-btn">' +
'<span class="glyphicon glyphicon-duplicate" aria-hidden=' +
'"true"></span> Clone</button></li></ul></div></nav>'
);
$.PrivateBin.TopNav.init();
results.push(
!$('#clonebutton').hasClass('hidden')
);
$.PrivateBin.TopNav.hideCloneButton();
results.push(
$('#clonebutton').hasClass('hidden')
);
cleanup();
assert.ok(results.every(element => element));
}
);
});
describe('hideRawButton', function () {
before(function () {
cleanup();
});
it(
'hides the raw text button',
function () {
var results = [];
$('body').html(
'<nav><div id="navbar"><ul><li><button ' +
'id="rawtextbutton" type="button" class="btn ' +
'btn-warning navbar-btn"><span class="glyphicon ' +
'glyphicon-text-background" aria-hidden="true"></span> ' +
'Raw text</button></li></ul></div></nav>'
);
$.PrivateBin.TopNav.init();
results.push(
!$('#rawtextbutton').hasClass('hidden')
);
$.PrivateBin.TopNav.hideRawButton();
results.push(
$('#rawtextbutton').hasClass('hidden')
);
cleanup();
assert.ok(results.every(element => element));
}
);
});
describe('hideFileSelector', function () {
before(function () {
cleanup();
});
it(
'hides the file attachment selection button',
function () {
var results = [];
$('body').html(
'<nav><div id="navbar"><ul><li id="attach" class="hidden ' +
'dropdown"><a href="#" class="dropdown-toggle" data-' +
'toggle="dropdown" role="button" aria-haspopup="true" ' +
'aria-expanded="false">Attach a file <span class="caret">' +
'</span></a><ul class="dropdown-menu"><li id="filewrap">' +
'<div><input type="file" id="file" name="file" /></div>' +
'</li><li id="customattachment" class="hidden"></li><li>' +
'<a id="fileremovebutton" href="#">Remove attachment</a>' +
'</li></ul></li></ul></div></nav>'
);
$.PrivateBin.TopNav.init();
results.push(
!$('#filewrap').hasClass('hidden')
);
$.PrivateBin.TopNav.hideFileSelector();
results.push(
$('#filewrap').hasClass('hidden')
);
cleanup();
assert.ok(results.every(element => element));
}
);
});
describe('showCustomAttachment', function () {
before(function () {
cleanup();
});
it(
'display the custom file attachment',
function () {
var results = [];
$('body').html(
'<nav><div id="navbar"><ul><li id="attach" class="hidden ' +
'dropdown"><a href="#" class="dropdown-toggle" data-' +
'toggle="dropdown" role="button" aria-haspopup="true" ' +
'aria-expanded="false">Attach a file <span class="caret">' +
'</span></a><ul class="dropdown-menu"><li id="filewrap">' +
'<div><input type="file" id="file" name="file" /></div>' +
'</li><li id="customattachment" class="hidden"></li><li>' +
'<a id="fileremovebutton" href="#">Remove attachment</a>' +
'</li></ul></li></ul></div></nav>'
);
$.PrivateBin.TopNav.init();
results.push(
$('#customattachment').hasClass('hidden')
);
$.PrivateBin.TopNav.showCustomAttachment();
results.push(
!$('#customattachment').hasClass('hidden')
);
cleanup();
assert.ok(results.every(element => element));
} }
); );
}); });

View File

@ -75,7 +75,7 @@ if ($MARKDOWN):
<?php <?php
endif; endif;
?> ?>
<script type="text/javascript" src="js/privatebin.js?<?php echo rawurlencode($VERSION); ?>" integrity="sha512-1taLHBI+tdu4RhEpnqw4JfGHePYdAmO9zwrIFh5Ym1R4XJWt4ls/3br9u/6kS5dN8s5RqZSRUz/nmsaauwUzAA==" crossorigin="anonymous"></script> <script type="text/javascript" src="js/privatebin.js?<?php echo rawurlencode($VERSION); ?>" integrity="sha512-Z3SG68lkzr8/Hg8goFersCg5T8qrI2dUKDCRnlA6uZanWLiKRCBBX8gNHgjSdPp/+XC3fFFTGL3KCZFgCXXdtQ==" crossorigin="anonymous"></script>
<!--[if lt IE 10]> <!--[if lt IE 10]>
<style type="text/css">body {padding-left:60px;padding-right:60px;} #ienotice {display:block;} #oldienotice {display:block;}</style> <style type="text/css">body {padding-left:60px;padding-right:60px;} #ienotice {display:block;} #oldienotice {display:block;}</style>
<![endif]--> <![endif]-->

View File

@ -54,7 +54,7 @@ if ($QRCODE):
<?php <?php
endif; endif;
?> ?>
<script type="text/javascript" src="js/privatebin.js?<?php echo rawurlencode($VERSION); ?>" integrity="sha512-1taLHBI+tdu4RhEpnqw4JfGHePYdAmO9zwrIFh5Ym1R4XJWt4ls/3br9u/6kS5dN8s5RqZSRUz/nmsaauwUzAA==" crossorigin="anonymous"></script> <script type="text/javascript" src="js/privatebin.js?<?php echo rawurlencode($VERSION); ?>" integrity="sha512-Z3SG68lkzr8/Hg8goFersCg5T8qrI2dUKDCRnlA6uZanWLiKRCBBX8gNHgjSdPp/+XC3fFFTGL3KCZFgCXXdtQ==" crossorigin="anonymous"></script>
<!--[if lt IE 10]> <!--[if lt IE 10]>
<style type="text/css">body {padding-left:60px;padding-right:60px;} #ienotice {display:block;} #oldienotice {display:block;}</style> <style type="text/css">body {padding-left:60px;padding-right:60px;} #ienotice {display:block;} #oldienotice {display:block;}</style>
<![endif]--> <![endif]-->