From ad570c391a506b460d5c441696ae04ba11721656 Mon Sep 17 00:00:00 2001 From: El RIDO Date: Wed, 28 Aug 2019 19:23:58 +0200 Subject: [PATCH] extend Alert class unit testing --- js/test/Alert.js | 134 +++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 129 insertions(+), 5 deletions(-) diff --git a/js/test/Alert.js b/js/test/Alert.js index 9d009556..8e3787d3 100644 --- a/js/test/Alert.js +++ b/js/test/Alert.js @@ -4,7 +4,25 @@ var common = require('../common'); describe('Alert', function () { describe('showStatus', function () { jsc.property( - 'shows a status message', + 'shows a status message (basic)', + jsc.array(common.jscAlnumString()), + jsc.array(common.jscAlnumString()), + function (icon, message) { + icon = icon.join(''); + message = message.join(''); + const expected = '
' + message + '
'; + $('body').html( + '
' + ); + $.PrivateBin.Alert.init(); + $.PrivateBin.Alert.showStatus(message, icon); + const result = $('body').html(); + return expected === result; + } + ); + + jsc.property( + 'shows a status message (bootstrap)', jsc.array(common.jscAlnumString()), jsc.array(common.jscAlnumString()), function (icon, message) { @@ -33,7 +51,25 @@ describe('Alert', function () { }); jsc.property( - 'shows an error message', + 'shows an error message (basic)', + jsc.array(common.jscAlnumString()), + jsc.array(common.jscAlnumString()), + function (icon, message) { + icon = icon.join(''); + message = message.join(''); + const expected = '
' + message + '
'; + $('body').html( + '
' + ); + $.PrivateBin.Alert.init(); + $.PrivateBin.Alert.showError(message, icon); + const result = $('body').html(); + return expected === result; + } + ); + + jsc.property( + 'shows an error message (bootstrap)', jsc.array(common.jscAlnumString()), jsc.array(common.jscAlnumString()), function (icon, message) { @@ -56,13 +92,79 @@ describe('Alert', function () { ); }); + describe('showWarning', function () { + before(function () { + cleanup(); + }); + + jsc.property( + 'shows a warning message (basic)', + jsc.array(common.jscAlnumString()), + jsc.array(common.jscAlnumString()), + function (icon, message) { + icon = icon.join(''); + message = message.join(''); + const expected = '
' + message + '
'; + $('body').html( + '
' + ); + $.PrivateBin.Alert.init(); + $.PrivateBin.Alert.showWarning(message, icon); + const result = $('body').html(); + return expected === result; + } + ); + + jsc.property( + 'shows a warning message (bootstrap)', + jsc.array(common.jscAlnumString()), + jsc.array(common.jscAlnumString()), + function (icon, message) { + icon = icon.join(''); + message = message.join(''); + const expected = ''; + $('body').html( + '' + ); + $.PrivateBin.Alert.init(); + $.PrivateBin.Alert.showWarning(message, icon); + const result = $('body').html(); + return expected === result; + } + ); + }); + describe('showRemaining', function () { before(function () { cleanup(); }); jsc.property( - 'shows remaining time', + 'shows remaining time (basic)', + jsc.array(common.jscAlnumString()), + jsc.array(common.jscAlnumString()), + 'integer', + function (message, string, number) { + message = message.join(''); + string = string.join(''); + const expected = '
' + string + message + number + '
'; + $('body').html( + '' + ); + $.PrivateBin.Alert.init(); + $.PrivateBin.Alert.showRemaining(['%s' + message + '%d', string, number]); + const result = $('body').html(); + return expected === result; + } + ); + + jsc.property( + 'shows remaining time (bootstrap)', jsc.array(common.jscAlnumString()), jsc.array(common.jscAlnumString()), 'integer', @@ -92,7 +194,7 @@ describe('Alert', function () { }); jsc.property( - 'shows a loading message', + 'shows a loading message (basic)', jsc.array(common.jscAlnumString()), jsc.array(common.jscAlnumString()), function (message, icon) { @@ -102,7 +204,29 @@ describe('Alert', function () { if (message.length === 0) { message = defaultMessage; } - var expected = '