From 01a6c0142a1a4b4f099a13a585b0bef576fe09b7 Mon Sep 17 00:00:00 2001 From: El RIDO Date: Sat, 4 Nov 2017 08:59:31 +0100 Subject: [PATCH] adding test for alert handler --- js/test.js | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/js/test.js b/js/test.js index f5100af0..78eeb5e9 100644 --- a/js/test.js +++ b/js/test.js @@ -1113,5 +1113,53 @@ describe('Alert', function () { } ); }); + + describe('setCustomHandler', function () { + before(function () { + cleanup(); + }); + + jsc.property( + 'calls a given handler function', + 'nat 3', + jsc.array(jsc.elements(alnumString)), + function (trigger, message) { + message = message.join(''); + var handlerCalled = false, + default_message = 'Loading…', + functions = [ + $.PrivateBin.Alert.showStatus, + $.PrivateBin.Alert.showError, + $.PrivateBin.Alert.showRemaining, + $.PrivateBin.Alert.showLoading + ]; + if (message.length == 0) { + message = default_message; + } + $('body').html( + '' + + '' + + '' + + '' + ); + $.PrivateBin.Alert.init(); + $.PrivateBin.Alert.setCustomHandler(function(id, $element) { + handlerCalled = true; + return true; + }); + functions[trigger](message); + return handlerCalled; + } + ); + }); });