From 9c6aec86c42bdd248c21088014acd72e5d665e1a Mon Sep 17 00:00:00 2001 From: El RIDO Date: Mon, 23 Oct 2017 21:33:07 +0200 Subject: [PATCH] making Alert class resetable and adding first tests for it --- js/privatebin.js | 14 ++++---- js/test.js | 90 +++++++++++++++++++++++++++++++++++++++++++++++ tpl/bootstrap.php | 2 +- tpl/page.php | 2 +- 4 files changed, 100 insertions(+), 8 deletions(-) diff --git a/js/privatebin.js b/js/privatebin.js index 74db28c..f818b98 100644 --- a/js/privatebin.js +++ b/js/privatebin.js @@ -1004,12 +1004,7 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) { $statusMessage, $remainingTime; - var currentIcon = [ - 'glyphicon-time', // loading icon - 'glyphicon-info-sign', // status icon - '', // resevered for warning, not used yet - 'glyphicon-alert' // error icon - ]; + var currentIcon; var alertType = [ 'loading', // not in bootstrap, but using a good value here @@ -1253,6 +1248,13 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) { $loadingIndicator = $('#loadingindicator'); $statusMessage = $('#status'); $remainingTime = $('#remainingtime'); + + currentIcon = [ + 'glyphicon-time', // loading icon + 'glyphicon-info-sign', // status icon + '', // reserved for warning, not used yet + 'glyphicon-alert' // error icon + ]; } return me; diff --git a/js/test.js b/js/test.js index 6a67972..63b6ba4 100644 --- a/js/test.js +++ b/js/test.js @@ -943,3 +943,93 @@ describe('UiHelper', function () { }); }); +describe('Alert', function () { + describe('showStatus', function () { + before(function () { + cleanup(); + }); + + jsc.property( + 'shows a status message', + jsc.array(jsc.elements(alnumString)), + jsc.array(jsc.elements(alnumString)), + function (icon, message) { + icon = icon.join(''); + message = message.join(''); + var expected = ''; + $('body').html( + '' + ); + $.PrivateBin.Alert.init(); + $.PrivateBin.Alert.showStatus(message, icon); + var result = $('body').html(); + return expected === result; + } + ); + }); + + describe('showError', function () { + before(function () { + cleanup(); + }); + + jsc.property( + 'shows an error message', + jsc.array(jsc.elements(alnumString)), + jsc.array(jsc.elements(alnumString)), + function (icon, message) { + icon = icon.join(''); + message = message.join(''); + var expected = ''; + $('body').html( + '' + ); + $.PrivateBin.Alert.init(); + $.PrivateBin.Alert.showError(message, icon); + var result = $('body').html(); + return expected === result; + } + ); + }); + + describe('showRemaining', function () { + before(function () { + cleanup(); + }); + + jsc.property( + 'shows remaining time', + jsc.array(jsc.elements(alnumString)), + jsc.array(jsc.elements(alnumString)), + 'integer', + function (message, string, number) { + message = message.join(''); + string = string.join(''); + var expected = ''; + $('body').html( + '' + ); + $.PrivateBin.Alert.init(); + $.PrivateBin.Alert.showRemaining(['%s' + message + '%d', string, number]); + var result = $('body').html(); + return expected === result; + } + ); + }); +}); + diff --git a/tpl/bootstrap.php b/tpl/bootstrap.php index 609ccb7..036452e 100644 --- a/tpl/bootstrap.php +++ b/tpl/bootstrap.php @@ -69,7 +69,7 @@ if ($MARKDOWN): - + diff --git a/tpl/page.php b/tpl/page.php index 8b8fcad..1cae6b3 100644 --- a/tpl/page.php +++ b/tpl/page.php @@ -47,7 +47,7 @@ if ($MARKDOWN): - +