From ce6764e97d2fdd16b98b151b258345a09dc42337 Mon Sep 17 00:00:00 2001 From: El RIDO Date: Thu, 1 Mar 2018 06:43:30 +0100 Subject: [PATCH] introduce built in asserts, working on TopNav, correcting some docs --- js/common.js | 1 + js/privatebin.js | 5 +- js/test/Alert.js | 12 ++-- js/test/CryptTool.js | 14 ++-- js/test/PasteStatus.js | 6 +- js/test/TopNav.js | 158 ++++++++++++++++++++++++++++++++++++++++- tpl/bootstrap.php | 2 +- tpl/page.php | 2 +- 8 files changed, 183 insertions(+), 17 deletions(-) diff --git a/js/common.js b/js/common.js index c60a706..3ab4999 100644 --- a/js/common.js +++ b/js/common.js @@ -1,6 +1,7 @@ 'use strict'; // testing prerequisites +global.assert = require('assert'); global.jsc = require('jsverify'); global.jsdom = require('jsdom-global'); global.cleanup = global.jsdom(); diff --git a/js/privatebin.js b/js/privatebin.js index 240726f..395ac0e 100644 --- a/js/privatebin.js +++ b/js/privatebin.js @@ -1290,7 +1290,7 @@ jQuery.PrivateBin = (function($, sjcl, Base64, RawDeflate) { /** * hides the remaining time and successful upload notification * - * @name PasteStatus.hideRemainingTime + * @name PasteStatus.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 pasteExpiration = Model.getExpirationDefault() || pasteExpiration; + + createButtonsDisplayed = false; + viewButtonsDisplayed = false; }; return me; diff --git a/js/test/Alert.js b/js/test/Alert.js index 2f0a2df..617c488 100644 --- a/js/test/Alert.js +++ b/js/test/Alert.js @@ -141,8 +141,10 @@ describe('Alert', function () { $('body').addClass('loading'); $.PrivateBin.Alert.init(); $.PrivateBin.Alert.hideLoading(); - return !$('body').hasClass('loading') && - $('#loadingindicator').hasClass('hidden'); + assert.ok( + !$('body').hasClass('loading') && + $('#loadingindicator').hasClass('hidden') + ); } ); }); @@ -165,8 +167,10 @@ describe('Alert', function () { ); $.PrivateBin.Alert.init(); $.PrivateBin.Alert.hideMessages(); - return $('#statusmessage').hasClass('hidden') && - $('#errormessage').hasClass('hidden'); + assert.ok( + $('#status').hasClass('hidden') && + $('#errormessage').hasClass('hidden') + ); } ); }); diff --git a/js/test/CryptTool.js b/js/test/CryptTool.js index 398ff75..3c89fff 100644 --- a/js/test/CryptTool.js +++ b/js/test/CryptTool.js @@ -87,9 +87,10 @@ describe('CryptTool', function () { 'MZtmnYpGAtAPg7AUG"}' ); - if (!paste1.includes('securely packed in iron') || !paste2.includes('Sol is right')) { - throw Error('v1 (SJCL based) pastes could not be deciphered'); - } + assert.ok( + paste1.includes('securely packed in iron') && + paste2.includes('Sol is right') + ); } ); @@ -152,9 +153,10 @@ describe('CryptTool', function () { jsdom(); delete require.cache[require.resolve('../privatebin')]; require('../privatebin'); - if (!paste1.includes('securely packed in iron') || !paste2.includes('Sol is right')) { - throw Error('v1 (SJCL based) pastes could not be deciphered'); - } + assert.ok( + paste1.includes('securely packed in iron') && + paste2.includes('Sol is right') + ); } ); }); diff --git a/js/test/PasteStatus.js b/js/test/PasteStatus.js index 1c31813..6b0805d 100644 --- a/js/test/PasteStatus.js +++ b/js/test/PasteStatus.js @@ -96,8 +96,10 @@ describe('PasteStatus', function () { ); $.PrivateBin.PasteStatus.init(); $.PrivateBin.PasteStatus.hideMessages(); - return $('#remainingtime').hasClass('hidden') && - $('#pastesuccess').hasClass('hidden'); + assert.ok( + $('#remainingtime').hasClass('hidden') && + $('#pastesuccess').hasClass('hidden') + ); } ); }); diff --git a/js/test/TopNav.js b/js/test/TopNav.js index 9deacf5..ba7ffad 100644 --- a/js/test/TopNav.js +++ b/js/test/TopNav.js @@ -52,7 +52,7 @@ describe('TopNav', function () { $('#qrcodelink').hasClass('hidden') ); cleanup(); - return results.every(element => element); + assert.ok(results.every(element => element)); } ); }); @@ -113,7 +113,161 @@ describe('TopNav', function () { $('#attach').hasClass('hidden') ); 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( + '' + ); + $.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( + '' + ); + $.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( + '' + ); + $.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( + '' + ); + $.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( + '' + ); + $.PrivateBin.TopNav.init(); + results.push( + $('#customattachment').hasClass('hidden') + ); + $.PrivateBin.TopNav.showCustomAttachment(); + results.push( + !$('#customattachment').hasClass('hidden') + ); + cleanup(); + assert.ok(results.every(element => element)); } ); }); diff --git a/tpl/bootstrap.php b/tpl/bootstrap.php index c39d516..ee078fa 100644 --- a/tpl/bootstrap.php +++ b/tpl/bootstrap.php @@ -75,7 +75,7 @@ if ($MARKDOWN): - + diff --git a/tpl/page.php b/tpl/page.php index a65b361..ac94a65 100644 --- a/tpl/page.php +++ b/tpl/page.php @@ -54,7 +54,7 @@ if ($QRCODE): - +