2017-12-15 06:20:51 +00:00
|
|
|
'use strict';
|
|
|
|
var common = require('../common');
|
|
|
|
|
|
|
|
describe('Alert', function () {
|
|
|
|
describe('showStatus', function () {
|
|
|
|
jsc.property(
|
2019-08-28 17:23:58 +00:00
|
|
|
'shows a status message (basic)',
|
|
|
|
jsc.array(common.jscAlnumString()),
|
|
|
|
jsc.array(common.jscAlnumString()),
|
|
|
|
function (icon, message) {
|
|
|
|
icon = icon.join('');
|
|
|
|
message = message.join('');
|
|
|
|
const expected = '<div id="status">' + message + '</div>';
|
|
|
|
$('body').html(
|
|
|
|
'<div id="status"></div>'
|
|
|
|
);
|
|
|
|
$.PrivateBin.Alert.init();
|
|
|
|
$.PrivateBin.Alert.showStatus(message, icon);
|
|
|
|
const result = $('body').html();
|
|
|
|
return expected === result;
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
jsc.property(
|
|
|
|
'shows a status message (bootstrap)',
|
2017-12-15 06:20:51 +00:00
|
|
|
jsc.array(common.jscAlnumString()),
|
2019-08-28 18:29:23 +00:00
|
|
|
function (message) {
|
|
|
|
message = message.join('');
|
|
|
|
const expected = '<div id="status" role="alert" ' +
|
|
|
|
'class="statusmessage alert alert-info"><span ' +
|
|
|
|
'class="glyphicon glyphicon-info-sign" ' +
|
|
|
|
'aria-hidden="true"></span> <span>' + message + '</span></div>';
|
|
|
|
$('body').html(
|
|
|
|
'<div id="status" role="alert" class="statusmessage ' +
|
|
|
|
'alert alert-info hidden"><span class="glyphicon ' +
|
|
|
|
'glyphicon-info-sign" aria-hidden="true"></span> </div>'
|
|
|
|
);
|
|
|
|
$.PrivateBin.Alert.init();
|
|
|
|
$.PrivateBin.Alert.showStatus(message);
|
|
|
|
const result = $('body').html();
|
|
|
|
return expected === result;
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
jsc.property(
|
|
|
|
'shows a status message (bootstrap, custom icon)',
|
|
|
|
jsc.array(common.jscAlnumString()),
|
2017-12-15 06:20:51 +00:00
|
|
|
jsc.array(common.jscAlnumString()),
|
|
|
|
function (icon, message) {
|
|
|
|
icon = icon.join('');
|
|
|
|
message = message.join('');
|
2019-08-27 21:16:06 +00:00
|
|
|
const expected = '<div id="status" role="alert" ' +
|
2017-12-15 06:20:51 +00:00
|
|
|
'class="statusmessage alert alert-info"><span ' +
|
|
|
|
'class="glyphicon glyphicon-' + icon +
|
2019-08-28 18:29:23 +00:00
|
|
|
'" aria-hidden="true"></span> <span>' + message + '</span></div>';
|
2017-12-15 06:20:51 +00:00
|
|
|
$('body').html(
|
|
|
|
'<div id="status" role="alert" class="statusmessage ' +
|
|
|
|
'alert alert-info hidden"><span class="glyphicon ' +
|
|
|
|
'glyphicon-info-sign" aria-hidden="true"></span> </div>'
|
|
|
|
);
|
|
|
|
$.PrivateBin.Alert.init();
|
|
|
|
$.PrivateBin.Alert.showStatus(message, icon);
|
2019-08-27 21:16:06 +00:00
|
|
|
const result = $('body').html();
|
2017-12-15 06:20:51 +00:00
|
|
|
return expected === result;
|
|
|
|
}
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2019-08-28 18:29:23 +00:00
|
|
|
describe('showWarning', function () {
|
2017-12-15 06:20:51 +00:00
|
|
|
before(function () {
|
|
|
|
cleanup();
|
|
|
|
});
|
|
|
|
|
|
|
|
jsc.property(
|
2019-08-28 18:29:23 +00:00
|
|
|
'shows a warning message (basic)',
|
2019-08-28 17:23:58 +00:00
|
|
|
jsc.array(common.jscAlnumString()),
|
|
|
|
jsc.array(common.jscAlnumString()),
|
|
|
|
function (icon, message) {
|
|
|
|
icon = icon.join('');
|
|
|
|
message = message.join('');
|
|
|
|
const expected = '<div id="errormessage">' + message + '</div>';
|
|
|
|
$('body').html(
|
|
|
|
'<div id="errormessage"></div>'
|
|
|
|
);
|
|
|
|
$.PrivateBin.Alert.init();
|
2019-08-28 18:29:23 +00:00
|
|
|
$.PrivateBin.Alert.showWarning(message, icon);
|
2019-08-28 17:23:58 +00:00
|
|
|
const result = $('body').html();
|
|
|
|
return expected === result;
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
jsc.property(
|
2019-08-28 18:29:23 +00:00
|
|
|
'shows a warning message (bootstrap)',
|
|
|
|
jsc.array(common.jscAlnumString()),
|
|
|
|
jsc.array(common.jscAlnumString()),
|
|
|
|
function (message) {
|
|
|
|
message = message.join('');
|
|
|
|
const expected = '<div id="errormessage" role="alert" ' +
|
|
|
|
'class="statusmessage alert alert-danger"><span ' +
|
|
|
|
'class="glyphicon glyphicon-warning-sign" ' +
|
|
|
|
'aria-hidden="true"></span> <span>' + message + '</span></div>';
|
|
|
|
$('body').html(
|
|
|
|
'<div id="errormessage" role="alert" class="statusmessage ' +
|
|
|
|
'alert alert-danger hidden"><span class="glyphicon ' +
|
|
|
|
'glyphicon-alert" aria-hidden="true"></span> </div>'
|
|
|
|
);
|
|
|
|
$.PrivateBin.Alert.init();
|
|
|
|
$.PrivateBin.Alert.showWarning(message);
|
|
|
|
const result = $('body').html();
|
|
|
|
return expected === result;
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
jsc.property(
|
|
|
|
'shows a warning message (bootstrap, custom icon)',
|
2017-12-15 06:20:51 +00:00
|
|
|
jsc.array(common.jscAlnumString()),
|
|
|
|
jsc.array(common.jscAlnumString()),
|
|
|
|
function (icon, message) {
|
|
|
|
icon = icon.join('');
|
|
|
|
message = message.join('');
|
2019-08-27 21:16:06 +00:00
|
|
|
const expected = '<div id="errormessage" role="alert" ' +
|
2017-12-15 06:20:51 +00:00
|
|
|
'class="statusmessage alert alert-danger"><span ' +
|
|
|
|
'class="glyphicon glyphicon-' + icon +
|
2019-08-28 18:29:23 +00:00
|
|
|
'" aria-hidden="true"></span> <span>' + message + '</span></div>';
|
2017-12-15 06:20:51 +00:00
|
|
|
$('body').html(
|
|
|
|
'<div id="errormessage" role="alert" class="statusmessage ' +
|
|
|
|
'alert alert-danger hidden"><span class="glyphicon ' +
|
|
|
|
'glyphicon-alert" aria-hidden="true"></span> </div>'
|
|
|
|
);
|
|
|
|
$.PrivateBin.Alert.init();
|
2019-08-28 18:29:23 +00:00
|
|
|
$.PrivateBin.Alert.showWarning(message, icon);
|
2019-08-27 21:16:06 +00:00
|
|
|
const result = $('body').html();
|
2017-12-15 06:20:51 +00:00
|
|
|
return expected === result;
|
|
|
|
}
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2019-08-28 18:29:23 +00:00
|
|
|
describe('showError', function () {
|
2019-08-28 17:23:58 +00:00
|
|
|
before(function () {
|
|
|
|
cleanup();
|
|
|
|
});
|
|
|
|
|
|
|
|
jsc.property(
|
2019-08-28 18:29:23 +00:00
|
|
|
'shows an error message (basic)',
|
2019-08-28 17:23:58 +00:00
|
|
|
jsc.array(common.jscAlnumString()),
|
|
|
|
jsc.array(common.jscAlnumString()),
|
|
|
|
function (icon, message) {
|
|
|
|
icon = icon.join('');
|
|
|
|
message = message.join('');
|
|
|
|
const expected = '<div id="errormessage">' + message + '</div>';
|
|
|
|
$('body').html(
|
|
|
|
'<div id="errormessage"></div>'
|
|
|
|
);
|
|
|
|
$.PrivateBin.Alert.init();
|
2019-08-28 18:29:23 +00:00
|
|
|
$.PrivateBin.Alert.showError(message, icon);
|
2019-08-28 17:23:58 +00:00
|
|
|
const result = $('body').html();
|
|
|
|
return expected === result;
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
jsc.property(
|
2019-08-28 18:29:23 +00:00
|
|
|
'shows an error message (bootstrap)',
|
|
|
|
jsc.array(common.jscAlnumString()),
|
|
|
|
jsc.array(common.jscAlnumString()),
|
|
|
|
function (icon, message) {
|
|
|
|
message = message.join('');
|
|
|
|
const expected = '<div id="errormessage" role="alert" ' +
|
|
|
|
'class="statusmessage alert alert-danger"><span ' +
|
|
|
|
'class="glyphicon glyphicon-alert" ' +
|
|
|
|
'aria-hidden="true"></span> <span>' + message + '</span></div>';
|
|
|
|
$('body').html(
|
|
|
|
'<div id="errormessage" role="alert" class="statusmessage ' +
|
|
|
|
'alert alert-danger hidden"><span class="glyphicon ' +
|
|
|
|
'glyphicon-alert" aria-hidden="true"></span> </div>'
|
|
|
|
);
|
|
|
|
$.PrivateBin.Alert.init();
|
|
|
|
$.PrivateBin.Alert.showError(message);
|
|
|
|
const result = $('body').html();
|
|
|
|
return expected === result;
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
jsc.property(
|
|
|
|
'shows an error message (bootstrap, custom icon)',
|
2019-08-28 17:23:58 +00:00
|
|
|
jsc.array(common.jscAlnumString()),
|
|
|
|
jsc.array(common.jscAlnumString()),
|
|
|
|
function (icon, message) {
|
|
|
|
icon = icon.join('');
|
|
|
|
message = message.join('');
|
|
|
|
const expected = '<div id="errormessage" role="alert" ' +
|
|
|
|
'class="statusmessage alert alert-danger"><span ' +
|
|
|
|
'class="glyphicon glyphicon-' + icon +
|
2019-08-28 18:29:23 +00:00
|
|
|
'" aria-hidden="true"></span> <span>' + message + '</span></div>';
|
2019-08-28 17:23:58 +00:00
|
|
|
$('body').html(
|
|
|
|
'<div id="errormessage" role="alert" class="statusmessage ' +
|
|
|
|
'alert alert-danger hidden"><span class="glyphicon ' +
|
|
|
|
'glyphicon-alert" aria-hidden="true"></span> </div>'
|
|
|
|
);
|
|
|
|
$.PrivateBin.Alert.init();
|
2019-08-28 18:29:23 +00:00
|
|
|
$.PrivateBin.Alert.showError(message, icon);
|
2019-08-28 17:23:58 +00:00
|
|
|
const result = $('body').html();
|
|
|
|
return expected === result;
|
|
|
|
}
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2017-12-15 06:20:51 +00:00
|
|
|
describe('showRemaining', function () {
|
|
|
|
before(function () {
|
|
|
|
cleanup();
|
|
|
|
});
|
|
|
|
|
|
|
|
jsc.property(
|
2019-08-28 17:23:58 +00:00
|
|
|
'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 = '<div id="remainingtime" class="">' + string + message + number + '</div>';
|
|
|
|
$('body').html(
|
|
|
|
'<div id="remainingtime" class="hidden"></div>'
|
|
|
|
);
|
|
|
|
$.PrivateBin.Alert.init();
|
|
|
|
$.PrivateBin.Alert.showRemaining(['%s' + message + '%d', string, number]);
|
|
|
|
const result = $('body').html();
|
|
|
|
return expected === result;
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
jsc.property(
|
|
|
|
'shows remaining time (bootstrap)',
|
2017-12-15 06:20:51 +00:00
|
|
|
jsc.array(common.jscAlnumString()),
|
|
|
|
jsc.array(common.jscAlnumString()),
|
|
|
|
'integer',
|
|
|
|
function (message, string, number) {
|
|
|
|
message = message.join('');
|
|
|
|
string = string.join('');
|
2019-08-27 21:16:06 +00:00
|
|
|
const expected = '<div id="remainingtime" role="alert" ' +
|
2017-12-15 06:20:51 +00:00
|
|
|
'class="alert alert-info"><span ' +
|
|
|
|
'class="glyphicon glyphicon-fire" aria-hidden="true">' +
|
2019-08-28 18:29:23 +00:00
|
|
|
'</span> <span>' + string + message + number + '</span></div>';
|
2017-12-15 06:20:51 +00:00
|
|
|
$('body').html(
|
|
|
|
'<div id="remainingtime" role="alert" class="hidden ' +
|
|
|
|
'alert alert-info"><span class="glyphicon ' +
|
|
|
|
'glyphicon-fire" aria-hidden="true"></span> </div>'
|
|
|
|
);
|
|
|
|
$.PrivateBin.Alert.init();
|
|
|
|
$.PrivateBin.Alert.showRemaining(['%s' + message + '%d', string, number]);
|
2019-08-27 21:16:06 +00:00
|
|
|
const result = $('body').html();
|
2017-12-15 06:20:51 +00:00
|
|
|
return expected === result;
|
|
|
|
}
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('showLoading', function () {
|
|
|
|
before(function () {
|
|
|
|
cleanup();
|
|
|
|
});
|
|
|
|
|
|
|
|
jsc.property(
|
2019-08-28 17:23:58 +00:00
|
|
|
'shows a loading message (basic)',
|
|
|
|
jsc.array(common.jscAlnumString()),
|
|
|
|
jsc.array(common.jscAlnumString()),
|
|
|
|
function (message, icon) {
|
|
|
|
message = message.join('');
|
|
|
|
icon = icon.join('');
|
|
|
|
const defaultMessage = 'Loading…';
|
|
|
|
if (message.length === 0) {
|
|
|
|
message = defaultMessage;
|
|
|
|
}
|
|
|
|
const expected = '<div id="loadingindicator" class="">' + message + '</div>';
|
|
|
|
$('body').html(
|
|
|
|
'<div id="loadingindicator" class="hidden">' + defaultMessage + '</div>'
|
|
|
|
);
|
|
|
|
$.PrivateBin.Alert.init();
|
|
|
|
$.PrivateBin.Alert.showLoading(message, icon);
|
|
|
|
const result = $('body').html();
|
|
|
|
return expected === result;
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
jsc.property(
|
|
|
|
'shows a loading message (bootstrap)',
|
2017-12-15 06:20:51 +00:00
|
|
|
jsc.array(common.jscAlnumString()),
|
|
|
|
jsc.array(common.jscAlnumString()),
|
2018-01-06 12:32:07 +00:00
|
|
|
function (message, icon) {
|
2017-12-15 06:20:51 +00:00
|
|
|
message = message.join('');
|
2018-01-06 12:32:07 +00:00
|
|
|
icon = icon.join('');
|
2019-08-27 21:16:06 +00:00
|
|
|
const defaultMessage = 'Loading…';
|
2018-01-06 06:17:33 +00:00
|
|
|
if (message.length === 0) {
|
2018-01-06 08:26:10 +00:00
|
|
|
message = defaultMessage;
|
2017-12-15 06:20:51 +00:00
|
|
|
}
|
2019-08-28 17:23:58 +00:00
|
|
|
const expected = '<ul class="nav navbar-nav"><li ' +
|
2017-12-15 06:20:51 +00:00
|
|
|
'id="loadingindicator" class="navbar-text"><span ' +
|
|
|
|
'class="glyphicon glyphicon-' + icon +
|
2019-08-28 18:29:23 +00:00
|
|
|
'" aria-hidden="true"></span> <span>' + message + '</span></li></ul>';
|
2017-12-15 06:20:51 +00:00
|
|
|
$('body').html(
|
|
|
|
'<ul class="nav navbar-nav"><li id="loadingindicator" ' +
|
|
|
|
'class="navbar-text hidden"><span class="glyphicon ' +
|
|
|
|
'glyphicon-time" aria-hidden="true"></span> ' +
|
2018-01-06 08:26:10 +00:00
|
|
|
defaultMessage + '</li></ul>'
|
2017-12-15 06:20:51 +00:00
|
|
|
);
|
|
|
|
$.PrivateBin.Alert.init();
|
2018-01-06 12:32:07 +00:00
|
|
|
$.PrivateBin.Alert.showLoading(message, icon);
|
2019-08-27 21:16:06 +00:00
|
|
|
const result = $('body').html();
|
2017-12-15 06:20:51 +00:00
|
|
|
return expected === result;
|
|
|
|
}
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('hideLoading', function () {
|
|
|
|
before(function () {
|
|
|
|
cleanup();
|
|
|
|
});
|
|
|
|
|
|
|
|
it(
|
|
|
|
'hides the loading message',
|
|
|
|
function() {
|
|
|
|
$('body').html(
|
|
|
|
'<ul class="nav navbar-nav"><li id="loadingindicator" ' +
|
|
|
|
'class="navbar-text"><span class="glyphicon ' +
|
|
|
|
'glyphicon-time" aria-hidden="true"></span> ' +
|
|
|
|
'Loading…</li></ul>'
|
|
|
|
);
|
|
|
|
$('body').addClass('loading');
|
|
|
|
$.PrivateBin.Alert.init();
|
|
|
|
$.PrivateBin.Alert.hideLoading();
|
2018-03-01 05:43:30 +00:00
|
|
|
assert.ok(
|
|
|
|
!$('body').hasClass('loading') &&
|
|
|
|
$('#loadingindicator').hasClass('hidden')
|
|
|
|
);
|
2017-12-15 06:20:51 +00:00
|
|
|
}
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('hideMessages', function () {
|
|
|
|
before(function () {
|
|
|
|
cleanup();
|
|
|
|
});
|
|
|
|
|
|
|
|
it(
|
|
|
|
'hides all messages',
|
|
|
|
function() {
|
|
|
|
$('body').html(
|
|
|
|
'<div id="status" role="alert" class="statusmessage ' +
|
|
|
|
'alert alert-info"><span class="glyphicon ' +
|
|
|
|
'glyphicon-info-sign" aria-hidden="true"></span> </div>' +
|
|
|
|
'<div id="errormessage" role="alert" class="statusmessage ' +
|
|
|
|
'alert alert-danger"><span class="glyphicon ' +
|
|
|
|
'glyphicon-alert" aria-hidden="true"></span> </div>'
|
|
|
|
);
|
|
|
|
$.PrivateBin.Alert.init();
|
|
|
|
$.PrivateBin.Alert.hideMessages();
|
2018-03-01 05:43:30 +00:00
|
|
|
assert.ok(
|
|
|
|
$('#status').hasClass('hidden') &&
|
|
|
|
$('#errormessage').hasClass('hidden')
|
|
|
|
);
|
2017-12-15 06:20:51 +00:00
|
|
|
}
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('setCustomHandler', function () {
|
|
|
|
before(function () {
|
|
|
|
cleanup();
|
|
|
|
});
|
|
|
|
|
|
|
|
jsc.property(
|
|
|
|
'calls a given handler function',
|
|
|
|
'nat 3',
|
|
|
|
jsc.array(common.jscAlnumString()),
|
|
|
|
function (trigger, message) {
|
|
|
|
message = message.join('');
|
2019-08-27 21:16:06 +00:00
|
|
|
let handlerCalled = false,
|
2018-01-06 08:26:10 +00:00
|
|
|
defaultMessage = 'Loading…',
|
2017-12-15 06:20:51 +00:00
|
|
|
functions = [
|
|
|
|
$.PrivateBin.Alert.showStatus,
|
|
|
|
$.PrivateBin.Alert.showError,
|
|
|
|
$.PrivateBin.Alert.showRemaining,
|
|
|
|
$.PrivateBin.Alert.showLoading
|
|
|
|
];
|
2018-01-06 06:17:33 +00:00
|
|
|
if (message.length === 0) {
|
2018-01-06 08:26:10 +00:00
|
|
|
message = defaultMessage;
|
2017-12-15 06:20:51 +00:00
|
|
|
}
|
|
|
|
$('body').html(
|
|
|
|
'<ul class="nav navbar-nav"><li id="loadingindicator" ' +
|
|
|
|
'class="navbar-text hidden"><span class="glyphicon ' +
|
|
|
|
'glyphicon-time" aria-hidden="true"></span> ' +
|
2018-01-06 08:26:10 +00:00
|
|
|
defaultMessage + '</li></ul>' +
|
2017-12-15 06:20:51 +00:00
|
|
|
'<div id="remainingtime" role="alert" class="hidden ' +
|
|
|
|
'alert alert-info"><span class="glyphicon ' +
|
|
|
|
'glyphicon-fire" aria-hidden="true"></span> </div>' +
|
|
|
|
'<div id="status" role="alert" class="statusmessage ' +
|
|
|
|
'alert alert-info"><span class="glyphicon ' +
|
|
|
|
'glyphicon-info-sign" aria-hidden="true"></span> </div>' +
|
|
|
|
'<div id="errormessage" role="alert" class="statusmessage ' +
|
|
|
|
'alert alert-danger"><span class="glyphicon ' +
|
|
|
|
'glyphicon-alert" aria-hidden="true"></span> </div>'
|
|
|
|
);
|
|
|
|
$.PrivateBin.Alert.init();
|
|
|
|
$.PrivateBin.Alert.setCustomHandler(function(id, $element) {
|
|
|
|
handlerCalled = true;
|
|
|
|
return jsc.random(0, 1) ? true : $element;
|
|
|
|
});
|
|
|
|
functions[trigger](message);
|
2019-06-23 07:39:21 +00:00
|
|
|
$.PrivateBin.Alert.setCustomHandler(null);
|
2017-12-15 06:20:51 +00:00
|
|
|
return handlerCalled;
|
|
|
|
}
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|