2016-12-07 18:38:59 +01:00
|
|
|
set_global("page_params", {
|
|
|
|
realm_uri: "https://chat.example.com",
|
2018-01-07 19:24:14 +01:00
|
|
|
realm_embedded_bots: [{name: "converter", config: {}},
|
|
|
|
{name:"giphy", config: {key: "12345678"}},
|
|
|
|
{name:"foobot", config: {bar: "baz", qux: "quux"}},
|
|
|
|
],
|
2016-12-07 18:38:59 +01:00
|
|
|
});
|
|
|
|
|
2017-06-20 00:32:20 +02:00
|
|
|
set_global("avatar", {});
|
|
|
|
|
|
|
|
set_global('$', global.make_zjquery());
|
2017-07-08 15:16:19 +02:00
|
|
|
set_global('document', 'document-stub');
|
2017-06-20 00:32:20 +02:00
|
|
|
|
2017-11-08 18:50:24 +01:00
|
|
|
zrequire('bot_data');
|
|
|
|
zrequire('settings_bots');
|
2018-01-07 19:24:14 +01:00
|
|
|
zrequire('Handlebars', 'handlebars');
|
|
|
|
zrequire('templates');
|
2016-12-07 18:38:59 +01:00
|
|
|
|
|
|
|
(function test_generate_zuliprc_uri() {
|
|
|
|
var bot = {
|
|
|
|
email: "error-bot@zulip.org",
|
|
|
|
api_key: "QadL788EkiottHmukyhHgePUFHREiu8b",
|
|
|
|
};
|
2017-04-06 22:47:27 +02:00
|
|
|
var uri = settings_bots.generate_zuliprc_uri(bot.email, bot.api_key);
|
2016-12-07 18:38:59 +01:00
|
|
|
var expected = "data:application/octet-stream;charset=utf-8," + encodeURIComponent(
|
|
|
|
"[api]\nemail=error-bot@zulip.org\n" +
|
|
|
|
"key=QadL788EkiottHmukyhHgePUFHREiu8b\n" +
|
|
|
|
"site=https://chat.example.com\n"
|
|
|
|
);
|
|
|
|
|
|
|
|
assert.equal(uri, expected);
|
|
|
|
}());
|
|
|
|
|
|
|
|
(function test_generate_zuliprc_content() {
|
|
|
|
var user = {
|
|
|
|
email: "admin12@chatting.net",
|
2017-01-12 00:17:43 +01:00
|
|
|
api_key: "nSlA0mUm7G42LP85lMv7syqFTzDE2q34",
|
2016-12-07 18:38:59 +01:00
|
|
|
};
|
2017-04-06 22:47:27 +02:00
|
|
|
var content = settings_bots.generate_zuliprc_content(user.email, user.api_key);
|
2016-12-07 18:38:59 +01:00
|
|
|
var expected = "[api]\nemail=admin12@chatting.net\n" +
|
|
|
|
"key=nSlA0mUm7G42LP85lMv7syqFTzDE2q34\n" +
|
|
|
|
"site=https://chat.example.com\n";
|
|
|
|
|
|
|
|
assert.equal(content, expected);
|
|
|
|
}());
|
2017-05-30 16:12:02 +02:00
|
|
|
|
|
|
|
(function test_generate_flaskbotrc_content() {
|
|
|
|
var user = {
|
|
|
|
email: "vabstest-bot@zulip.com",
|
|
|
|
api_key: "nSlA0mUm7G42LP85lMv7syqFTzDE2q34",
|
|
|
|
};
|
|
|
|
var content = settings_bots.generate_flaskbotrc_content(user.email, user.api_key);
|
|
|
|
var expected = "[vabstest]\nemail=vabstest-bot@zulip.com\n" +
|
|
|
|
"key=nSlA0mUm7G42LP85lMv7syqFTzDE2q34\n" +
|
|
|
|
"site=https://chat.example.com\n";
|
|
|
|
|
|
|
|
assert.equal(content, expected);
|
|
|
|
}());
|
2017-06-20 00:32:20 +02:00
|
|
|
|
2017-06-24 22:38:27 +02:00
|
|
|
function test_create_bot_type_input_box_toggle(f) {
|
|
|
|
var create_payload_url = $('#create_payload_url');
|
|
|
|
var payload_url_inputbox = $('#payload_url_inputbox');
|
2018-01-07 19:24:14 +01:00
|
|
|
var config_inputbox = $('#config_inputbox');
|
2017-07-15 18:23:44 +02:00
|
|
|
var EMBEDDED_BOT_TYPE = '4';
|
2017-06-24 22:38:27 +02:00
|
|
|
var OUTGOING_WEBHOOK_BOT_TYPE = '3';
|
|
|
|
var GENERIC_BOT_TYPE = '1';
|
|
|
|
|
2017-07-15 18:23:44 +02:00
|
|
|
$('#create_bot_type :selected').val(EMBEDDED_BOT_TYPE);
|
|
|
|
f.apply();
|
|
|
|
assert(!create_payload_url.hasClass('required'));
|
|
|
|
assert(!payload_url_inputbox.visible());
|
|
|
|
assert($('#select_service_name').hasClass('required'));
|
|
|
|
assert($('#service_name_list').visible());
|
2018-01-07 19:24:14 +01:00
|
|
|
assert(config_inputbox.visible());
|
2017-07-15 18:23:44 +02:00
|
|
|
|
2017-06-24 22:38:27 +02:00
|
|
|
$('#create_bot_type :selected').val(OUTGOING_WEBHOOK_BOT_TYPE);
|
|
|
|
f.apply();
|
|
|
|
assert(create_payload_url.hasClass('required'));
|
|
|
|
assert(payload_url_inputbox.visible());
|
2018-01-07 19:24:14 +01:00
|
|
|
assert(!config_inputbox.visible());
|
2017-06-24 22:38:27 +02:00
|
|
|
|
|
|
|
$('#create_bot_type :selected').val(GENERIC_BOT_TYPE);
|
|
|
|
f.apply();
|
|
|
|
assert(!(create_payload_url.hasClass('required')));
|
|
|
|
assert(!payload_url_inputbox.visible());
|
2018-01-07 19:24:14 +01:00
|
|
|
assert(!config_inputbox.visible());
|
2017-06-24 22:38:27 +02:00
|
|
|
}
|
2017-06-20 00:32:20 +02:00
|
|
|
|
|
|
|
(function test_set_up() {
|
|
|
|
// bunch of stubs
|
|
|
|
|
|
|
|
$.validator = { addMethod: function () {} };
|
|
|
|
|
|
|
|
$("#get_api_key_box form").ajaxForm = function () {};
|
|
|
|
|
|
|
|
$("#create_bot_form").validate = function () {};
|
|
|
|
|
2017-06-24 22:38:27 +02:00
|
|
|
$('#create_bot_type').on = function (action, f) {
|
|
|
|
if (action === 'change') {
|
|
|
|
test_create_bot_type_input_box_toggle(f);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-10-19 16:27:03 +02:00
|
|
|
var embedded_bots_added = 0;
|
|
|
|
$('#select_service_name').append = function () {
|
|
|
|
embedded_bots_added += 1;
|
|
|
|
};
|
2018-01-07 19:24:14 +01:00
|
|
|
$('#config_inputbox').children = function () {
|
|
|
|
var mock_children = {
|
|
|
|
hide: function () {
|
|
|
|
return;
|
|
|
|
},
|
|
|
|
};
|
|
|
|
return mock_children;
|
|
|
|
};
|
|
|
|
global.compile_template('embedded_bot_config_item');
|
2017-06-20 00:32:20 +02:00
|
|
|
avatar.build_bot_create_widget = function () {};
|
|
|
|
avatar.build_bot_edit_widget = function () {};
|
|
|
|
|
|
|
|
settings_bots.set_up();
|
2017-10-19 16:27:03 +02:00
|
|
|
assert(embedded_bots_added === page_params.realm_embedded_bots.length);
|
2017-06-20 00:32:20 +02:00
|
|
|
}());
|
|
|
|
|