2017-06-16 14:41:10 +02:00
|
|
|
set_global('$', global.make_zjquery());
|
2017-06-29 20:57:01 +02:00
|
|
|
set_global('i18n', global.stub_i18n);
|
2017-06-16 14:41:10 +02:00
|
|
|
|
2017-11-08 18:51:31 +01:00
|
|
|
zrequire('stream_data');
|
2018-03-02 21:44:14 +01:00
|
|
|
zrequire('settings_account');
|
2017-11-08 18:51:31 +01:00
|
|
|
zrequire('settings_org');
|
2018-03-03 05:44:58 +01:00
|
|
|
zrequire('settings_ui');
|
2018-03-29 02:02:01 +02:00
|
|
|
zrequire('settings_ui');
|
2017-06-16 14:41:10 +02:00
|
|
|
|
|
|
|
var noop = function () {};
|
|
|
|
|
|
|
|
set_global('loading', {
|
|
|
|
make_indicator: noop,
|
|
|
|
destroy_indicator: noop,
|
|
|
|
});
|
|
|
|
|
|
|
|
set_global('page_params', {
|
|
|
|
is_admin: false,
|
|
|
|
realm_domains: [
|
|
|
|
{ domain: 'example.com', allow_subdomains: true },
|
|
|
|
{ domain: 'example.org', allow_subdomains: false },
|
|
|
|
],
|
|
|
|
});
|
|
|
|
|
|
|
|
set_global('realm_icon', {
|
|
|
|
});
|
|
|
|
|
|
|
|
set_global('channel', {
|
|
|
|
});
|
|
|
|
|
|
|
|
set_global('templates', {
|
|
|
|
});
|
|
|
|
|
|
|
|
(function test_unloaded() {
|
|
|
|
// This test mostly gets us line coverage, and makes
|
|
|
|
// sure things don't explode before set_up is called.
|
|
|
|
|
|
|
|
settings_org.reset();
|
|
|
|
settings_org.populate_realm_domains();
|
|
|
|
settings_org.populate_auth_methods();
|
|
|
|
}());
|
|
|
|
|
|
|
|
(function stub_rendering() {
|
|
|
|
templates.render = function (name, data) {
|
|
|
|
if (name === 'admin-realm-domains-list') {
|
|
|
|
assert(data.realm_domain.domain);
|
|
|
|
return 'stub-domains-list';
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}());
|
|
|
|
|
|
|
|
set_global('ui_report', {
|
|
|
|
success: function (msg, elem) {
|
|
|
|
elem.val(msg);
|
|
|
|
},
|
|
|
|
|
|
|
|
error: function (msg, xhr, elem) {
|
|
|
|
elem.val(msg);
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
function simulate_auth_methods() {
|
2017-07-08 14:31:18 +02:00
|
|
|
$('#admin_auth_methods_table').set_find_results(
|
2017-06-16 14:41:10 +02:00
|
|
|
'tr.method_row',
|
2017-07-08 15:16:19 +02:00
|
|
|
$.create('admin-tr-stub')
|
2017-06-16 14:41:10 +02:00
|
|
|
);
|
|
|
|
|
2017-07-08 15:16:19 +02:00
|
|
|
var controls = $.create('auth-methods-controls-stub');
|
2017-06-16 14:41:10 +02:00
|
|
|
|
2017-07-08 14:31:18 +02:00
|
|
|
$(".organization-box [data-name='auth-methods']").set_find_results(
|
2017-06-16 14:41:10 +02:00
|
|
|
'input, button, select, checked',
|
|
|
|
controls
|
|
|
|
);
|
|
|
|
|
|
|
|
controls.attr = function (name, val) {
|
|
|
|
assert.equal(name, 'disabled');
|
|
|
|
assert.equal(val, true);
|
|
|
|
};
|
|
|
|
|
2017-07-08 15:16:19 +02:00
|
|
|
var non_editables = $.create('auth-methods-not-edit-stub');
|
2017-07-08 14:31:18 +02:00
|
|
|
$('.organization-box').set_find_results(
|
2017-06-16 14:41:10 +02:00
|
|
|
'.settings-section:not(.can-edit)',
|
|
|
|
non_editables
|
|
|
|
);
|
|
|
|
|
2017-07-13 20:53:27 +02:00
|
|
|
non_editables.not = function () { return this; };
|
2017-06-16 14:41:10 +02:00
|
|
|
non_editables.prepend = noop;
|
|
|
|
}
|
|
|
|
|
|
|
|
function simulate_realm_domains_table() {
|
2017-07-08 14:31:18 +02:00
|
|
|
$('#realm_domains_table tbody').set_find_results(
|
2017-06-16 14:41:10 +02:00
|
|
|
'tr',
|
2017-07-08 15:16:19 +02:00
|
|
|
$.create('realm-tr-stub')
|
2017-06-16 14:41:10 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
var appended;
|
|
|
|
$("#realm_domains_table tbody").append = function (html) {
|
|
|
|
appended = true;
|
|
|
|
assert.equal(html, 'stub-domains-list');
|
|
|
|
};
|
|
|
|
|
|
|
|
return function verify() {
|
|
|
|
assert(appended);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
function test_realms_domain_modal(add_realm_domain) {
|
2017-12-02 18:44:39 +01:00
|
|
|
var info = $('.realm_domains_info');
|
2017-06-16 14:41:10 +02:00
|
|
|
|
2017-07-08 14:31:18 +02:00
|
|
|
$('#add-realm-domain-widget').set_find_results(
|
2017-06-16 14:41:10 +02:00
|
|
|
'.new-realm-domain',
|
2017-07-08 15:16:19 +02:00
|
|
|
$.create('new-realm-domain-stub')
|
2017-06-16 14:41:10 +02:00
|
|
|
);
|
|
|
|
|
2017-07-08 14:31:18 +02:00
|
|
|
$('#add-realm-domain-widget').set_find_results(
|
2017-06-16 14:41:10 +02:00
|
|
|
'.new-realm-domain-allow-subdomains',
|
2017-07-08 15:16:19 +02:00
|
|
|
$.create('new-realm-domain-allow-subdomains-stub')
|
2017-06-16 14:41:10 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
var posted;
|
|
|
|
var success_callback;
|
|
|
|
var error_callback;
|
|
|
|
channel.post = function (req) {
|
|
|
|
posted = true;
|
|
|
|
assert.equal(req.url, '/json/realm/domains');
|
|
|
|
success_callback = req.success;
|
|
|
|
error_callback = req.error;
|
|
|
|
};
|
|
|
|
|
|
|
|
add_realm_domain();
|
|
|
|
|
|
|
|
assert(posted);
|
|
|
|
|
|
|
|
success_callback();
|
2017-12-25 17:49:46 +01:00
|
|
|
assert.equal(info.val(), 'translated: Added successfully!');
|
2017-06-16 14:41:10 +02:00
|
|
|
|
2017-12-25 17:49:46 +01:00
|
|
|
error_callback({});
|
|
|
|
assert.equal(info.val(), 'translated: Failed');
|
2017-06-16 14:41:10 +02:00
|
|
|
}
|
2018-03-29 02:02:01 +02:00
|
|
|
function createSaveButtons() {
|
|
|
|
var stub_save_button_header = $('.subsection-header');
|
|
|
|
var save_btn_controls = $.create('.save-btn-controls');
|
|
|
|
var stub_save_button = $('#org-submit-msg-editing');
|
|
|
|
var stub_save_button_text = $.create('.icon-button-text');
|
|
|
|
stub_save_button_header.prevAll = function () {
|
|
|
|
return $.create('<stub failed alert status element>');
|
|
|
|
};
|
|
|
|
stub_save_button.closest = function () {
|
|
|
|
return stub_save_button_header;
|
|
|
|
};
|
|
|
|
save_btn_controls.set_find_results(
|
|
|
|
'.save-button', stub_save_button
|
|
|
|
);
|
|
|
|
stub_save_button.set_find_results(
|
|
|
|
'.icon-button-text', stub_save_button_text
|
|
|
|
);
|
|
|
|
stub_save_button_header.set_find_results(
|
|
|
|
'.save-button-controls', save_btn_controls
|
|
|
|
);
|
|
|
|
stub_save_button_header.set_find_results(
|
|
|
|
'.subsection-changes-discard .button', $.create('#org-discard-msg-editing')
|
|
|
|
);
|
|
|
|
var props = {};
|
|
|
|
props.hidden = false;
|
|
|
|
props.status = "";
|
|
|
|
stub_save_button.attr = function (name, val) {
|
|
|
|
if (name === "data-status") {
|
|
|
|
if (val !== null) {
|
|
|
|
props.status = val;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
return props.status;
|
|
|
|
} else if (name === "id") {
|
|
|
|
return 'org-submit-msg-editing';
|
|
|
|
}
|
|
|
|
};
|
|
|
|
save_btn_controls.animate = function (obj) {
|
|
|
|
if (obj.opacity === 0) {
|
|
|
|
props.hidden = true;
|
|
|
|
} else {
|
|
|
|
props.hidden = false;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
return {
|
|
|
|
props: props,
|
|
|
|
save_button: stub_save_button,
|
|
|
|
save_button_header: stub_save_button_header,
|
|
|
|
save_button_controls: save_btn_controls,
|
|
|
|
save_button_text: stub_save_button_text,
|
|
|
|
};
|
|
|
|
}
|
2017-08-18 01:23:55 +02:00
|
|
|
function test_submit_settings_form(submit_form) {
|
2017-06-16 14:41:10 +02:00
|
|
|
var ev = {
|
|
|
|
preventDefault: noop,
|
|
|
|
stopPropagation: noop,
|
2018-03-29 02:02:01 +02:00
|
|
|
currentTarget: '#org-submit-msg-editing',
|
2017-06-16 14:41:10 +02:00
|
|
|
};
|
|
|
|
|
2017-08-18 01:23:55 +02:00
|
|
|
$('#id_realm_default_language').val('fr');
|
2017-06-16 14:41:10 +02:00
|
|
|
|
|
|
|
var patched;
|
|
|
|
var success_callback;
|
2017-08-18 01:23:55 +02:00
|
|
|
|
2017-06-16 14:41:10 +02:00
|
|
|
channel.patch = function (req) {
|
|
|
|
patched = true;
|
|
|
|
assert.equal(req.url, '/json/realm');
|
|
|
|
success_callback = req.success;
|
|
|
|
};
|
|
|
|
|
2018-03-29 02:02:01 +02:00
|
|
|
createSaveButtons();
|
2018-03-14 23:45:42 +01:00
|
|
|
|
2017-06-16 14:41:10 +02:00
|
|
|
submit_form(ev);
|
|
|
|
assert(patched);
|
|
|
|
|
|
|
|
var response_data = {
|
|
|
|
allow_message_editing: true,
|
|
|
|
message_content_edit_limit_seconds: 210,
|
|
|
|
};
|
2017-08-18 01:23:55 +02:00
|
|
|
success_callback(response_data);
|
2017-06-16 14:41:10 +02:00
|
|
|
|
2018-03-14 23:45:42 +01:00
|
|
|
var updated_value_from_response = $('#id_realm_message_content_edit_limit_minutes').val();
|
|
|
|
assert(updated_value_from_response, 3);
|
2017-06-16 14:41:10 +02:00
|
|
|
|
2018-03-14 23:45:42 +01:00
|
|
|
$('#id_realm_message_content_edit_limit_minutes').val = function (time_limit) {
|
|
|
|
updated_value_from_response = time_limit;
|
2017-06-16 14:41:10 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
response_data = {
|
2018-03-14 23:45:42 +01:00
|
|
|
allow_message_editing: true,
|
|
|
|
message_content_edit_limit_seconds: 10,
|
2017-06-16 14:41:10 +02:00
|
|
|
};
|
|
|
|
success_callback(response_data);
|
2018-03-14 23:45:42 +01:00
|
|
|
assert(updated_value_from_response, 0);
|
2017-08-18 01:23:55 +02:00
|
|
|
}
|
|
|
|
|
2018-03-29 02:02:01 +02:00
|
|
|
function test_change_save_button_state() {
|
|
|
|
set_global('$', global.make_zjquery());
|
|
|
|
var stubs = createSaveButtons();
|
|
|
|
var $save_btn_controls = stubs.save_button_controls;
|
|
|
|
var $save_btn_text = stubs.save_button_text;
|
|
|
|
var $save_btn = stubs.save_button;
|
|
|
|
var props = stubs.props;
|
|
|
|
settings_org.change_save_button_state($save_btn_controls, "unsaved");
|
|
|
|
assert.equal($save_btn_text.text(), 'translated: Save changes');
|
|
|
|
assert.equal(props.hidden, false);
|
|
|
|
assert.equal(props.status, "unsaved");
|
|
|
|
settings_org.change_save_button_state($save_btn_controls, "saved");
|
|
|
|
assert.equal($save_btn_text.text(), 'translated: Save changes');
|
|
|
|
assert.equal(props.hidden, true);
|
|
|
|
assert.equal(props.status, "");
|
|
|
|
settings_org.change_save_button_state($save_btn_controls, "saving");
|
|
|
|
assert.equal($save_btn_text.text(), 'translated: Saving');
|
|
|
|
assert.equal(props.status, "saving");
|
|
|
|
assert.equal($save_btn.hasClass('saving'), true);
|
|
|
|
settings_org.change_save_button_state($save_btn_controls, "discarded");
|
|
|
|
assert.equal(props.hidden, true);
|
|
|
|
assert.equal($save_btn.hasClass('saving'), false);
|
|
|
|
settings_org.change_save_button_state($save_btn_controls, "succeeded");
|
|
|
|
assert.equal(props.hidden, true);
|
|
|
|
assert.equal(props.status, "saved");
|
|
|
|
assert.equal($save_btn_text.text(), 'translated: Saved');
|
|
|
|
settings_org.change_save_button_state($save_btn_controls, "failed");
|
|
|
|
assert.equal(props.hidden, false);
|
|
|
|
assert.equal(props.status, "failed");
|
|
|
|
assert.equal($save_btn_text.text(), 'translated: Save changes');
|
|
|
|
}
|
|
|
|
|
2017-06-16 14:41:10 +02:00
|
|
|
function test_upload_realm_icon(upload_realm_icon) {
|
|
|
|
var form_data = {
|
|
|
|
append: function (field, val) {
|
|
|
|
form_data[field] = val;
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
set_global('csrf_token', 'token-stub');
|
|
|
|
set_global('jQuery', {
|
|
|
|
each: function (lst, f) {
|
|
|
|
_.each(lst, function (v, k) {
|
|
|
|
f(k, v);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
set_global('FormData', function () {
|
|
|
|
return form_data;
|
|
|
|
});
|
|
|
|
|
|
|
|
var file_input = [
|
|
|
|
{files: ['image1.png', 'image2.png']},
|
|
|
|
];
|
|
|
|
|
|
|
|
var posted;
|
2017-07-05 19:02:54 +02:00
|
|
|
channel.post = function (req) {
|
2017-06-16 14:41:10 +02:00
|
|
|
posted = true;
|
|
|
|
assert.equal(req.url, '/json/realm/icon');
|
|
|
|
assert.equal(req.data.csrfmiddlewaretoken, 'token-stub');
|
|
|
|
assert.equal(req.data['file-0'], 'image1.png');
|
|
|
|
assert.equal(req.data['file-1'], 'image2.png');
|
|
|
|
};
|
|
|
|
|
|
|
|
upload_realm_icon(file_input);
|
|
|
|
assert(posted);
|
|
|
|
}
|
|
|
|
|
|
|
|
function test_change_message_editing(change_message_editing) {
|
2017-07-08 15:16:19 +02:00
|
|
|
var parent_elem = $.create('editing-parent-stub');
|
2017-06-16 14:41:10 +02:00
|
|
|
|
2017-07-08 14:05:49 +02:00
|
|
|
$('#id_realm_message_content_edit_limit_minutes_label').set_parent(parent_elem);
|
2017-06-16 14:41:10 +02:00
|
|
|
|
|
|
|
change_message_editing.apply({checked: false});
|
|
|
|
assert(parent_elem.hasClass('control-label-disabled'));
|
2018-03-03 05:44:58 +01:00
|
|
|
assert.equal($('#id_realm_message_content_edit_limit_minutes').attr('disabled'), 'disabled');
|
2017-06-16 14:41:10 +02:00
|
|
|
|
|
|
|
change_message_editing.apply({checked: true});
|
|
|
|
assert(!parent_elem.hasClass('control-label-disabled'));
|
2018-03-03 05:44:58 +01:00
|
|
|
assert.equal($('#id_realm_message_content_edit_limit_minutes').attr('disabled'), false);
|
2017-06-16 14:41:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function test_change_invite_required(change_invite_required) {
|
2017-07-08 15:16:19 +02:00
|
|
|
var parent_elem = $.create('invite-parent-stub');
|
2017-06-16 14:41:10 +02:00
|
|
|
|
2017-07-08 14:05:49 +02:00
|
|
|
$('#id_realm_invite_by_admins_only_label').set_parent(parent_elem);
|
2017-06-16 14:41:10 +02:00
|
|
|
|
|
|
|
change_invite_required.apply({checked: false});
|
|
|
|
assert(parent_elem.hasClass('control-label-disabled'));
|
2018-03-03 05:44:58 +01:00
|
|
|
assert.equal($('#id_realm_invite_by_admins_only').attr('disabled'), 'disabled');
|
2017-06-16 14:41:10 +02:00
|
|
|
|
|
|
|
change_invite_required.apply({checked: true});
|
|
|
|
assert(!parent_elem.hasClass('control-label-disabled'));
|
2018-03-03 05:44:58 +01:00
|
|
|
assert.equal($('#id_realm_invite_by_admins_only').attr('disabled'), false);
|
2017-06-16 14:41:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function test_disable_notifications_stream(disable_notifications_stream) {
|
|
|
|
var success_callback;
|
|
|
|
var error_callback;
|
|
|
|
channel.patch = function (req) {
|
|
|
|
assert.equal(req.url, '/json/realm');
|
|
|
|
assert.equal(req.data.notifications_stream_id, '-1');
|
|
|
|
success_callback = req.success;
|
|
|
|
error_callback = req.error;
|
|
|
|
};
|
|
|
|
|
|
|
|
disable_notifications_stream();
|
|
|
|
|
|
|
|
var response_data = {
|
|
|
|
notifications_stream_id: -1,
|
|
|
|
};
|
|
|
|
|
|
|
|
success_callback(response_data);
|
|
|
|
assert.equal($('#admin-realm-notifications-stream-status').val(),
|
|
|
|
'translated: Notifications stream disabled!');
|
|
|
|
|
|
|
|
error_callback({});
|
|
|
|
assert.equal($('#admin-realm-notifications-stream-status').val(),
|
|
|
|
'translated: Failed to change notifications stream!');
|
|
|
|
}
|
|
|
|
|
2017-10-20 16:55:04 +02:00
|
|
|
function test_disable_signup_notifications_stream(disable_signup_notifications_stream) {
|
|
|
|
var success_callback;
|
|
|
|
var error_callback;
|
|
|
|
channel.patch = function (req) {
|
|
|
|
assert.equal(req.url, '/json/realm');
|
|
|
|
assert.equal(req.data.signup_notifications_stream_id, '-1');
|
|
|
|
success_callback = req.success;
|
|
|
|
error_callback = req.error;
|
|
|
|
};
|
|
|
|
|
|
|
|
disable_signup_notifications_stream();
|
|
|
|
|
|
|
|
var response_data = {
|
|
|
|
signup_notifications_stream_id: -1,
|
|
|
|
};
|
|
|
|
|
|
|
|
success_callback(response_data);
|
|
|
|
assert.equal($('#admin-realm-signup-notifications-stream-status').val(),
|
|
|
|
'translated: Signup notifications stream disabled!');
|
|
|
|
|
|
|
|
error_callback({});
|
|
|
|
assert.equal($('#admin-realm-signup-notifications-stream-status').val(),
|
|
|
|
'translated: Failed to change signup notifications stream!');
|
|
|
|
}
|
|
|
|
|
2017-06-16 14:41:10 +02:00
|
|
|
function test_change_allow_subdomains(change_allow_subdomains) {
|
|
|
|
var ev = {
|
|
|
|
stopPropagation: noop,
|
|
|
|
};
|
|
|
|
|
2017-12-02 18:44:39 +01:00
|
|
|
var info = $('.realm_domains_info');
|
2017-06-16 14:41:10 +02:00
|
|
|
var domain = 'example.com';
|
|
|
|
var allow = true;
|
|
|
|
|
|
|
|
var success_callback;
|
|
|
|
var error_callback;
|
|
|
|
channel.patch = function (req) {
|
|
|
|
assert.equal(req.url, '/json/realm/domains/example.com');
|
|
|
|
assert.equal(req.data.allow_subdomains, JSON.stringify(allow));
|
|
|
|
success_callback = req.success;
|
|
|
|
error_callback = req.error;
|
|
|
|
};
|
|
|
|
|
2017-07-08 15:16:19 +02:00
|
|
|
var domain_obj = $.create('domain object');
|
|
|
|
domain_obj.text(domain);
|
|
|
|
|
|
|
|
|
|
|
|
var elem_obj = $('<elem html>');
|
|
|
|
var parents_obj = $.create('parents object');
|
|
|
|
|
|
|
|
elem_obj.set_parents_result('tr', parents_obj);
|
|
|
|
parents_obj.set_find_results('.domain', domain_obj);
|
|
|
|
elem_obj.prop('checked', allow);
|
2017-06-16 14:41:10 +02:00
|
|
|
|
2017-07-08 15:16:19 +02:00
|
|
|
change_allow_subdomains.apply('<elem html>', [ev]);
|
2017-06-16 14:41:10 +02:00
|
|
|
|
|
|
|
success_callback();
|
2017-12-25 17:49:46 +01:00
|
|
|
assert.equal(info.val(),
|
2017-06-29 20:57:01 +02:00
|
|
|
'translated: Update successful: Subdomains allowed for example.com');
|
2017-06-16 14:41:10 +02:00
|
|
|
|
2017-12-25 17:49:46 +01:00
|
|
|
error_callback({});
|
|
|
|
assert.equal(info.val(), 'translated: Failed');
|
2017-06-16 14:41:10 +02:00
|
|
|
|
|
|
|
allow = false;
|
2017-07-08 15:16:19 +02:00
|
|
|
elem_obj.prop('checked', allow);
|
|
|
|
change_allow_subdomains.apply('<elem html>', [ev]);
|
2017-06-16 14:41:10 +02:00
|
|
|
success_callback();
|
2017-12-25 17:49:46 +01:00
|
|
|
assert.equal(info.val(),
|
2017-06-29 20:57:01 +02:00
|
|
|
'translated: Update successful: Subdomains no longer allowed for example.com');
|
2017-06-16 14:41:10 +02:00
|
|
|
}
|
|
|
|
|
2018-03-14 23:50:17 +01:00
|
|
|
function test_extract_property_name() {
|
|
|
|
$('#id_realm_allow_message_editing').attr('id', 'id_realm_allow_message_editing');
|
|
|
|
assert.equal(
|
|
|
|
settings_org.extract_property_name($('#id_realm_allow_message_editing')),
|
|
|
|
'realm_allow_message_editing'
|
|
|
|
);
|
|
|
|
|
|
|
|
$('#id_realm_message_content_edit_limit_minutes_label').attr(
|
|
|
|
'id', 'id_realm_message_content_edit_limit_minutes_label');
|
|
|
|
assert.equal(
|
|
|
|
settings_org.extract_property_name($('#id_realm_message_content_edit_limit_minutes_label')),
|
|
|
|
'realm_message_content_edit_limit_minutes_label'
|
|
|
|
);
|
|
|
|
|
|
|
|
$('#id-realm-allow-message-deleting').attr(
|
|
|
|
'id', 'id-realm-allow-message-deleting');
|
|
|
|
assert.equal(
|
|
|
|
settings_org.extract_property_name($('#id-realm-allow-message-deleting')),
|
|
|
|
'realm_allow_message_deleting'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2017-06-16 14:41:10 +02:00
|
|
|
(function test_set_up() {
|
|
|
|
var callbacks = {};
|
|
|
|
|
|
|
|
function set_callback(name) {
|
|
|
|
return function (f) {
|
|
|
|
callbacks[name] = f;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
var verify_realm_domains = simulate_realm_domains_table();
|
|
|
|
simulate_auth_methods();
|
|
|
|
|
2018-01-05 15:34:10 +01:00
|
|
|
$('#id_realm_create_stream_permission').change = set_callback('realm_create_stream_permission');
|
2017-06-16 14:41:10 +02:00
|
|
|
$('#id_realm_invite_required').change = set_callback('change_invite_required');
|
2018-03-05 19:19:19 +01:00
|
|
|
$('#id_realm_restricted_to_domain').change = set_callback('id_realm_restricted_to_domain');
|
2017-06-16 14:41:10 +02:00
|
|
|
$('#id_realm_allow_message_editing').change = set_callback('change_message_editing');
|
|
|
|
$('#submit-add-realm-domain').click = set_callback('add_realm_domain');
|
|
|
|
$('.notifications-stream-disable').click = set_callback('disable_notifications_stream');
|
2017-10-20 16:55:04 +02:00
|
|
|
$('.signup-notifications-stream-disable').click = set_callback('disable_signup_notifications_stream');
|
2017-06-16 14:41:10 +02:00
|
|
|
|
|
|
|
var submit_settings_form;
|
|
|
|
$('.organization').on = function (action, selector, f) {
|
2018-03-29 02:02:01 +02:00
|
|
|
if (selector === '.subsection-header .subsection-changes-save .button') {
|
2018-01-11 17:47:37 +01:00
|
|
|
assert.equal(action, 'click');
|
2017-06-16 14:41:10 +02:00
|
|
|
submit_settings_form = f;
|
|
|
|
}
|
2018-01-11 17:47:37 +01:00
|
|
|
if (selector === 'button.save-language-org-settings') {
|
|
|
|
assert.equal(action, 'click');
|
|
|
|
}
|
2018-03-25 15:46:34 +02:00
|
|
|
};
|
|
|
|
|
2017-06-16 14:41:10 +02:00
|
|
|
var change_allow_subdomains;
|
|
|
|
$('#realm_domains_table').on = function (action, selector, f) {
|
|
|
|
if (action === 'change') {
|
|
|
|
assert.equal(selector, '.allow-subdomains');
|
|
|
|
change_allow_subdomains = f;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
var upload_realm_icon;
|
|
|
|
realm_icon.build_realm_icon_widget = function (f) {
|
|
|
|
upload_realm_icon = f;
|
|
|
|
};
|
|
|
|
|
2018-04-03 22:25:18 +02:00
|
|
|
var stub_render_notifications_stream_ui = settings_org.render_notifications_stream_ui;
|
|
|
|
settings_org.render_notifications_stream_ui = noop;
|
2018-01-05 15:34:10 +01:00
|
|
|
var parent_elem = $.create('waiting-period-parent-stub');
|
|
|
|
$('#id_realm_waiting_period_threshold').set_parent(parent_elem);
|
2017-06-16 14:41:10 +02:00
|
|
|
// TEST set_up() here, but this mostly just allows us to
|
|
|
|
// get access to the click handlers.
|
|
|
|
settings_org.set_up();
|
|
|
|
|
|
|
|
verify_realm_domains();
|
|
|
|
|
|
|
|
test_realms_domain_modal(callbacks.add_realm_domain);
|
|
|
|
test_submit_settings_form(submit_settings_form);
|
|
|
|
test_upload_realm_icon(upload_realm_icon);
|
|
|
|
test_change_invite_required(callbacks.change_invite_required);
|
|
|
|
test_change_message_editing(callbacks.change_message_editing);
|
|
|
|
test_disable_notifications_stream(callbacks.disable_notifications_stream);
|
2017-10-20 16:55:04 +02:00
|
|
|
test_disable_signup_notifications_stream(callbacks.disable_signup_notifications_stream);
|
2017-06-16 14:41:10 +02:00
|
|
|
test_change_allow_subdomains(change_allow_subdomains);
|
2018-03-14 23:50:17 +01:00
|
|
|
test_extract_property_name();
|
2018-04-03 22:25:18 +02:00
|
|
|
settings_org.render_notifications_stream_ui = stub_render_notifications_stream_ui;
|
2018-03-29 02:02:01 +02:00
|
|
|
test_change_save_button_state();
|
2017-06-16 14:41:10 +02:00
|
|
|
}());
|
|
|
|
|
|
|
|
(function test_misc() {
|
2018-02-02 16:54:26 +01:00
|
|
|
page_params.is_admin = false;
|
2017-06-16 14:41:10 +02:00
|
|
|
|
2018-04-03 22:25:18 +02:00
|
|
|
var stub_notification_disable_parent = $.create('<stub notification_disable parent');
|
|
|
|
stub_notification_disable_parent.set_find_results('.notification-disable',
|
|
|
|
$.create('<disable link>'));
|
|
|
|
|
2018-03-02 21:26:59 +01:00
|
|
|
page_params.realm_name_changes_disabled = false;
|
2018-03-02 21:44:14 +01:00
|
|
|
settings_account.update_name_change_display();
|
2018-03-02 21:48:23 +01:00
|
|
|
assert.equal($('#full_name').attr('disabled'), false);
|
2017-06-16 14:41:10 +02:00
|
|
|
|
2018-03-02 21:26:59 +01:00
|
|
|
page_params.realm_name_changes_disabled = true;
|
2018-03-02 21:44:14 +01:00
|
|
|
settings_account.update_name_change_display();
|
2018-03-02 21:48:23 +01:00
|
|
|
assert.equal($('#full_name').attr('disabled'), 'disabled');
|
2017-06-16 14:41:10 +02:00
|
|
|
|
2018-03-02 21:26:59 +01:00
|
|
|
page_params.realm_email_changes_disabled = false;
|
2018-03-02 21:44:14 +01:00
|
|
|
settings_account.update_email_change_display();
|
2018-03-02 21:48:23 +01:00
|
|
|
assert.equal($("#change_email .button").attr('disabled'), false);
|
2018-01-04 13:02:17 +01:00
|
|
|
|
2018-03-02 21:26:59 +01:00
|
|
|
page_params.realm_email_changes_disabled = true;
|
2018-03-02 21:44:14 +01:00
|
|
|
settings_account.update_email_change_display();
|
2018-03-02 21:48:23 +01:00
|
|
|
assert.equal($("#change_email .button").attr('disabled'), 'disabled');
|
2017-06-16 14:41:10 +02:00
|
|
|
|
2018-03-02 21:44:14 +01:00
|
|
|
// If organization admin, these UI elements are never disabled.
|
2018-02-02 16:54:26 +01:00
|
|
|
page_params.is_admin = true;
|
2018-03-02 21:44:14 +01:00
|
|
|
settings_account.update_name_change_display();
|
2018-03-02 21:48:23 +01:00
|
|
|
assert.equal($('#full_name').attr('disabled'), false);
|
2018-02-02 16:54:26 +01:00
|
|
|
|
2018-03-02 21:44:14 +01:00
|
|
|
settings_account.update_email_change_display();
|
2018-03-02 21:48:23 +01:00
|
|
|
assert.equal($("#change_email .button").attr('disabled'), false);
|
2018-02-02 16:54:26 +01:00
|
|
|
|
2017-06-16 14:41:10 +02:00
|
|
|
var elem = $('#realm_notifications_stream_name');
|
2018-04-03 22:25:18 +02:00
|
|
|
elem.closest = function () {
|
|
|
|
return stub_notification_disable_parent;
|
|
|
|
};
|
2017-06-16 14:41:10 +02:00
|
|
|
stream_data.get_sub_by_id = function (stream_id) {
|
|
|
|
assert.equal(stream_id, 42);
|
|
|
|
return { name: 'some_stream' };
|
|
|
|
};
|
2018-03-31 03:08:33 +02:00
|
|
|
settings_org.render_notifications_stream_ui(42, elem);
|
2017-06-16 14:41:10 +02:00
|
|
|
assert.equal(elem.text(), '#some_stream');
|
|
|
|
assert(!elem.hasClass('text-warning'));
|
|
|
|
|
|
|
|
stream_data.get_sub_by_id = noop;
|
2018-03-31 03:08:33 +02:00
|
|
|
settings_org.render_notifications_stream_ui(undefined, elem);
|
2017-06-16 14:41:10 +02:00
|
|
|
assert.equal(elem.text(), 'translated: Disabled');
|
|
|
|
assert(elem.hasClass('text-warning'));
|
2017-10-20 16:55:04 +02:00
|
|
|
|
|
|
|
elem = $('#realm_signup_notifications_stream_name');
|
2018-04-03 22:25:18 +02:00
|
|
|
elem.closest = function () {
|
|
|
|
return stub_notification_disable_parent;
|
|
|
|
};
|
2017-10-20 16:55:04 +02:00
|
|
|
stream_data.get_sub_by_id = function (stream_id) {
|
|
|
|
assert.equal(stream_id, 75);
|
|
|
|
return { name: 'some_stream' };
|
|
|
|
};
|
2018-03-31 03:44:07 +02:00
|
|
|
settings_org.render_notifications_stream_ui(75, elem);
|
2017-10-20 16:55:04 +02:00
|
|
|
assert.equal(elem.text(), '#some_stream');
|
|
|
|
assert(!elem.hasClass('text-warning'));
|
|
|
|
|
|
|
|
stream_data.get_sub_by_id = noop;
|
2018-03-31 03:44:07 +02:00
|
|
|
settings_org.render_notifications_stream_ui(undefined, elem);
|
2017-10-20 16:55:04 +02:00
|
|
|
assert.equal(elem.text(), 'translated: Disabled');
|
|
|
|
assert(elem.hasClass('text-warning'));
|
|
|
|
|
2017-06-16 14:41:10 +02:00
|
|
|
}());
|