Add run_test helper for individual tests.

This run_test helper sets up a convention that allows
us to give really short tracebacks for errors, and
eventually we can have more control over running
individual tests.  (The latter goal has some
complications, since we often intentionally leak
setup in tests.)
This commit is contained in:
Steve Howell 2018-05-15 10:40:07 +00:00 committed by Tim Abbott
parent 4f0b3fc1b6
commit 42435db492
85 changed files with 815 additions and 807 deletions

View File

@ -9,6 +9,7 @@
"globals": {
"$": false,
"_": false,
"run_test": false,
"jQuery": false,
"Spinner": false,
"Handlebars": false,

View File

@ -140,21 +140,21 @@ presence_info[jill.user_id] = { status: 'active' };
presence.presence_info = presence_info;
(function test_get_status() {
run_test('get_status', () => {
assert.equal(presence.get_status(page_params.user_id), "active");
assert.equal(presence.get_status(alice.user_id), "inactive");
assert.equal(presence.get_status(fred.user_id), "active");
assert.equal(presence.get_status(zoe.user_id), "offline");
}());
});
(function test_reload_defaults() {
run_test('reload_defaults', () => {
blueslip.set_test_data('warn', 'get_filter_text() is called before initialization');
assert.equal(activity.get_filter_text(), '');
assert(blueslip.get_test_logs('warn').length, 1);
blueslip.clear_test_data();
}());
});
(function test_sort_users() {
run_test('sort_users', () => {
const user_ids = [alice.user_id, fred.user_id, jill.user_id];
buddy_data.sort_users(user_ids);
@ -164,9 +164,9 @@ presence.presence_info = presence_info;
jill.user_id,
alice.user_id,
]);
}());
});
(function test_process_loaded_messages() {
run_test('process_loaded_messages', () => {
const huddle1 = 'jill@zulip.com,norbert@zulip.com';
const timestamp1 = 1382479029; // older
@ -206,9 +206,9 @@ presence.presence_info = presence_info;
const user_ids_string1 = people.emails_strings_to_user_ids_string(huddle1);
const user_ids_string2 = people.emails_strings_to_user_ids_string(huddle2);
assert.deepEqual(activity.get_huddles(), [user_ids_string2, user_ids_string1]);
}());
});
(function test_full_huddle_name() {
run_test('full_huddle_name', () => {
function full_name(emails_string) {
const user_ids_string = people.emails_strings_to_user_ids_string(emails_string);
return activity.full_huddle_name(user_ids_string);
@ -221,9 +221,9 @@ presence.presence_info = presence_info;
assert.equal(
full_name('alice@zulip.com,fred@zulip.com,jill@zulip.com'),
'Alice Smith, Fred Flintstone, Jill Hill');
}());
});
(function test_short_huddle_name() {
run_test('short_huddle_name', () => {
function short_name(emails_string) {
const user_ids_string = people.emails_strings_to_user_ids_string(emails_string);
return activity.short_huddle_name(user_ids_string);
@ -249,9 +249,9 @@ presence.presence_info = presence_info;
short_name('alice@zulip.com,fred@zulip.com,jill@zulip.com,mark@zulip.com,norbert@zulip.com'),
'Alice Smith, Fred Flintstone, Jill Hill, + 2 others');
}());
});
(function test_huddle_fraction_present() {
run_test('huddle_fraction_present', () => {
let huddle = 'alice@zulip.com,fred@zulip.com,jill@zulip.com,mark@zulip.com';
huddle = people.emails_strings_to_user_ids_string(huddle);
@ -278,7 +278,7 @@ presence.presence_info = presence_info;
assert.equal(
activity.huddle_fraction_present(huddle),
false);
}());
});
presence.presence_info = {};
presence.presence_info[alice.user_id] = { status: activity.IDLE };
@ -301,7 +301,7 @@ function reset_setup() {
reset_setup();
(function test_presence_list_full_update() {
run_test('presence_list_full_update', () => {
$('.user-list-filter').focus();
compose_state.recipient = () => fred.email;
compose_fade.set_focused_recipient("private");
@ -363,7 +363,7 @@ reset_setup();
faded: true,
},
]);
}());
});
function simulate_right_column_buddy_list() {
$('.user-list-filter').closest = function (selector) {
@ -401,7 +401,7 @@ function buddy_list_add(user_id, stub) {
$('#user_presences').set_find_results(sel, stub);
}
(function test_PM_update_dom_counts() {
run_test('PM_update_dom_counts', () => {
const value = $.create('alice-value');
const count = $.create('alice-count');
const pm_key = alice.user_id.toString();
@ -424,9 +424,9 @@ function buddy_list_add(user_id, stub) {
activity.update_dom_with_unread_counts({pm_count: counts});
assert(!li.hasClass('user-with-count'));
assert.equal(value.text(), '');
}());
});
(function test_group_update_dom_counts() {
run_test('group_update_dom_counts', () => {
const value = $.create('alice-fred-value');
const count = $.create('alice-fred-count');
const pm_key = alice.user_id.toString() + "," + fred.user_id.toString();
@ -449,11 +449,11 @@ function buddy_list_add(user_id, stub) {
activity.update_dom_with_unread_counts({pm_count: counts});
assert(!li.hasClass('group-with-count'));
assert.equal(value.text(), '');
}());
});
reset_setup();
(function test_handlers() {
run_test('handlers', () => {
// This is kind of weak coverage; we are mostly making sure that
// keys and clicks got mapped to functions that don't crash.
@ -541,7 +541,7 @@ reset_setup();
const handler = $('.user-list-filter').get_on_handler('blur');
handler(e);
}());
}());
});
presence.presence_info = {};
presence.presence_info[alice.user_id] = { status: activity.ACTIVE };
@ -553,7 +553,7 @@ presence.presence_info[zoe.user_id] = { status: activity.ACTIVE };
reset_setup();
(function test_filter_user_ids() {
run_test('filter_user_ids', () => {
const user_filter = $('.user-list-filter');
user_filter.val(''); // no search filter
@ -598,9 +598,9 @@ reset_setup();
presence.presence_info[alice.user_id] = { status: activity.ACTIVE };
user_ids = get_user_ids();
assert.deepEqual(user_ids, [alice.user_id, fred.user_id]);
}());
});
(function test_insert_one_user_into_empty_list() {
run_test('insert_one_user_into_empty_list', () => {
const alice_li = $.create('alice list item');
let appended_html;
@ -622,11 +622,11 @@ reset_setup();
assert(appended_html.indexOf('data-user-id="1"') > 0);
assert(appended_html.indexOf('user_active') > 0);
assert(removed);
}());
});
reset_setup();
(function test_insert_fred_after_alice() {
run_test('insert_fred_after_alice', () => {
const alice_li = $.create('alice list item');
const fred_li = $.create('fred list item');
@ -653,11 +653,11 @@ reset_setup();
assert(appended_html.indexOf('data-user-id="2"') > 0);
assert(appended_html.indexOf('user_active') > 0);
assert(removed);
}());
});
reset_setup();
(function test_insert_fred_before_jill() {
run_test('insert_fred_before_jill', () => {
const fred_li = $.create('fred-li');
const jill_li = $.create('jill-li');
@ -684,21 +684,21 @@ reset_setup();
assert(before_html.indexOf('data-user-id="2"') > 0);
assert(before_html.indexOf('user_active') > 0);
assert(removed);
}());
});
// Reset jquery here.
reset_setup();
(function test_insert_unfiltered_user_with_filter() {
run_test('insert_unfiltered_user_with_filter', () => {
// This test only tests that we do not explode when
// try to insert Fred into a list where he does not
// match the search filter.
const user_filter = $('.user-list-filter');
user_filter.val('do-not-match-filter');
activity.insert_user_into_list(fred.user_id);
}());
});
(function test_realm_presence_disabled() {
run_test('realm_presence_disabled', () => {
page_params.realm_presence_disabled = true;
unread.suppress_unread_counts = false;
@ -706,7 +706,7 @@ reset_setup();
activity.build_user_sidebar();
real_update_huddles();
}());
});
// Mock the jquery is func
$('.user-list-filter').is = function (sel) {
@ -719,21 +719,21 @@ $('.user-list-filter').parent = function () {
return $('#user-list .input-append');
};
(function test_clear_search() {
run_test('clear_search', () => {
$('.user-list-filter').val('somevalue');
activity.user_filter.clear_search();
assert.equal($('.user-list-filter').val(), '');
activity.user_filter.clear_search();
assert($('#user-list .input-append').hasClass('notdisplayed'));
}());
});
(function test_escape_search() {
run_test('escape_search', () => {
$('.user-list-filter').val('somevalue');
activity.escape_search();
assert.equal($('.user-list-filter').val(), '');
activity.escape_search();
assert($('#user-list .input-append').hasClass('notdisplayed'));
}());
});
reset_setup();
@ -742,7 +742,7 @@ reset_setup();
simulate_list_items([alice_li]);
}());
(function test_initiate_search() {
run_test('initiate_search', () => {
$('.user-list-filter').blur();
simulate_right_column_buddy_list();
activity.initiate_search();
@ -753,9 +753,9 @@ reset_setup();
activity.initiate_search();
assert.equal($('.column-left').hasClass('expanded'), true);
assert.equal($('.user-list-filter').is_focused(), true);
}());
});
(function test_toggle_filter_display() {
run_test('toggle_filter_display', () => {
activity.user_filter.toggle_filter_displayed();
assert($('#user-list .input-append').hasClass('notdisplayed'));
$('.user-list-filter').closest = function (selector) {
@ -764,16 +764,16 @@ reset_setup();
};
activity.user_filter.toggle_filter_displayed();
assert.equal($('#user-list .input-append').hasClass('notdisplayed'), false);
}());
});
(function test_searching() {
run_test('searching', () => {
$('.user-list-filter').focus();
assert.equal(activity.searching(), true);
$('.user-list-filter').blur();
assert.equal(activity.searching(), false);
}());
});
(function test_update_huddles_and_redraw() {
run_test('update_huddles_and_redraw', () => {
const value = $.create('alice-fred-value');
const count = $.create('alice-fred-count');
const pm_key = alice.user_id.toString() + "," + fred.user_id.toString();
@ -796,11 +796,11 @@ reset_setup();
assert.equal($('#group-pm-list').hasClass('show'), false);
activity.get_huddles = real_get_huddles;
activity.update_huddles = function () {};
}());
});
reset_setup();
(function test_set_user_status() {
run_test('set_user_status', () => {
const server_time = 500;
const info = {
website: {
@ -837,9 +837,9 @@ reset_setup();
assert(blueslip.get_test_logs('warn').length, 1);
assert(blueslip.get_test_logs('error').length, 1);
blueslip.clear_test_data();
}());
});
(function test_initialize() {
run_test('initialize', () => {
$.stub_selector('html', {
on: function (name, func) {
func();
@ -880,4 +880,4 @@ reset_setup();
return true;
};
activity.initialize();
}());
});

View File

@ -75,7 +75,7 @@ const message_with_emoji = {
alerted: true,
};
(function test_notifications() {
run_test('notifications', () => {
assert(!alert_words.notifies(regular_message));
assert(!alert_words.notifies(own_message));
assert(alert_words.notifies(other_message));
@ -85,9 +85,9 @@ const message_with_emoji = {
assert(alert_words.notifies(unsafe_word_message));
assert(alert_words.notifies(alert_domain_message));
assert(alert_words.notifies(message_with_emoji));
}());
});
(function test_munging() {
run_test('munging', () => {
let saved_content = regular_message.content;
alert_words.process_message(regular_message);
assert.equal(saved_content, regular_message.content);
@ -118,4 +118,4 @@ const message_with_emoji = {
alert_words.process_message(message_with_emoji);
assert.equal(message_with_emoji.content, `<p>I <img alt=":heart:" class="emoji" src="/static/generated/emoji/images/emoji/unicode/2764.png" title="heart"> <span class='alert-word'>emoji</span>!</p>`);
}());
});

View File

@ -41,7 +41,7 @@ set_global('page_params', {});
});
}());
(function test_user_ids() {
run_test('user_ids', () => {
var user_ids;
// Even though we have 1000 users, we only get the 400 active
@ -73,4 +73,4 @@ set_global('page_params', {});
user_ids = buddy_data.get_filtered_and_sorted_user_ids('');
assert.equal(user_ids.length, 700);
}());
});

View File

@ -1,7 +1,7 @@
set_global('$', global.make_zjquery());
zrequire('buddy_list');
(function test_get_items() {
run_test('get_items', () => {
const alice_li = $.create('alice stub');
const sel = 'li.user_sidebar_entry';
@ -11,4 +11,4 @@ zrequire('buddy_list');
const items = buddy_list.get_items();
assert.deepEqual(items, [alice_li]);
}());
});

View File

@ -37,7 +37,7 @@ function test_with_mock_ajax(test_params) {
}
(function test_basics() {
run_test('basics', () => {
test_with_mock_ajax({
run_code: function () {
channel.post({});
@ -114,9 +114,9 @@ function test_with_mock_ajax(test_params) {
},
});
}());
});
(function test_normal_post() {
run_test('normal_post', () => {
const data = {
s: 'some_string',
num: 7,
@ -159,9 +159,9 @@ function test_with_mock_ajax(test_params) {
assert(orig_error_called);
},
});
}());
});
(function test_patch_with_form_data() {
run_test('patch_with_form_data', () => {
let appended;
const data = {
@ -190,9 +190,9 @@ function test_with_mock_ajax(test_params) {
options.simulate_error();
},
});
}());
});
(function test_reload_on_403_error() {
run_test('reload_on_403_error', () => {
test_with_mock_ajax({
xhr: {
status: 403,
@ -219,9 +219,9 @@ function test_with_mock_ajax(test_params) {
assert(reload_initiated);
},
});
}());
});
(function test_unexpected_403_response() {
run_test('unexpected_403_response', () => {
test_with_mock_ajax({
xhr: {
status: 403,
@ -239,9 +239,9 @@ function test_with_mock_ajax(test_params) {
blueslip.clear_test_data();
},
});
}());
});
(function test_retry() {
run_test('retry', () => {
test_with_mock_ajax({
run_code: function () {
channel.post({
@ -271,9 +271,9 @@ function test_with_mock_ajax(test_params) {
blueslip.clear_test_data();
},
});
}());
});
(function test_too_many_pending() {
run_test('too_many_pending', () => {
$.ajax = function () {
const xhr = 'stub';
return xhr;
@ -287,9 +287,9 @@ function test_with_mock_ajax(test_params) {
});
assert.equal(blueslip.get_test_logs('warn').length, 1);
blueslip.clear_test_data();
}());
});
(function test_xhr_error_message() {
run_test('xhr_error_message', () => {
let xhr = {
status: '200',
responseText: 'does not matter',
@ -303,4 +303,4 @@ function test_with_mock_ajax(test_params) {
};
msg = 'some message';
assert.equal(channel.xhr_error_message(msg, xhr), 'some message: file not found');
}());
});

View File

@ -1,6 +1,6 @@
zrequire('colorspace');
(function test_sRGB_to_linear() {
run_test('sRGB_to_linear', () => {
var srgb_color = 0.0042;
var expected_value = 0.0042 / 255.0 / 12.92;
var actual_value = colorspace.sRGB_to_linear(srgb_color);
@ -10,16 +10,16 @@ zrequire('colorspace');
expected_value = 1;
actual_value = colorspace.sRGB_to_linear(srgb_color);
assert.equal(actual_value, expected_value);
}());
});
(function test_rgb_luminance() {
run_test('rgb_luminance', () => {
var channel = [1, 1, 1];
var expected_value = 1;
var actual_value = colorspace.rgb_luminance(channel);
assert.equal(actual_value, expected_value);
}());
});
(function test_luminance_to_lightness() {
run_test('luminance_to_lightness', () => {
var luminance = 0;
var expected_value = 116 * 4 / 29 - 16;
var actual_value = colorspace.luminance_to_lightness(luminance);
@ -29,9 +29,9 @@ zrequire('colorspace');
expected_value = 100;
actual_value = colorspace.luminance_to_lightness(luminance);
assert.equal(actual_value, expected_value);
}());
});
(function test_getDecimalColor() {
run_test('getDecimalColor', () => {
var hex_color = '#1f293b';
var expected_value = {
r: 31,
@ -40,9 +40,9 @@ zrequire('colorspace');
};
var actual_value = colorspace.getDecimalColor(hex_color);
assert.deepEqual(actual_value, expected_value);
}());
});
(function test_getLighterColor() {
run_test('getLighterColor', () => {
var rgb_color = {
r: 31,
g: 41,
@ -52,9 +52,9 @@ zrequire('colorspace');
var expected_value = rgb_color;
var actual_value = colorspace.getLighterColor(rgb_color, lightness);
assert.deepEqual(actual_value, expected_value);
}());
});
(function test_getHexColor() {
run_test('getHexColor', () => {
var rgb_color = {
r: 31,
g: 41,
@ -63,6 +63,6 @@ zrequire('colorspace');
var expected_value = '#1f293b';
var actual_value = colorspace.getHexColor(rgb_color);
assert.equal(actual_value, expected_value);
}());
});

View File

@ -2,7 +2,7 @@ zrequire('common');
set_global('$', global.make_zjquery());
(function test_basics() {
run_test('basics', () => {
common.autofocus('#home');
assert($('#home').is_focused());
}());
});

View File

@ -8,7 +8,7 @@ var noop = function () {};
var LEFT_KEY = { which: 37, preventDefault: noop };
var RIGHT_KEY = { which: 39, preventDefault: noop };
(function test_basics() {
run_test('basics', () => {
var keydown_f;
var click_f;
var tabs = [];
@ -197,4 +197,4 @@ var RIGHT_KEY = { which: 39, preventDefault: noop };
click_f.call(tabs[1]);
assert.equal(widget.value(), 'translated: Message formatting');
}());
});

View File

@ -89,7 +89,7 @@ people.initialize_current_user(me.user_id);
people.add(alice);
people.add(bob);
(function test_validate_stream_message_address_info() {
run_test('validate_stream_message_address_info', () => {
var sub = {
stream_id: 101,
name: 'social',
@ -143,9 +143,9 @@ people.add(bob);
};
assert(!compose.validate_stream_message_address_info('social'));
assert.equal($('#compose-error-msg').html(), i18n.t("Error checking subscription"));
}());
});
(function test_validate() {
run_test('validate', () => {
function initialize_pm_pill() {
set_global('$', global.make_zjquery());
@ -238,9 +238,9 @@ people.add(bob);
$("#subject").select(noop);
assert(!compose.validate());
assert.equal($('#compose-error-msg').html(), i18n.t('Please specify a topic'));
}());
});
(function test_get_invalid_recipient_emails() {
run_test('get_invalid_recipient_emails', () => {
var feedback_bot = {
email: 'feedback@example.com',
user_id: 124,
@ -251,9 +251,9 @@ people.add(bob);
people.initialize();
compose_state.recipient('feedback@example.com');
assert.deepEqual(compose.get_invalid_recipient_emails(), []);
}());
});
(function test_validate_stream_message() {
run_test('validate_stream_message', () => {
// This test is in kind of continuation to test_validate but since it is
// primarily used to get coverage over functions called from validate()
// we are separating it up in different test. Though their relative position
@ -294,9 +294,9 @@ people.add(bob);
assert(!$("#compose-send-status").visible());
assert.equal(compose_content, 'compose_all_everyone_stub');
assert($("#compose-all-everyone").visible());
}());
});
(function test_markdown_shortcuts() {
run_test('markdown_shortcuts', () => {
var queryCommandEnabled = true;
var event = {
keyCode: 66,
@ -452,9 +452,9 @@ people.add(bob);
// Reset userAgent
global.navigator.userAgent = "";
}());
});
(function test_send_message_success() {
run_test('send_message_success', () => {
$("#compose-textarea").val('foobarfoobar');
$("#compose-textarea").blur();
$("#compose-send-status").show();
@ -477,9 +477,9 @@ people.add(bob);
assert(!$("#sending-indicator").visible());
assert(reify_message_id_checked);
}());
});
(function test_send_message() {
run_test('send_message', () => {
// This is the common setup stuff for all of the four tests.
var stub_state;
function initialize_state_stub_dict() {
@ -631,11 +631,11 @@ people.add(bob);
assert.equal($("#compose-send-button").prop('disabled'), false);
assert(!$("#sending-indicator").visible());
}());
}());
});
set_global('document', 'document-stub');
(function test_enter_with_preview_open() {
run_test('enter_with_preview_open', () => {
// Test sending a message with content.
compose_state.set_message_type('stream');
$("#compose-textarea").val('message me');
@ -670,9 +670,9 @@ set_global('document', 'document-stub');
assert($("#enter_sends").prop("checked"));
assert.equal($("#compose-error-msg").html(), i18n.t('You have nothing to send!'));
}());
});
(function test_finish() {
run_test('finish', () => {
(function test_when_compose_validation_fails() {
$("#compose_invite_users").show();
$("#compose-send-button").prop('disabled', false);
@ -717,9 +717,9 @@ set_global('document', 'document-stub');
assert(send_message_called);
assert(compose_finished_event_checked);
}());
}());
});
(function test_abort_xhr() {
run_test('abort_xhr', () => {
$("#compose-send-button").attr('disabled', 'disabled');
var compose_removedata_checked = false;
$('#compose').removeData = function (sel) {
@ -739,7 +739,7 @@ set_global('document', 'document-stub');
assert.equal($("#compose-send-button").attr(), undefined);
assert(xhr_abort_checked);
assert(compose_removedata_checked);
}());
});
function verify_filedrop_payload(payload) {
assert.equal(payload.url, '/json/user_uploads');
@ -778,7 +778,7 @@ function test_raw_file_drop(raw_drop_func) {
assert(compose_ui_autosize_textarea_checked);
}
(function test_initialize() {
run_test('initialize', () => {
// In this test we mostly do the setup stuff in addition to testing the
// normal workflow of the function. All the tests for the on functions are
// done in subsequent tests directly below this test.
@ -861,9 +861,9 @@ function test_raw_file_drop(raw_drop_func) {
assert(compose_actions_start_checked);
}());
}());
});
(function test_update_fade() {
run_test('update_fade', () => {
var selector = '#stream,#subject,#private_message_recipient';
var keyup_handler_func = $(selector).get_on_handler('keyup');
@ -889,9 +889,9 @@ function test_raw_file_drop(raw_drop_func) {
keyup_handler_func();
assert(set_focused_recipient_checked);
assert(update_all_called);
}());
});
(function test_trigger_submit_compose_form() {
run_test('trigger_submit_compose_form', () => {
var prevent_default_checked = false;
var compose_finish_checked = false;
var e = {
@ -909,9 +909,9 @@ function test_raw_file_drop(raw_drop_func) {
assert(prevent_default_checked);
assert(compose_finish_checked);
}());
});
(function test_on_events() {
run_test('on_events', () => {
(function test_usermention_completed_zulip_triggered() {
var handler = $(document).get_on_handler('usermention_completed.zulip');
@ -1429,9 +1429,9 @@ function test_raw_file_drop(raw_drop_func) {
assert($("#markdown_preview").visible());
}());
}());
});
(function test_create_message_object() {
run_test('create_message_object', () => {
var sub = {
stream_id: 101,
name: 'social',
@ -1479,4 +1479,4 @@ function test_raw_file_drop(raw_drop_func) {
assert.equal(message.to_user_ids, '31,32');
assert.equal(message.content, 'burrito');
}());
});

View File

@ -92,13 +92,13 @@ function assert_hidden(sel) {
assert(!$(sel).visible());
}
(function test_initial_state() {
run_test('initial_state', () => {
assert.equal(compose_state.composing(), false);
assert.equal(compose_state.get_message_type(), false);
assert.equal(compose_state.has_message_content(), false);
}());
});
(function test_start() {
run_test('start', () => {
compose_actions.autosize_message_content = noop;
compose_actions.expand_compose_box = noop;
compose_actions.set_focus = noop;
@ -160,9 +160,9 @@ function assert_hidden(sel) {
assert_visible('#compose_controls');
assert_hidden('#private-message');
assert(!compose_state.composing());
}());
});
(function test_respond_to_message() {
run_test('respond_to_message', () => {
// Test PM
var person = {
user_id: 22,
@ -198,9 +198,9 @@ function assert_hidden(sel) {
respond_to_message(opts);
assert.equal($('#stream').val(), 'devel');
}());
});
(function test_reply_with_mention() {
run_test('reply_with_mention', () => {
var msg = {
type: 'stream',
stream: 'devel',
@ -222,9 +222,9 @@ function assert_hidden(sel) {
assert.equal($('#stream').val(), 'devel');
assert.equal(syntax_to_insert, '@**Bob Roberts**');
assert(compose_state.has_message_content());
}());
});
(function test_get_focus_area() {
run_test('get_focus_area', () => {
assert.equal(get_focus_area('private', {}), 'private_message_recipient');
assert.equal(get_focus_area('private', {
private_message_recipient: 'bob@example.com'}), 'compose-textarea');
@ -238,9 +238,9 @@ function assert_hidden(sel) {
subject: 'more',
trigger: 'new topic button'}),
'subject');
}());
});
(function test_focus_in_empty_compose() {
run_test('focus_in_empty_compose', () => {
$('#compose-textarea').is = function (attr) {
assert.equal(attr, ':focus');
return $('#compose-textarea').is_focused;
@ -259,4 +259,4 @@ function assert_hidden(sel) {
$('#compose-textarea').blur();
assert(!compose_state.focus_in_empty_compose());
}());
});

View File

@ -31,7 +31,7 @@ people.add_in_realm(alice);
people.add_in_realm(bob);
(function test_set_focused_recipient() {
run_test('set_focused_recipient', () => {
var sub = {
stream_id: 101,
name: 'social',
@ -77,4 +77,4 @@ people.add_in_realm(bob);
};
assert(!compose_fade.should_fade_message(good_msg));
assert(compose_fade.should_fade_message(bad_msg));
}());
});

View File

@ -8,7 +8,7 @@ var pills = {
pill: {},
};
(function test_pills() {
run_test('pills', () => {
var othello = {
user_id: 1,
email: 'othello@example.com',
@ -141,4 +141,4 @@ var pills = {
assert(pills_cleared);
assert(appendValue_called);
assert(text_cleared);
}());
});

View File

@ -54,7 +54,7 @@ function make_textbox(s) {
return widget;
}
(function test_insert_syntax_and_focus() {
run_test('insert_syntax_and_focus', () => {
blueslip.error = noop;
blueslip.log = noop;
$('#compose-textarea').val("xyz ");
@ -70,9 +70,9 @@ function make_textbox(s) {
assert.equal($('#compose-textarea').val(), 'xyz :octopus: ');
assert($("#compose-textarea").is_focused());
}());
});
(function test_smart_insert() {
run_test('smart_insert', () => {
var textbox = make_textbox('abc');
textbox.caret(4);
@ -105,5 +105,5 @@ function make_textbox(s) {
// Note that we don't have any special logic for strings that are
// already surrounded by spaces, since we are usually inserting things
// like emojis and file links.
}());
});

View File

@ -174,7 +174,7 @@ user_pill.get_user_ids = function () {
return [];
};
(function test_add_topic() {
run_test('add_topic', () => {
ct.add_topic('Denmark', 'civil fears');
ct.add_topic('devel', 'fading');
ct.add_topic('denmark', 'acceptance');
@ -185,14 +185,14 @@ user_pill.get_user_ids = function () {
ct.topics_seen_for('Denmark'),
['With Twisted Metal', 'acceptance', 'civil fears']
);
}());
});
(function test_topics_seen_for() {
run_test('topics_seen_for', () => {
// Test when the stream doesn't exist (there are no topics)
assert.deepEqual(ct.topics_seen_for('non-existing-stream'), []);
}());
});
(function test_content_typeahead_selected() {
run_test('content_typeahead_selected', () => {
var fake_this = {
query: '',
$element: {},
@ -355,9 +355,9 @@ user_pill.get_user_ids = function () {
assert(document_stub_trigger1_called);
assert(document_stub_group_trigger_called);
assert(document_stub_trigger2_called);
}());
});
(function test_initialize() {
run_test('initialize', () => {
var stream_typeahead_called = false;
$('#stream').typeahead = function (options) {
// options.source()
@ -908,9 +908,9 @@ user_pill.get_user_ids = function () {
assert(compose_textarea_typeahead_called);
assert(focus_handler_called);
assert(stream_one_called);
}());
});
(function test_begins_typeahead() {
run_test('begins_typeahead', () => {
var begin_typehead_this = {options: {completions: {
emoji: true, mention: true, stream: true, syntax: true}}};
@ -1050,9 +1050,9 @@ user_pill.get_user_ids = function () {
assert_typeahead_equals("```test", symbol, lang_list);
assert_typeahead_equals("~~~test", symbol, lang_list);
});
}());
});
(function test_tokenizing() {
run_test('tokenizing', () => {
assert.equal(ct.tokenize_compose_str("foo bar"), "");
assert.equal(ct.tokenize_compose_str("foo#@:bar"), "");
assert.equal(ct.tokenize_compose_str("foo bar [#alic"), "#alic");
@ -1071,9 +1071,9 @@ user_pill.get_user_ids = function () {
assert.equal(ct.tokenize_compose_str(
"foo @toomanycharactersisridiculoustocomplete"), "");
assert.equal(ct.tokenize_compose_str("foo #streams@foo"), "#streams@foo");
}());
});
(function test_content_highlighter() {
run_test('content_highlighter', () => {
var fake_this = { completing: 'emoji' };
var emoji = { emoji_name: 'person shrugging', emoji_url: '¯\_(ツ)_/¯' };
var th_render_typeahead_item_called = false;
@ -1123,9 +1123,9 @@ user_pill.get_user_ids = function () {
assert(th_render_user_group_called);
assert(th_render_stream_called);
assert(th_render_typeahead_item_called);
}());
});
(function test_typeahead_results() {
run_test('typeahead_results', () => {
var all_items = _.map(['all', 'everyone', 'stream'], function (mention) {
return {
special_item_text: 'translated: ' + mention +" (Notify stream)",
@ -1198,4 +1198,4 @@ user_pill.get_user_ids = function () {
assert_stream_matches('cold', [sweden_stream, denmark_stream]);
assert_stream_matches('the ', [netherland_stream]);
assert_stream_matches('city', [netherland_stream]);
}());
});

View File

@ -12,7 +12,7 @@ global.$ = require('jquery')(window);
zrequire('toMarkdown', 'node_modules/to-markdown/dist/to-markdown.js');
var copy_and_paste = zrequire('copy_and_paste');
(function test_paste_handler() {
run_test('paste_handler', () => {
var input = '<meta http-equiv="content-type" content="text/html; charset=utf-8"><span style="color: rgb(34, 34, 34); font-family: arial, sans-serif; font-size: 12.8px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); text-decoration-style: initial; text-decoration-color: initial;"><span> </span>love the<span> </span><b>Zulip</b><b> </b></span><b style="color: rgb(34, 34, 34); font-family: arial, sans-serif; font-size: 12.8px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); text-decoration-style: initial; text-decoration-color: initial;">Organization</b><span style="color: rgb(34, 34, 34); font-family: arial, sans-serif; font-size: 12.8px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); text-decoration-style: initial; text-decoration-color: initial;">.</span>';
assert.equal(copy_and_paste.paste_handler_converter(input),
@ -49,4 +49,4 @@ var copy_and_paste = zrequire('copy_and_paste');
input = '<div class="ace-line gutter-author-d-iz88z86z86za0dz67zz78zz78zz74zz68zjz80zz71z9iz90za3z66zs0z65zz65zq8z75zlaz81zcz66zj6g2mz78zz76zmz66z22z75zfcz69zz66z ace-ltr focused-line" dir="auto" id="editor-3-ace-line-41"><span>Test List:</span></div><div class="ace-line gutter-author-d-iz88z86z86za0dz67zz78zz78zz74zz68zjz80zz71z9iz90za3z66zs0z65zz65zq8z75zlaz81zcz66zj6g2mz78zz76zmz66z22z75zfcz69zz66z line-list-type-bullet ace-ltr" dir="auto" id="editor-3-ace-line-42"><ul class="listtype-bullet listindent1 list-bullet1"><li><span class="ace-line-pocket-zws" data-faketext="" data-contentcollector-ignore-space-at="end"></span><span class="ace-line-pocket" data-faketext="" contenteditable="false"></span><span class="ace-line-pocket-zws" data-faketext="" data-contentcollector-ignore-space-at="start"></span><span>Item 1</span></li></ul></div><div class="ace-line gutter-author-d-iz88z86z86za0dz67zz78zz78zz74zz68zjz80zz71z9iz90za3z66zs0z65zz65zq8z75zlaz81zcz66zj6g2mz78zz76zmz66z22z75zfcz69zz66z line-list-type-bullet ace-ltr" dir="auto" id="editor-3-ace-line-43"><ul class="listtype-bullet listindent1 list-bullet1"><li><span class="ace-line-pocket-zws" data-faketext="" data-contentcollector-ignore-space-at="end"></span><span class="ace-line-pocket" data-faketext="" contenteditable="false"></span><span class="ace-line-pocket-zws" data-faketext="" data-contentcollector-ignore-space-at="start"></span><span>Item 2</span></li></ul></div>';
assert.equal(copy_and_paste.paste_handler_converter(input),
'Test List:\n* Item 1\n* Item 2');
}());
});

View File

@ -1,6 +1,6 @@
set_global('blueslip', global.make_zblueslip());
(function test_basic() {
run_test('basic', () => {
var d = new Dict();
assert(d.is_empty());
@ -34,9 +34,9 @@ set_global('blueslip', global.make_zblueslip());
var val = ['foo'];
var res = d.set('abc', val);
assert.equal(val, res);
}());
});
(function test_fold_case() {
run_test('fold_case', () => {
var d = new Dict({fold_case: true});
assert.deepEqual(d.keys(), []);
@ -54,9 +54,9 @@ set_global('blueslip', global.make_zblueslip());
assert.equal(d.has('foo'), false);
assert.deepEqual(d.keys(), []);
}());
});
(function test_undefined_keys() {
run_test('undefined_keys', () => {
blueslip.set_test_data('error', 'Tried to call a Dict method with an undefined key.');
var d = new Dict();
@ -71,9 +71,9 @@ set_global('blueslip', global.make_zblueslip());
assert.equal(blueslip.get_test_logs('error').length, 4);
blueslip.clear_test_data();
}());
});
(function test_restricted_keys() {
run_test('restricted_keys', () => {
var d = new Dict();
assert.equal(d.has('__proto__'), false);
@ -90,9 +90,9 @@ set_global('blueslip', global.make_zblueslip());
d.set('__proto__', 'foo');
d.set('foo', 'bar');
assert.equal(d.get('foo'), 'bar');
}());
});
(function test_construction() {
run_test('construction', () => {
var d1 = new Dict();
assert.deepEqual(d1.items(), []);
@ -125,9 +125,9 @@ set_global('blueslip', global.make_zblueslip());
assert.equal(e2.toString(), 'TypeError: Argument is not an array');
}
assert(caught);
}());
});
(function test_each() {
run_test('each', () => {
var d = new Dict();
d.set('apple', 40);
d.set('banana', 50);
@ -144,9 +144,9 @@ set_global('blueslip', global.make_zblueslip());
assert.equal(cnt, d.keys().length);
assert.equal(unseen_keys.length, 0);
}());
});
(function test_setdefault() {
run_test('setdefault', () => {
var d = new Dict();
var val = ['foo'];
var res = d.setdefault('foo', val);
@ -158,9 +158,9 @@ set_global('blueslip', global.make_zblueslip());
res = d.setdefault('foo', val2);
assert.equal(res, val);
assert.equal(d.get('foo'), val);
}());
});
(function test_num_items() {
run_test('num_items', () => {
var d = new Dict();
assert.equal(d.num_items(), 0);
assert(d.is_empty());
@ -177,9 +177,9 @@ set_global('blueslip', global.make_zblueslip());
assert.equal(d.num_items(), 2);
d.del('foo');
assert.equal(d.num_items(), 1);
}());
});
(function test_clear() {
run_test('clear', () => {
var d = new Dict();
function populate() {
@ -202,4 +202,4 @@ set_global('blueslip', global.make_zblueslip());
// make sure it still works after clearing
populate();
assert.equal(d.num_items(), 2);
}());
});

View File

@ -73,7 +73,7 @@ var draft_2 = {
content: "Test Private Message",
};
(function test_draft_model() {
run_test('draft_model', () => {
var draft_model = drafts.draft_model;
var ls = localstorage();
@ -123,9 +123,9 @@ var draft_2 = {
assert.deepEqual(ls.get("drafts"), {});
}());
}());
});
(function test_snapshot_message() {
run_test('snapshot_message', () => {
function stub_draft(draft) {
global.compose_state.get_message_type = function () {
return draft.type;
@ -155,9 +155,9 @@ var draft_2 = {
stub_draft({});
assert.equal(drafts.snapshot_message(), undefined);
}());
});
(function test_initialize() {
run_test('initialize', () => {
var message_content = $("#compose-textarea");
message_content.focusout = function (f) {
assert.equal(f, drafts.update_draft);
@ -173,9 +173,9 @@ var draft_2 = {
};
drafts.initialize();
}());
});
(function test_remove_old_drafts() {
run_test('remove_old_drafts', () => {
var draft_3 = {
stream: "stream",
subject: "topic",
@ -199,9 +199,9 @@ var draft_2 = {
drafts.remove_old_drafts();
assert.deepEqual(draft_model.get(), {id3: draft_3});
}());
});
(function test_format_drafts() {
run_test('format_drafts', () => {
draft_1.updatedAt = new Date(1549958107000).getTime(); // 2/12/2019 07:55:07 AM (UTC+0)
draft_2.updatedAt = new Date(1549958107000).setDate(-1);
var draft_3 = {
@ -292,4 +292,4 @@ var draft_2 = {
drafts.setup_page();
timerender.render_now = stub_render_now;
}());
});

View File

@ -10,7 +10,7 @@ zrequire('emoji');
zrequire('markdown');
zrequire('util');
(function test_build_emoji_upload_widget() {
run_test('build_emoji_upload_widget', () => {
var build_widget_stub = false;
upload_widget.build_widget = function (
get_file_input,
@ -28,9 +28,9 @@ zrequire('util');
};
emoji.build_emoji_upload_widget();
assert(build_widget_stub);
}());
});
(function test_initialize() {
run_test('initialize', () => {
var image_stub = false;
class Image {
set src(data) {
@ -41,9 +41,9 @@ zrequire('util');
set_global('Image', Image);
emoji.initialize();
assert(image_stub);
}());
});
(function test_get_canonical_name() {
run_test('get_canonical_name', () => {
emoji.active_realm_emojis = {
realm_emoji: 'TBD',
};
@ -71,9 +71,9 @@ zrequire('util');
emoji.get_canonical_name('non_existent');
assert.equal(blueslip.get_test_logs('error').length, 1);
blueslip.clear_test_data();
}());
});
(function test_translate_emoticons_to_names() {
run_test('translate_emoticons_to_names', () => {
// Simple test
var test_text = 'Testing :)';
var expected = 'Testing :smiley:';
@ -107,4 +107,4 @@ zrequire('util');
assert.equal(result, expected);
});
});
}());
});

View File

@ -2,7 +2,7 @@ zrequire('emoji_codes', 'generated/emoji/emoji_codes');
zrequire('emoji');
zrequire('emoji_picker');
(function test_initialize() {
run_test('initialize', () => {
emoji.update_emojis({});
emoji_picker.initialize();
@ -33,4 +33,4 @@ zrequire('emoji_picker');
assert_emoji_category(complete_emoji_catalog.pop(), 'fa-cutlery', 85);
assert_emoji_category(complete_emoji_catalog.pop(), 'fa-cog', 1);
assert_emoji_category(complete_emoji_catalog.pop(), 'fa-soccer-ball-o', 67);
}());
});

View File

@ -30,7 +30,7 @@ function has_not_found_newest() {
assert.equal(fetch_status.has_found_newest(), false);
}
(function test_basics() {
run_test('basics', () => {
reset();
fetch_status.start_initial_narrow();
@ -119,4 +119,4 @@ function has_not_found_newest() {
can_load_older();
blocked_newer();
}());
});

View File

@ -49,7 +49,7 @@ function assert_same_operators(result, terms) {
assert.deepEqual(result, terms);
}
(function test_basics() {
run_test('basics', () => {
var operators = [
{operator: 'stream', operand: 'foo'},
{operator: 'stream', operand: 'exclude_stream', negated: true},
@ -107,9 +107,9 @@ function assert_same_operators(result, terms) {
filter = new Filter(operators);
assert(filter.has_operator('has'));
assert(!filter.can_apply_locally());
}());
});
(function test_topic_stuff() {
run_test('topic_stuff', () => {
var operators = [
{operator: 'stream', operand: 'foo'},
{operator: 'topic', operand: 'old topic'},
@ -124,9 +124,9 @@ function assert_same_operators(result, terms) {
assert.deepEqual(new_filter.operands('stream'), ['foo']);
assert.deepEqual(new_filter.operands('topic'), ['new topic']);
}());
});
(function test_new_style_operators() {
run_test('new_style_operators', () => {
var term = {
operator: 'stream',
operand: 'foo',
@ -136,9 +136,9 @@ function assert_same_operators(result, terms) {
assert.deepEqual(filter.operands('stream'), ['foo']);
assert(filter.is_exactly('stream'));
}());
});
(function test_public_operators() {
run_test('public_operators', () => {
var operators = [
{operator: 'stream', operand: 'foo'},
{operator: 'in', operand: 'all'},
@ -155,9 +155,9 @@ function assert_same_operators(result, terms) {
];
filter = new Filter(operators);
assert_same_operators(filter.public_operators(), []);
}());
});
(function test_canonicalizations() {
run_test('canonicalizations', () => {
assert.equal(Filter.canonicalize_operator('Is'), 'is');
assert.equal(Filter.canonicalize_operator('Stream'), 'stream');
assert.equal(Filter.canonicalize_operator('Subject'), 'topic');
@ -203,7 +203,7 @@ function assert_same_operators(result, terms) {
assert.equal(term.operator, 'has');
assert.equal(term.operand, 'link');
}());
});
function get_predicate(operators) {
operators = _.map(operators, function (op) {
@ -220,7 +220,7 @@ function make_sub(name, stream_id) {
global.stream_data.add_sub(name, sub);
}
(function test_predicate_basics() {
run_test('predicate_basics', () => {
// Predicates are functions that accept a message object with the message
// attributes (not content), and return true if the message belongs in a
// given narrow. If the narrow parameters include a search, the predicate
@ -350,9 +350,9 @@ function make_sub(name, stream_id) {
display_recipient: [{id: steve.user_id}, {id: me.user_id}],
}));
assert(!predicate({type: 'stream'}));
}());
});
(function test_negated_predicates() {
run_test('negated_predicates', () => {
var predicate;
var narrow;
@ -365,9 +365,9 @@ function make_sub(name, stream_id) {
predicate = new Filter(narrow).predicate();
assert(predicate({type: 'stream', stream_id: 999999}));
assert(!predicate({type: 'stream', stream_id: social_stream_id}));
}());
});
(function test_mit_exceptions() {
run_test('mit_exceptions', () => {
global.page_params.realm_is_zephyr_mirror_realm = true;
var predicate = get_predicate([['stream', 'Foo'], ['topic', 'personal']]);
@ -396,9 +396,9 @@ function make_sub(name, stream_id) {
];
predicate = new Filter(terms).predicate();
assert(!predicate({type: 'stream', stream: 'foo', subject: 'bar'}));
}());
});
(function test_predicate_edge_cases() {
run_test('predicate_edge_cases', () => {
var predicate;
// The code supports undefined as an operator to Filter, which results
// in a predicate that accepts any message.
@ -427,9 +427,9 @@ function make_sub(name, stream_id) {
predicate = filter.predicate(); // get cached version
assert(predicate({type: 'stream', stream: 'foo', subject: 'bar'}));
}());
});
(function test_parse() {
run_test('parse', () => {
var string;
var operators;
@ -535,9 +535,9 @@ function make_sub(name, stream_id) {
{operator: 'topic', operand: 'with space'},
];
_test();
}());
});
(function test_unparse() {
run_test('unparse', () => {
var string;
var operators;
@ -566,9 +566,9 @@ function make_sub(name, stream_id) {
];
string = '';
assert.deepEqual(Filter.unparse(operators), string);
}());
});
(function test_describe() {
run_test('describe', () => {
var narrow;
var string;
@ -668,9 +668,9 @@ function make_sub(name, stream_id) {
narrow = [];
string = 'all messages';
assert.equal(Filter.describe(narrow), string);
}());
});
(function test_is_functions() {
run_test('is_functions', () => {
var terms = [
{operator: 'stream', operand: 'My Stream'},
];
@ -756,9 +756,9 @@ function make_sub(name, stream_id) {
filter = new Filter(terms);
assert.equal(filter.is_exactly('is-mentioned'), false);
assert.equal(filter.is_exactly('is-private'), false);
}());
});
(function test_term_type() {
run_test('term_type', () => {
function assert_term_type(term, expected_term_type) {
assert.equal(Filter.term_type(term), expected_term_type);
}
@ -811,9 +811,9 @@ function make_sub(name, stream_id) {
const term_types = filter.sorted_term_types();
assert.deepEqual(term_types, ['stream', 'topic', 'sender']);
}());
});
(function test_first_valid_id_from() {
run_test('first_valid_id_from', () => {
const terms = [
{operator: 'is', operand: 'alerted'},
];
@ -837,9 +837,9 @@ function make_sub(name, stream_id) {
message_store.get = (msg_id) => messages[msg_id];
assert.equal(filter.first_valid_id_from(msg_ids), 20);
}());
});
(function test_update_email() {
run_test('update_email', () => {
var terms = [
{operator: 'pm-with', operand: 'steve@foo.com'},
{operator: 'sender', operand: 'steve@foo.com'},
@ -850,14 +850,14 @@ function make_sub(name, stream_id) {
assert.deepEqual(filter.operands('pm-with'), ['showell@foo.com']);
assert.deepEqual(filter.operands('sender'), ['showell@foo.com']);
assert.deepEqual(filter.operands('stream'), ['steve@foo.com']);
}());
});
(function test_error_cases() {
run_test('error_cases', () => {
// This test just gives us 100% line coverage on defensive code that
// should not be reached unless we break other code.
people.pm_with_user_ids = function () {};
var predicate = get_predicate([['pm-with', 'Joe@example.com']]);
assert(!predicate({type: 'private'}));
}());
});

View File

@ -56,12 +56,12 @@ const denmark_stream = {
zrequire('stream_data');
(function test_stream_data() {
run_test('stream_data', () => {
assert.equal(stream_data.get_sub_by_name('Denmark'), undefined);
stream_data.add_sub('Denmark', denmark_stream);
const sub = stream_data.get_sub_by_name('Denmark');
assert.equal(sub.color, 'blue');
}());
});
// Hopefully the basic patterns for testing data-oriented modules
// are starting to become apparent. To reinforce that, we will present
@ -101,7 +101,7 @@ zrequire('topic_data');
// And finally require the module that we will test directly:
zrequire('message_store');
(function test_message_store() {
run_test('message_store', () => {
// Our test runner automatically sets _ for us.
// See http://underscorejs.org/ for help on that library.
var in_message = _.clone(messages.isaac_to_denmark_stream);
@ -120,13 +120,13 @@ zrequire('message_store');
// There are more side effects.
const topic_names = topic_data.get_recent_names(denmark_stream.stream_id);
assert.deepEqual(topic_names, ['copenhagen']);
}());
});
// Tracking unread messages is a very fundamental part of the Zulip
// app, and we use the unread object to track unread messages.
zrequire('unread');
(function test_unread() {
run_test('unread', () => {
const stream_id = denmark_stream.stream_id;
const topic_name = 'copenhagen';
@ -137,7 +137,7 @@ zrequire('unread');
unread.process_loaded_messages([in_message]);
assert.equal(unread.num_unread_for_topic(stream_id, topic_name), 1);
}());
});
// In the Zulip app you can narrow your message stream by topic, by
// sender, by PM recipient, by search keywords, etc. We will discuss
@ -155,7 +155,7 @@ set_global('page_params', {});
// Filter class.
zrequire('Filter', 'js/filter');
(function test_filter() {
run_test('filter', () => {
const filter_terms = [
{operator: 'stream', operand: 'Denmark'},
{operator: 'topic', operand: 'copenhagen'},
@ -181,7 +181,7 @@ zrequire('Filter', 'js/filter');
stream_id: denmark_stream.stream_id,
subject: 'copenhagen',
}), true);
}());
});
// We have a "narrow" abstraction that sits roughly on top of the
// "filter" abstraction. If you are in a narrow, we track the
@ -189,7 +189,7 @@ zrequire('Filter', 'js/filter');
zrequire('narrow_state');
(function test_narrow_state() {
run_test('narrow_state', () => {
// As we often do, first make assertions about the starting
// state:
@ -207,7 +207,7 @@ zrequire('narrow_state');
assert.equal(narrow_state.stream(), 'Denmark');
assert.equal(narrow_state.topic(), 'copenhagen');
}());
});
/*
@ -295,7 +295,7 @@ const bob = {
full_name: 'Bob Roberts',
};
(function test_add_user_event() {
run_test('add_user_event', () => {
const event = {
type: 'realm_user',
op: 'add',
@ -305,7 +305,7 @@ const bob = {
assert(!people.is_known_user_id(bob.user_id));
server_events_dispatch.dispatch_normal_event(event);
assert(people.is_known_user_id(bob.user_id));
}());
});
/*
@ -328,7 +328,7 @@ set_global('settings_users', {});
zrequire('user_events');
(function test_update_user_event() {
run_test('update_user_event', () => {
const new_bob = {
email: 'bob@example.com',
user_id: bob.user_id,
@ -356,7 +356,7 @@ zrequire('user_events');
// Verify that the code actually did its main job:
assert.equal(user.full_name, 'The Artist Formerly Known as Bob');
}());
});
/*
@ -413,7 +413,7 @@ set_global('unread_ui', {});
zrequire('message_events');
(function test_insert_message() {
run_test('insert_message', () => {
const helper = test_helper();
const new_message = {
@ -458,7 +458,7 @@ zrequire('message_events');
const inserted_message = message_store.get(new_message.id);
assert.equal(inserted_message.id, new_message.id);
assert.equal(inserted_message.content, 'example content');
}());
});
/*
@ -504,7 +504,7 @@ zrequire('message_flags');
zrequire('unread_ops');
(function test_unread_ops() {
run_test('unread_ops', () => {
(function set_up() {
const test_messages = [
{
@ -555,7 +555,7 @@ zrequire('unread_ops');
data: { messages: '[50]', op: 'add', flag: 'read' },
success: channel_post_opts.success,
});
}());
});
/*
@ -706,7 +706,7 @@ function make_sidebar_helper() {
};
}
(function test_stream_list() {
run_test('stream_list', () => {
const jquery_helper = make_jquery_helper();
const sidebar_helper = make_sidebar_helper();
const topic_list_helper = make_topic_list_helper();
@ -724,4 +724,4 @@ function make_sidebar_helper() {
jquery_helper.verify_actions();
sidebar_helper.verify_actions();
topic_list_helper.verify_actions();
}());
});

View File

@ -17,7 +17,7 @@ var sub = {
stream_data.add_sub(sub.name, sub);
(function test_hash_util() {
run_test('hash_util', () => {
// Test encodeHashComponent
var str = 'https://www.zulipexample.com';
var result1 = hash_util.encodeHashComponent(str);
@ -51,4 +51,4 @@ stream_data.add_sub(sub.name, sub);
operand = 'testing 123';
encode_decode_operand(operator, operand, 'testing.20123');
}());
});

View File

@ -33,7 +33,7 @@ set_global('blueslip', {
wrap_function: blueslip_wrap,
});
(function test_operators_round_trip() {
run_test('operators_round_trip', () => {
var operators;
var hash;
var narrow;
@ -79,9 +79,9 @@ set_global('blueslip', {
assert.deepEqual(narrow, [
{operator: 'stream', operand: 'Florida, USA', negated: false},
]);
}());
});
(function test_people_slugs() {
run_test('people_slugs', () => {
var operators;
var hash;
var narrow;
@ -108,7 +108,7 @@ set_global('blueslip', {
];
hash = hashchange.operators_to_hash(operators);
assert.equal(hash, '#narrow/pm-with/42-alice');
}());
});
function stub_trigger(f) {
set_global('$', () => {
@ -169,7 +169,7 @@ function test_helper() {
};
}
(function test_hash_interactions() {
run_test('hash_interactions', () => {
var helper = test_helper();
window.location.hash = '#';
@ -301,9 +301,9 @@ function test_helper() {
]);
assert(called_back);
}());
});
(function test_save_narrow() {
run_test('save_narrow', () => {
var helper = test_helper();
var operators = [
@ -333,5 +333,5 @@ function test_helper() {
'favicon.reset',
]);
assert.equal(url_pushed, 'http://example.com/#narrow/is/starred');
}());
});

View File

@ -62,7 +62,7 @@ function stubbing(func_name_to_stub, test_function) {
});
}
(function test_mappings() {
run_test('mappings', () => {
function map_press(which, shiftKey) {
return hotkey.get_keypress_hotkey({
which: which,
@ -130,9 +130,9 @@ function stubbing(func_name_to_stub, test_function) {
// Reset userAgent
global.navigator.userAgent = '';
}());
});
(function test_basic_chars() {
run_test('basic_chars', () => {
function process(s) {
var e = {
which: s.charCodeAt(0),
@ -307,9 +307,9 @@ function stubbing(func_name_to_stub, test_function) {
global.current_msg_list.empty = return_false;
}());
});
(function test_motion_keys() {
run_test('motion_keys', () => {
var codes = {
down_arrow: 40,
end: 35,
@ -418,4 +418,4 @@ function stubbing(func_name_to_stub, test_function) {
assert_mapping('down_arrow', 'drafts.drafts_handle_events');
overlays.is_active = return_false;
overlays.drafts_open = return_false;
}());
});

View File

@ -20,7 +20,7 @@ i18n.init({
},
});
(function test_t_tag() {
run_test('t_tag', () => {
var args = {
message: {
is_stream: true,
@ -37,9 +37,9 @@ i18n.init({
var html = global.render_template('actions_popover_content', args);
assert(html.indexOf("French translation") > 0);
}());
});
(function test_tr_tag() {
run_test('tr_tag', () => {
var args = {
page_params: {
full_name: "John Doe",
@ -61,4 +61,4 @@ i18n.init({
var html = global.render_template('settings_tab', args);
assert(html.indexOf('Some French text with Zulip') > 0);
}());
});

View File

@ -35,7 +35,7 @@ function pill_html(value, data_id) {
return templates.render('input_pill', opts);
}
(function test_basics() {
run_test('basics', () => {
var config = {};
blueslip.set_test_data('error', 'Pill needs container.');
@ -79,9 +79,9 @@ function pill_html(value, data_id) {
assert(inserted_before);
assert.deepEqual(widget.items(), [item]);
}());
});
(function test_insert_remove() {
run_test('insert_remove', () => {
set_global('$', global.make_zjquery());
var items = {
blue: {
@ -176,4 +176,4 @@ function pill_html(value, data_id) {
items.blue,
items.red,
]);
}());
});

View File

@ -120,7 +120,7 @@ function div(item) {
return '<div>' + item + '</div>';
}
(function test_list_render() {
run_test('list_render', () => {
const {container, parent_container} = make_containers();
const search_input = make_search_input();
@ -183,7 +183,7 @@ function div(item) {
widget.render();
expected_html = '<div>greta</div><div>gary</div>';
assert.deepEqual(container.appended_data.html(), expected_html);
}());
});
function sort_button(opts) {
// The complications here are due to needing to find
@ -237,7 +237,7 @@ function sort_button(opts) {
return button;
}
(function test_sorting() {
run_test('sorting', () => {
const {container} = make_containers();
var cleared;
@ -309,4 +309,4 @@ function sort_button(opts) {
expected_html = html_for([dave, cal, bob, alice]);
assert.deepEqual(container.appended_data.html(), expected_html);
}());
});

View File

@ -135,18 +135,18 @@ stream_data.add_sub('Bobby <h1>Tables</h1>', edgecase_stream);
// Check the default behavior of fenced code blocks
// works properly before markdown is initialized.
(function test_fenced_block_defaults() {
run_test('fenced_block_defaults', () => {
var input = '\n```\nfenced code\n```\n\nand then after\n';
var expected = '\n\n<div class="codehilite"><pre><span></span>fenced code\n</pre></div>\n\n\n\nand then after\n\n';
var output = fenced_code.process_fenced_code(input);
assert.equal(output, expected);
}());
});
markdown.initialize();
var bugdown_data = global.read_fixture_data('markdown_test_cases.json');
(function test_bugdown_detection() {
run_test('bugdown_detection', () => {
var no_markup = [
"This is a plaintext message",
"This is a plaintext: message",
@ -192,9 +192,9 @@ var bugdown_data = global.read_fixture_data('markdown_test_cases.json');
markup.forEach(function (content) {
assert.equal(markdown.contains_backend_only_syntax(content), true);
});
}());
});
(function test_marked_shared() {
run_test('marked_shared', () => {
var tests = bugdown_data.regular_tests;
tests.forEach(function (test) {
@ -218,9 +218,9 @@ var bugdown_data = global.read_fixture_data('markdown_test_cases.json');
global.bugdown_assert.equal(test.expected_output, output, error_message);
}
});
}());
});
(function test_message_flags() {
run_test('message_flags', () => {
var message = {raw_content: '@**Leo**'};
markdown.apply_markdown(message);
assert(!message.mentioned);
@ -235,9 +235,9 @@ var bugdown_data = global.read_fixture_data('markdown_test_cases.json');
markdown.apply_markdown(message);
assert(message.mentioned);
assert(!message.mentioned_me_directly);
}());
});
(function test_marked() {
run_test('marked', () => {
var test_cases = [
{input: 'hello', expected: '<p>hello</p>'},
{input: 'hello there', expected: '<p>hello there</p>'},
@ -359,9 +359,9 @@ var bugdown_data = global.read_fixture_data('markdown_test_cases.json');
var output = message.content;
assert.equal(expected, output);
});
}());
});
(function test_subject_links() {
run_test('subject_links', () => {
var message = {type: 'stream', subject: "No links here"};
markdown.add_subject_links(message);
assert.equal(message.subject_links.length, []);
@ -396,9 +396,9 @@ var bugdown_data = global.read_fixture_data('markdown_test_cases.json');
message = {type: "not-stream"};
markdown.add_subject_links(message);
assert.equal(message.subject_links.length, 0);
}());
});
(function test_message_flags() {
run_test('message_flags', () => {
var input = "/me is testing this";
var message = {subject: "No links here", raw_content: input};
markdown.apply_markdown(message);
@ -468,9 +468,9 @@ var bugdown_data = global.read_fixture_data('markdown_test_cases.json');
message = {subject: "No links here", raw_content: input};
markdown.apply_markdown(message);
assert.equal(message.mentioned, false);
}());
});
(function test_backend_only_realm_filters() {
run_test('backend_only_realm_filters', () => {
var backend_only_realm_filters = [
'Here is the PR-#123.',
'Function abc() was introduced in (PR)#123.',
@ -478,22 +478,22 @@ var bugdown_data = global.read_fixture_data('markdown_test_cases.json');
backend_only_realm_filters.forEach(function (content) {
assert.equal(markdown.contains_backend_only_syntax(content), true);
});
}());
});
(function test_python_to_js_filter() {
run_test('python_to_js_filter', () => {
// The only way to reach python_to_js_filter is indirectly, hence the call
// to set_realm_filters.
markdown.set_realm_filters([['/a(?im)a/g'], ['/a(?L)a/g']]);
var actual_value = (marked.InlineLexer.rules.zulip.realm_filters);
var expected_value = [/\/aa\/g(?![\w])/gim, /\/aa\/g(?![\w])/g];
assert.deepEqual(actual_value, expected_value);
}());
});
(function test_katex_throws_unexpected_exceptions() {
run_test('katex_throws_unexpected_exceptions', () => {
katex.renderToString = function () { throw new Error('some-exception'); };
blueslip.set_test_data('error', 'Error: some-exception');
var message = { raw_content: '$$a$$' };
markdown.apply_markdown(message);
assert(blueslip.get_test_logs('error').length, 1);
blueslip.clear_test_data();
}());
});

View File

@ -9,7 +9,7 @@ zrequire('message_edit');
var get_editability = message_edit.get_editability;
var editability_types = message_edit.editability_types;
(function test_get_editability() {
run_test('get_editability', () => {
// You can't edit a null message
assert.equal(get_editability(null), editability_types.NO);
// You can't edit a message you didn't send
@ -89,4 +89,4 @@ var editability_types = message_edit.editability_types;
message.sent_by_me = false;
global.page_params.realm_allow_community_topic_editing = false;
assert.equal(message_edit.is_topic_editable(message), false);
}());
});

View File

@ -239,7 +239,7 @@ function test_backfill_idle(idle_config) {
});
}
(function test_initialize() {
run_test('initialize', () => {
reset_lists();
var step1 = initial_fetch_step();
@ -254,7 +254,7 @@ function test_backfill_idle(idle_config) {
var idle_config = step2.finish();
test_backfill_idle(idle_config);
}());
});
function simulate_narrow() {
@ -276,7 +276,7 @@ function simulate_narrow() {
return msg_list;
}
(function test_loading_newer() {
run_test('loading_newer', () => {
function test_dup_new_fetch(msg_list) {
assert.equal(msg_list.fetch_status.can_load_newer_messages(), false);
message_fetch.maybe_load_newer_messages({
@ -376,4 +376,4 @@ function simulate_narrow() {
}());
}());
});

View File

@ -20,7 +20,7 @@ set_global('feature_flags', {});
var with_overrides = global.with_overrides; // make lint happy
(function test_basics() {
run_test('basics', () => {
var table;
var filter = {};
@ -113,9 +113,9 @@ var with_overrides = global.with_overrides; // make lint happy
list.clear();
assert.deepEqual(list.all_messages(), []);
}());
});
(function test_message_range() {
run_test('message_range', () => {
var table;
var filter = {};
var list = new MessageList(table, filter);
@ -127,9 +127,9 @@ var with_overrides = global.with_overrides; // make lint happy
assert.deepEqual(list.message_range(30, 40), [{id: 30}, {id: 40}]);
assert.deepEqual(list.message_range(31, 39), [{id: 40}]);
assert.deepEqual(list.message_range(31, 1000), [{id: 40}, {id: 50}, {id: 60}]);
}());
});
(function test_updates() {
run_test('updates', () => {
var table;
var filter = {};
var list = new MessageList(table, filter);
@ -166,9 +166,9 @@ var with_overrides = global.with_overrides; // make lint happy
list.update_stream_name(64, "Finland");
assert.equal(list.get(2).stream, "Finland");
assert.equal(list.get(1).stream, "denmark");
}());
});
(function test_nth_most_recent_id() {
run_test('nth_most_recent_id', () => {
var table;
var filter = {};
@ -178,9 +178,9 @@ var with_overrides = global.with_overrides; // make lint happy
assert.equal(list.nth_most_recent_id(2), 20);
assert.equal(list.nth_most_recent_id(3), 10);
assert.equal(list.nth_most_recent_id(4), -1);
}());
});
(function test_change_message_id() {
run_test('change_message_id', () => {
var table;
var filter = {};
@ -191,9 +191,9 @@ var with_overrides = global.with_overrides; // make lint happy
list.change_message_id(20.5, 10);
assert.equal(list.get(10).content, "ok!");
}());
});
(function test_last_sent_by_me() {
run_test('last_sent_by_me', () => {
var table;
var filter = {};
@ -217,9 +217,9 @@ var with_overrides = global.with_overrides; // make lint happy
set_global("page_params", {user_id: 3});
// Look for the last message where user_id == 3 (our ID)
assert.equal(list.get_last_message_sent_by_me().id, 2);
}());
});
(function test_local_echo() {
run_test('local_echo', () => {
var table;
var filter = {};
@ -269,9 +269,9 @@ var with_overrides = global.with_overrides; // make lint happy
assert.equal(list.closest_id(51), 50.02);
assert.equal(list.closest_id(59), 60);
assert.equal(list.closest_id(50.01), 50.01);
}());
});
(function test_bookend() {
run_test('bookend', () => {
var table;
var filter = {};
@ -349,9 +349,9 @@ var with_overrides = global.with_overrides; // make lint happy
assert.equal(bookend.show_button, true);
});
});
}());
});
(function test_unmuted_messages() {
run_test('unmuted_messages', () => {
var table;
var filter = {};
@ -387,9 +387,9 @@ var with_overrides = global.with_overrides; // make lint happy
var test_unmuted = list.unmuted_messages(unmuted.concat(muted));
assert.deepEqual(unmuted, test_unmuted);
});
}());
});
(function test_add_remove_rerender() {
run_test('add_remove_rerender', () => {
var table;
var filter = {};
@ -414,4 +414,4 @@ var with_overrides = global.with_overrides; // make lint happy
assert.equal(stub.num_calls, 1);
assert.equal(list.num_items(), 0);
});
}());
});

View File

@ -23,7 +23,7 @@ function make_msgs(msg_ids) {
return _.map(msg_ids, make_msg);
}
(function test_basics() {
run_test('basics', () => {
const mld = new MessageListData({
muting_enabled: false,
filter: undefined,
@ -102,12 +102,12 @@ function make_msgs(msg_ids) {
});
assert.equal(mld.first_unread_message_id(), 145);
}());
});
(function test_errors() {
run_test('errors', () => {
const mld = new MessageListData({
muting_enabled: false,
filter: undefined,
});
assert.equal(mld.get('bogus-id'), undefined);
}());
});

View File

@ -46,7 +46,7 @@ set_global('rows', {
},
});
(function test_merge_message_groups() {
run_test('merge_message_groups', () => {
// MessageListView has lots of DOM code, so we are going to test the message
// group mearging logic on its own.
@ -359,9 +359,9 @@ set_global('rows', {
assert_message_list_equal(result.rerender_messages, []);
}());
}());
});
(function test_render_windows() {
run_test('render_windows', () => {
// We only render up to 400 messages at a time in our message list,
// and we only change the window (which is a range, really, with
// start/end) when the pointer moves outside of the window or close
@ -475,4 +475,4 @@ set_global('rows', {
verify_move(197, [0, 400]);
verify_no_move_range(0, 350);
}());
});

View File

@ -60,7 +60,7 @@ people.add_in_realm(cindy);
global.people.initialize_current_user(me.user_id);
(function test_add_message_metadata() {
run_test('add_message_metadata', () => {
var message = {
sender_email: 'me@example.com',
sender_id: me.user_id,
@ -128,9 +128,9 @@ global.people.initialize_current_user(me.user_id);
assert.equal(message.alerted, false);
});
}());
});
(function test_errors() {
run_test('errors', () => {
// Test a user that doesn't exist
var message = {
type: 'private',
@ -166,9 +166,9 @@ global.people.initialize_current_user(me.user_id);
});
message_store.process_message_for_recent_private_messages(message);
assert.equal(num_partner, 0);
}());
});
(function test_update_booleans() {
run_test('update_booleans', () => {
var message = {};
// First, test fields that we do actually want to update.
@ -198,9 +198,9 @@ global.people.initialize_current_user(me.user_id);
flags = ['read'];
message_store.update_booleans(message, flags);
assert.equal(message.unread, true);
}());
});
(function test_message_id_change() {
run_test('message_id_change', () => {
var message = {
sender_email: 'me@example.com',
sender_id: me.user_id,
@ -240,4 +240,4 @@ global.people.initialize_current_user(me.user_id);
assert.equal(msg_id.new, 402);
});
}());
});

View File

@ -1,14 +1,14 @@
zrequire('muting');
(function test_edge_cases() {
run_test('edge_cases', () => {
// private messages
assert(!muting.is_topic_muted(undefined, undefined));
// defensive
assert(!muting.is_topic_muted('nonexistent', undefined));
}());
});
(function test_basics() {
run_test('basics', () => {
assert(!muting.is_topic_muted('devel', 'java'));
muting.add_muted_topic('devel', 'java');
assert(muting.is_topic_muted('devel', 'java'));
@ -27,9 +27,9 @@ zrequire('muting');
// test unknown stream is harmless too
muting.remove_muted_topic('unknown', 'java');
assert(!muting.is_topic_muted('unknown', 'java'));
}());
});
(function test_get_and_set_muted_topics() {
run_test('get_and_set_muted_topics', () => {
assert.deepEqual(muting.get_muted_topics(), []);
muting.add_muted_topic('office', 'gossip');
muting.add_muted_topic('devel', 'java');
@ -46,9 +46,9 @@ zrequire('muting');
['design', 'typography'],
['social', 'breakfast'],
]);
}());
});
(function test_case_insensitivity() {
run_test('case_insensitivity', () => {
muting.set_muted_topics([]);
assert(!muting.is_topic_muted('SOCial', 'breakfast'));
muting.set_muted_topics([
@ -57,4 +57,4 @@ zrequire('muting');
assert(muting.is_topic_muted('SOCial', 'breakfast'));
assert(muting.is_topic_muted('social', 'breakfast'));
assert(muting.is_topic_muted('social', 'breakFAST'));
}());
});

View File

@ -14,7 +14,7 @@ function set_filter(operators) {
narrow_state.set_current_filter(new Filter(operators));
}
(function test_stream_topic() {
run_test('stream_topic', () => {
set_filter([['stream', 'Foo'], ['topic', 'Bar'], ['search', 'Yo']]);
set_global('current_msg_list', {
@ -43,9 +43,9 @@ function set_filter(operators) {
topic: 'Topic1',
});
}());
});
(function test_uris() {
run_test('uris', () => {
var ray = {
email: 'ray@example.com',
user_id: 22,
@ -71,9 +71,9 @@ function set_filter(operators) {
var emails = global.hash_util.decode_operand('pm-with', '22,23-group');
assert.equal(emails, 'alice@example.com,ray@example.com');
}());
});
(function test_show_empty_narrow_message() {
run_test('show_empty_narrow_message', () => {
var hide_id;
var show_id;
@ -151,4 +151,4 @@ function set_filter(operators) {
narrow.show_empty_narrow_message();
assert.equal(hide_id,'.empty_feed_notice');
assert.equal(show_id, '#empty_search_narrow_message');
}());
});

View File

@ -132,7 +132,7 @@ function stub_message_list() {
};
}
(function test_basics() {
run_test('basics', () => {
stub_message_list();
var helper = test_helper();
@ -212,4 +212,4 @@ function stub_message_list() {
'report narrow times',
]);
}());
});

View File

@ -14,7 +14,7 @@ function set_filter(operators) {
}
(function test_stream() {
run_test('stream', () => {
assert.equal(narrow_state.public_operators(), undefined);
assert(!narrow_state.active());
@ -44,10 +44,10 @@ function set_filter(operators) {
var public_operators = narrow_state.public_operators();
assert.deepEqual(public_operators, expected_operators);
assert.equal(narrow_state.search_string(), 'stream:Test topic:Bar yo');
}());
});
(function test_narrowed() {
run_test('narrowed', () => {
narrow_state.reset_current_filter(); // not narrowed, basically
assert(!narrow_state.narrowed_to_pms());
assert(!narrow_state.narrowed_by_reply());
@ -93,9 +93,9 @@ function set_filter(operators) {
assert(narrow_state.narrowed_to_search());
assert(!narrow_state.narrowed_to_topic());
assert(!narrow_state.narrowed_by_stream_reply());
}());
});
(function test_operators() {
run_test('operators', () => {
set_filter([['stream', 'Foo'], ['topic', 'Bar'], ['search', 'Yo']]);
var result = narrow_state.operators();
assert.equal(result.length, 3);
@ -111,9 +111,9 @@ function set_filter(operators) {
narrow_state.reset_current_filter();
result = narrow_state.operators();
assert.equal(result.length, 0);
}());
});
(function test_muting_enabled() {
run_test('muting_enabled', () => {
set_filter([['stream', 'devel']]);
assert(narrow_state.muting_enabled());
@ -129,9 +129,9 @@ function set_filter(operators) {
set_filter([['is', 'private']]);
assert(!narrow_state.muting_enabled());
}());
});
(function test_set_compose_defaults() {
run_test('set_compose_defaults', () => {
set_filter([['stream', 'Foo'], ['topic', 'Bar']]);
var stream_and_subject = narrow_state.set_compose_defaults();
@ -150,9 +150,9 @@ function set_filter(operators) {
var stream_test = narrow_state.set_compose_defaults();
assert.equal(stream_test.stream, 'ROME');
}());
});
(function test_update_email() {
run_test('update_email', () => {
var steve = {
email: 'steve@foo.com',
user_id: 43,
@ -170,9 +170,9 @@ function set_filter(operators) {
assert.deepEqual(filter.operands('pm-with'), ['showell@foo.com']);
assert.deepEqual(filter.operands('sender'), ['showell@foo.com']);
assert.deepEqual(filter.operands('stream'), ['steve@foo.com']);
}());
});
(function test_topic() {
run_test('topic', () => {
set_filter([['stream', 'Foo'], ['topic', 'Bar']]);
assert.equal(narrow_state.topic(), 'Bar');
@ -190,10 +190,10 @@ function set_filter(operators) {
narrow_state.set_current_filter(undefined);
assert.equal(narrow_state.topic(), undefined);
}());
});
(function test_stream() {
run_test('stream', () => {
set_filter(undefined);
assert.equal(narrow_state.stream(), undefined);
assert.equal(narrow_state.stream_id(), undefined);
@ -210,9 +210,9 @@ function set_filter(operators) {
set_filter([['sender', 'someone'], ['topic', 'random']]);
assert.equal(narrow_state.stream(), undefined);
}());
});
(function test_pm_string() {
run_test('pm_string', () => {
// This function will return undefined unless we're clearly
// narrowed to a specific PM (including huddles) with real
// users.
@ -248,4 +248,4 @@ function set_filter(operators) {
set_filter([['pm-with', 'bob@foo.com,alice@foo.com']]);
assert.equal(narrow_state.pm_string(), '444,555');
}());
});

View File

@ -38,7 +38,7 @@ function candidate_ids() {
return narrow_state._possible_unread_message_ids();
}
(function test_get_unread_ids() {
run_test('get_unread_ids', () => {
var unread_ids;
var terms;
@ -194,4 +194,4 @@ function candidate_ids() {
assert_unread_info({
flavor: 'cannot_compute',
});
}());
});

View File

@ -56,7 +56,7 @@ muting.add_muted_topic(three.name, 'topic_seven');
// Subscribe to topic
stream_data.add_sub('stream_two', two);
(function test_message_is_notifiable() {
run_test('message_is_notifiable', () => {
// This function tests logic for 4 cases
// that should override any of the user's notifications settings
// and a 5th that passes it on the user's notifications settings
@ -154,10 +154,10 @@ stream_data.add_sub('stream_two', two);
stream_id: 20,
subject: 'topic_two',
}), true);
}());
});
(function test_basic_notifications() {
run_test('basic_notifications', () => {
var n; // Object for storing all notification data for assertions.
var last_closed_message_id = null;
@ -261,4 +261,4 @@ stream_data.add_sub('stream_two', two);
assert.equal('undefined to stream_one > topic_two' in n, false);
assert.equal(Object.keys(n).length, 0);
assert.equal(last_closed_message_id, message_2.id);
}());
});

View File

@ -3,7 +3,7 @@ zrequire('common');
set_global('i18n', global.stub_i18n);
(function test_basics() {
run_test('basics', () => {
var accepted;
var password;
var warning;
@ -72,4 +72,4 @@ set_global('i18n', global.stub_i18n);
assert(accepted === undefined);
warning = common.password_warning(password, password_field(6));
assert(warning === undefined);
}());
});

View File

@ -24,7 +24,7 @@ function initialize() {
initialize();
(function test_basics() {
run_test('basics', () => {
var persons = people.get_all_persons();
assert.equal(_.size(persons), 1);
@ -107,28 +107,28 @@ initialize();
assert.equal(people.is_my_user_id(me.user_id), true);
assert.equal(people.is_my_user_id(isaac.user_id), false);
assert.equal(people.is_my_user_id(undefined), false);
}());
});
(function test_pm_lookup_key() {
run_test('pm_lookup_key', () => {
assert.equal(people.pm_lookup_key('30'), '30');
assert.equal(people.pm_lookup_key('32,30'), '32');
assert.equal(people.pm_lookup_key('101,32,30'), '32,101');
}());
});
(function test_get_recipients() {
run_test('get_recipients', () => {
assert.equal(people.get_recipients('30'), 'Me Myself');
assert.equal(people.get_recipients('30,32'), 'Isaac Newton');
}());
});
(function test_my_custom_profile_data() {
run_test('my_custom_profile_data', () => {
var person = people.get_by_email(me.email);
person.profile_data = {3: 'My address', 4: 'My phone number'};
assert.equal(people.my_custom_profile_data(3), 'My address');
assert.equal(people.my_custom_profile_data(4), 'My phone number');
assert.equal(people.my_custom_profile_data(undefined), undefined);
}());
});
(function test_user_timezone() {
run_test('user_timezone', () => {
var expected_pref = {
timezone: 'US/Pacific',
format: 'HH:mm',
@ -150,17 +150,17 @@ initialize();
expected_pref.format = 'hh:mm A';
global.page_params.twenty_four_hour_time = false;
assert.equal(people.get_user_time(me.user_id), '12:09 AM');
}());
});
(function test_updates() {
run_test('updates', () => {
var person = people.get_by_email('me@example.com');
people.set_full_name(person, 'Me the Third');
assert.equal(people.my_full_name(), 'Me the Third');
assert.equal(person.full_name, 'Me the Third');
assert.equal(people.get_by_name('Me the Third').email, 'me@example.com');
}());
});
(function test_get_person_from_user_id() {
run_test('get_person_from_user_id', () => {
var person = {
email: 'mary@example.com',
user_id: 42,
@ -184,11 +184,11 @@ initialize();
assert.equal(person, undefined);
person = people.get_person_from_user_id(42);
assert.equal(person.user_id, 42);
}());
});
initialize();
(function test_set_custom_profile_field_data() {
run_test('set_custom_profile_field_data', () => {
var person = people.get_by_email(me.email);
me.profile_data = {};
var field = {id: 3, name: 'Custom long field', type: 'text', value: 'Field value'};
@ -196,9 +196,9 @@ initialize();
assert.deepEqual(person.profile_data, {});
people.set_custom_profile_field_data(person.user_id, field);
assert.equal(person.profile_data[field.id], 'Field value');
}());
});
(function test_get_rest_of_realm() {
run_test('get_rest_of_realm', () => {
var alice1 = {
email: 'alice1@example.com',
user_id: 202,
@ -227,11 +227,11 @@ initialize();
];
assert.deepEqual(others, expected);
}());
});
initialize();
(function test_recipient_counts() {
run_test('recipient_counts', () => {
var user_id = 99;
assert.equal(people.get_recipient_count({id: user_id}), 0);
people.incr_recipient_count(user_id);
@ -239,9 +239,9 @@ initialize();
assert.equal(people.get_recipient_count({user_id: user_id}), 2);
assert.equal(people.get_recipient_count({pm_recipient_count: 5}), 5);
}());
});
(function test_filtered_users() {
run_test('filtered_users', () => {
var charles = {
email: 'charles@example.com',
user_id: 301,
@ -323,11 +323,11 @@ initialize();
filtered_people = people.filter_people_by_search_terms(users, ['ltorv']);
assert.equal(filtered_people.num_items(), 1);
assert(filtered_people.has(linus.user_id));
}());
});
people.init();
(function test_multi_user_methods() {
run_test('multi_user_methods', () => {
var emp401 = {
email: 'emp401@example.com',
user_id: 401,
@ -359,11 +359,11 @@ people.init();
assert.equal(slug, '401,402-group');
assert.equal(people.reply_to_to_user_ids_string('invalid@example.com'), undefined);
}());
});
initialize();
(function test_message_methods() {
run_test('message_methods', () => {
var charles = {
email: 'charles@example.com',
user_id: 451,
@ -459,11 +459,11 @@ initialize();
message = { sender_id: undefined };
assert.equal(people.sender_is_bot(message), false);
}());
});
initialize();
(function test_extract_people_from_message() {
run_test('extract_people_from_message', () => {
var unknown_user = {
email: 'unknown@example.com',
user_id: 500,
@ -505,11 +505,11 @@ initialize();
display_recipient: [unknown_user],
};
people.extract_people_from_message(message);
}());
});
initialize();
(function test_maybe_incr_recipient_count() {
run_test('maybe_incr_recipient_count', () => {
var maria = {
email: 'athens@example.com',
user_id: 452,
@ -555,9 +555,9 @@ initialize();
};
people.maybe_incr_recipient_count(message);
assert.equal(people.get_recipient_count(maria), 1);
}());
});
(function test_slugs() {
run_test('slugs', () => {
var person = {
email: 'deBBie71@example.com',
user_id: 501,
@ -574,11 +574,11 @@ initialize();
// Test undefined slug
people.emails_strings_to_user_ids_string = function () { return; };
assert.equal(people.emails_to_slug(), undefined);
}());
});
initialize();
(function test_updates() {
run_test('updates', () => {
var old_email = 'FOO@example.com';
var new_email = 'bar@example.com';
var user_id = 502;
@ -622,11 +622,11 @@ initialize();
assert.equal(person.user_id, user_id);
assert.equal(blueslip.get_test_logs('warn').length, 1);
blueslip.clear_test_data();
}());
});
initialize();
(function test_update_email_in_reply_to() {
run_test('update_email_in_reply_to', () => {
var charles = {
email: 'charles@example.com',
user_id: 601,
@ -655,9 +655,9 @@ initialize();
people.update_email_in_reply_to(reply_to, 9999, 'whatever'),
reply_to
);
}());
});
(function test_initialize() {
run_test('initialize', () => {
people.init();
global.page_params.realm_non_active_users = [
@ -701,4 +701,4 @@ initialize();
assert.equal(global.page_params.realm_users, undefined);
assert.equal(global.page_params.cross_realm_bots, undefined);
assert.equal(global.page_params.realm_non_active_users, undefined);
}());
});

View File

@ -18,7 +18,7 @@ people.init();
people.add(me);
people.initialize_current_user(me.user_id);
(function test_report_late_add() {
run_test('report_late_add', () => {
blueslip.set_test_data('error', 'Added user late: user_id=55 email=foo@example.com');
people.report_late_add(55, 'foo@example.com');
assert.equal(blueslip.get_test_logs('error').length, 1);
@ -30,9 +30,9 @@ people.initialize_current_user(me.user_id);
assert.equal(blueslip.get_test_logs('log')[0], 'Added user late: user_id=55 email=foo@example.com');
assert.equal(blueslip.get_test_logs('error').length, 0);
blueslip.clear_test_data();
}());
});
(function test_blueslip() {
run_test('blueslip', () => {
var unknown_email = "alicebobfred@example.com";
blueslip.set_test_data('debug', 'User email operand unknown: ' + unknown_email);
@ -118,4 +118,4 @@ people.initialize_current_user(me.user_id);
assert.equal(uri.indexOf('unk'), uri.length - 3);
assert.equal(blueslip.get_test_logs('error').length, 1);
blueslip.clear_test_data();
}());
});

View File

@ -1,6 +1,6 @@
var pmc = zrequire('pm_conversations');
(function test_partners() {
run_test('partners', () => {
var user1_id = 1;
var user2_id = 2;
var user3_id = 3;
@ -11,9 +11,9 @@ var pmc = zrequire('pm_conversations');
assert.equal(pmc.is_partner(user1_id), true);
assert.equal(pmc.is_partner(user2_id), false);
assert.equal(pmc.is_partner(user3_id), true);
}());
});
(function test_insert_recent_private_message() {
run_test('insert_recent_private_message', () => {
pmc.recent.insert('1', 1001);
pmc.recent.insert('2', 2001);
pmc.recent.insert('1', 3001);
@ -27,5 +27,5 @@ var pmc = zrequire('pm_conversations');
]);
assert.deepEqual(pmc.recent.get_strings(), ['1', '2']);
}());
});

View File

@ -43,25 +43,25 @@ global.people.add_in_realm(bob);
global.people.add_in_realm(me);
global.people.initialize_current_user(me.user_id);
(function test_get_conversation_li() {
run_test('get_conversation_li', () => {
var test_conversation = 'foo@example.com,bar@example.com';
blueslip.set_test_data('warn', 'Unknown conversation: ' + test_conversation);
blueslip.set_test_data('warn', 'Unknown emails: ' + test_conversation); // people.js
pm_list.get_conversation_li(test_conversation);
assert.equal(blueslip.get_test_logs('warn').length, 2);
blueslip.clear_test_data();
}());
});
(function test_close() {
run_test('close', () => {
var collapsed;
$('ul.expanded_private_messages').remove = function () {
collapsed = true;
};
pm_list.close();
assert(collapsed);
}());
});
(function test_build_private_messages_list() {
run_test('build_private_messages_list', () => {
var active_conversation_1 = "alice@zulip.com,bob@zulip.com";
var active_conversation_2 = 'me@zulip.com,alice@zulip.com';
var max_conversations = 5;
@ -120,9 +120,9 @@ global.people.initialize_current_user(me.user_id);
expected_data.want_show_more_messages_links = false;
pm_list._build_private_messages_list(active_conversation_2, max_conversations);
assert.deepEqual(template_data, expected_data);
}());
});
(function test_expand_and_update_private_messages() {
run_test('expand_and_update_private_messages', () => {
var collapsed;
$('ul.expanded_private_messages').remove = function () {
collapsed = true;
@ -222,9 +222,9 @@ global.people.initialize_current_user(me.user_id);
narrow_state.active = function () { return false; };
pm_list.update_private_messages();
}());
});
(function test_update_dom_with_unread_counts() {
run_test('update_dom_with_unread_counts', () => {
var total_value = $.create('total-value-stub');
var total_count = $.create('total-count-stub');
var private_li = $("#global_filters > li[data-name='private']");
@ -289,4 +289,4 @@ global.people.initialize_current_user(me.user_id);
assert(toggle_button_set);
assert.equal(child_value.text(), '');
assert.equal(total_value.text(), '');
}());
});

View File

@ -88,7 +88,7 @@ function make_image_stubber() {
};
}
(function test_sender_hover() {
run_test('sender_hover', () => {
popovers.register_click_handlers();
var handler = $('#main_div').get_on_handler('click', '.sender_info_hover');
@ -174,4 +174,4 @@ function make_image_stubber() {
assert.equal(avatar_img.src, 'avatar/42/medium');
// todo: load image
}());
});

View File

@ -44,7 +44,7 @@ people.add_in_realm(zoe);
people.add_in_realm(bot);
people.initialize_current_user(me.user_id);
(function test_on_mobile_property() {
run_test('on_mobile_property', () => {
// TODO: move this test to a new test module directly testing presence.js
var status_from_timestamp = presence._status_from_timestamp;
@ -136,9 +136,9 @@ people.initialize_current_user(me.user_id);
assert.equal(status.mobile, false);
assert.equal(status.status, "active"); // website
assert(called);
}());
});
(function test_set_presence_info() {
run_test('set_presence_info', () => {
var presences = {};
var base_time = 500;
@ -190,9 +190,9 @@ people.initialize_current_user(me.user_id);
assert.equal(msg, 'Unknown email in presence data: unknown@zulip.com');
};
presence.set_info(presences, base_time);
}());
});
(function test_last_active_date() {
run_test('last_active_date', () => {
var unknown_id = 42;
presence.presence_info = {
1: { last_active: 500 }, // alice.user_id
@ -203,9 +203,9 @@ people.initialize_current_user(me.user_id);
assert.equal(presence.last_active_date(unknown_id), undefined);
assert.equal(presence.last_active_date(fred.user_id), undefined);
assert.deepEqual(presence.last_active_date(alice.user_id), {seconds: 500000});
}());
});
(function test_set_user_status() {
run_test('set_user_status', () => {
var server_time = 500;
var info = {
website: {
@ -219,5 +219,5 @@ people.initialize_current_user(me.user_id);
var expected = { status: 'active', mobile: false, last_active: 500 };
assert.deepEqual(presence.presence_info[alice.user_id], expected);
}());
});

View File

@ -122,7 +122,7 @@ set_global('current_msg_list', {
},
});
(function test_open_reactions_popover() {
run_test('open_reactions_popover', () => {
$('.selected-row').set_find_results('.actions_hover', $('.target-action'));
$('.selected-row').set_find_results('.reaction_button', $('.target-reaction'));
@ -147,9 +147,9 @@ set_global('current_msg_list', {
assert(reactions.open_reactions_popover());
assert(called);
}());
});
(function test_basics() {
run_test('basics', () => {
var result = reactions.get_message_reactions(message);
assert(reactions.current_user_has_reacted_to_emoji(message, '1f604', 'unicode_emoji'));
@ -195,9 +195,9 @@ set_global('current_msg_list', {
},
];
assert.deepEqual(result, expected_result);
}());
});
(function test_sending() {
run_test('sending', () => {
var message_id = 1001; // see above for setup
var emoji_name = 'smile'; // should be a current reaction
@ -278,9 +278,9 @@ set_global('current_msg_list', {
global.blueslip.warn = orig_func;
reactions.add_reaction = orig_add_reaction;
reactions.remove_reaction = orig_remove_reaction;
}());
});
(function test_set_reaction_count() {
run_test('set_reaction_count', () => {
var count_element = $.create('count-stub');
var reaction_element = $.create('reaction-stub');
@ -289,9 +289,9 @@ set_global('current_msg_list', {
reactions.set_reaction_count(reaction_element, 5);
assert.equal(count_element.text(), '5');
}());
});
(function test_get_reaction_section() {
run_test('get_reaction_section', () => {
var message_table = $.create('.message_table');
var message_row = $.create('some-message-row');
var message_reactions = $.create('our-reactions-section');
@ -302,9 +302,9 @@ set_global('current_msg_list', {
var section = reactions.get_reaction_section(555);
assert.equal(section, message_reactions);
}());
});
(function test_add_and_remove_reaction() {
run_test('add_and_remove_reaction', () => {
// Insert 8ball for Alice.
var alice_event = {
message_id: 1001,
@ -485,9 +485,9 @@ set_global('current_msg_list', {
reactions.remove_reaction(alice_event);
assert(!reaction_element.hasClass('reacted'));
}());
});
(function test_with_view_stubs() {
run_test('with_view_stubs', () => {
// This function tests reaction events by mocking out calls to
// the view.
@ -646,9 +646,9 @@ set_global('current_msg_list', {
],
});
}());
});
(function test_error_handling() {
run_test('error_handling', () => {
var error_msg;
global.message_store.get = function () {
@ -681,9 +681,9 @@ set_global('current_msg_list', {
reactions.remove_reaction(bogus_event);
assert.equal(error_msg, undefined);
}());
});
(function test_local_reaction_id() {
run_test('local_reaction_id', () => {
var reaction_info = {
reaction_type: 'unicode_emoji',
emoji_name: 'thumbs_up',
@ -694,9 +694,9 @@ set_global('current_msg_list', {
var reverse_info = reactions.get_reaction_info(local_id);
assert.deepEqual(reverse_info, reaction_info);
}());
});
(function test_process_reaction_click() {
run_test('process_reaction_click', () => {
var message_id = 1001;
var expected_reaction_info = {
reaction_type: 'unicode_emoji',
@ -728,4 +728,4 @@ set_global('current_msg_list', {
assert.equal(args.url, '/json/messages/1001/reactions');
assert.deepEqual(args.data, expected_reaction_info);
});
}());
});

View File

@ -1,6 +1,6 @@
var rs = zrequire('recent_senders');
(function test_process_message_for_senders() {
run_test('process_message_for_senders', () => {
var stream1 = 1;
var stream2 = 2;
var stream3 = 3;
@ -111,4 +111,4 @@ var rs = zrequire('recent_senders');
true);
assert.equal(rs.compare_by_recency({}, {}, _.uniqueId(), ''), 0);
}());
});

View File

@ -1,7 +1,7 @@
zrequire('util');
var rtl = zrequire('rtl');
(function test_get_direction() {
run_test('get_direction', () => {
// These characters are strong R or AL: ا ب پ ج ض و د ؛
// These characters are not strong: ۱ ۲ ۳ ۴ ۵ ۶ ۷ ۸ ۹ ۰
@ -45,4 +45,4 @@ var rtl = zrequire('rtl');
assert.equal(rtl.get_direction(',,' + i_chars.charAt(1) + 'bb' + pdi + '33' + pdi + '..'), 'ltr');
assert.equal(rtl.get_direction(',,' + i_chars.charAt(2) + 'bb' + pdi + '12' + pdi + 'وو'), 'rtl');
assert.equal(rtl.get_direction(',,' + i_chars.charAt(1) + 'ضج' + pdi + '12' + pdi + 'ff'), 'ltr');
}());
});

View File

@ -1,6 +1,6 @@
zrequire('scroll_util');
(function test_scroll_delta() {
run_test('scroll_delta', () => {
// If we are entirely on-screen, don't scroll
assert.equal(0, scroll_util.scroll_delta({
elem_top: 1,
@ -52,9 +52,9 @@ zrequire('scroll_util');
container_height: 10,
}));
}());
});
(function test_scroll_element_into_container() {
run_test('scroll_element_into_container', () => {
const container = (function () {
var top = 3;
return {
@ -89,5 +89,5 @@ zrequire('scroll_util');
};
scroll_util.scroll_element_into_container(elem2, container);
assert.equal(container.scrollTop(), 250 - 100 + 3 + 15);
}());
});

View File

@ -26,7 +26,7 @@ set_global('narrow', {});
topic_data.reset();
(function test_basic_get_suggestions() {
run_test('basic_get_suggestions', () => {
var query = 'fred';
global.stream_data.subscribed_streams = function () {
@ -43,9 +43,9 @@ topic_data.reset();
'fred',
];
assert.deepEqual(suggestions.strings, expected);
}());
});
(function test_subset_suggestions() {
run_test('subset_suggestions', () => {
var query = 'stream:Denmark topic:Hamlet shakespeare';
global.stream_data.subscribed_streams = function () {
@ -65,9 +65,9 @@ topic_data.reset();
];
assert.deepEqual(suggestions.strings, expected);
}());
});
(function test_private_suggestions() {
run_test('private_suggestions', () => {
global.stream_data.subscribed_streams = function () {
return [];
};
@ -236,9 +236,9 @@ topic_data.reset();
'sender:ted@zulip.com',
];
assert.deepEqual(suggestions.strings, expected);
}());
});
(function test_group_suggestions() {
run_test('group_suggestions', () => {
global.stream_data.subscribed_streams = function () {
return [];
};
@ -418,11 +418,11 @@ topic_data.reset();
"pm-with:jeff@zulip.com,ted@zulip.com",
];
assert.deepEqual(suggestions.strings, expected);
}());
});
init();
(function test_empty_query_suggestions() {
run_test('empty_query_suggestions', () => {
var query = '';
global.stream_data.subscribed_streams = function () {
@ -458,9 +458,9 @@ init();
assert.equal(describe('is:alerted'), 'Alerted messages');
assert.equal(describe('is:unread'), 'Unread messages');
assert.equal(describe('sender:bob@zulip.com'), 'Sent by me');
}());
});
(function test_sent_by_me_suggestions() {
run_test('sent_by_me_suggestions', () => {
global.stream_data.subscribed_streams = function () {
return [];
};
@ -541,9 +541,9 @@ init();
"sender:alice@zulip.com",
];
assert.deepEqual(suggestions.strings, expected);
}());
});
(function test_topic_suggestions() {
run_test('topic_suggestions', () => {
var suggestions;
var expected;
@ -654,9 +654,9 @@ init();
'topic:REXX',
];
assert.deepEqual(suggestions.strings, expected);
}());
});
(function test_whitespace_glitch() {
run_test('whitespace_glitch', () => {
var query = 'stream:office '; // note trailing space
global.stream_data.subscribed_streams = function () {
@ -676,9 +676,9 @@ init();
];
assert.deepEqual(suggestions.strings, expected);
}());
});
(function test_stream_completion() {
run_test('stream_completion', () => {
global.stream_data.subscribed_streams = function () {
return ['office', 'dev help'];
};
@ -704,9 +704,9 @@ init();
"stream:dev+help",
];
assert.deepEqual(suggestions.strings, expected);
}());
});
(function test_people_suggestions() {
run_test('people_suggestions', () => {
var query = 'te';
global.stream_data.subscribed_streams = function () {
@ -773,9 +773,9 @@ init();
assert.deepEqual(suggestions.strings, expected);
}());
});
(function test_contains_suggestions() {
run_test('contains_suggestions', () => {
var query = 'has:';
var suggestions = search.get_suggestions(query);
var expected = [
@ -819,9 +819,9 @@ init();
'stream:Denmark',
];
assert.deepEqual(suggestions.strings, expected);
}());
});
(function test_operator_suggestions() {
run_test('operator_suggestions', () => {
// Completed operator should return nothing
var query = 'stream:';
var suggestions = search.get_suggestions(query);
@ -865,9 +865,9 @@ init();
'stream:Denmark',
];
assert.deepEqual(suggestions.strings, expected);
}());
});
(function test_queries_with_spaces() {
run_test('queries_with_spaces', () => {
global.stream_data.subscribed_streams = function () {
return ['office', 'dev help'];
};
@ -904,4 +904,4 @@ init();
"stream:office",
];
assert.deepEqual(suggestions.strings, expected);
}());
});

View File

@ -38,7 +38,7 @@ set_global('ui_report', {
server_events.home_view_loaded();
(function test_message_event() {
run_test('message_event', () => {
var event = {
type: 'message',
message: {
@ -57,9 +57,9 @@ server_events.home_view_loaded();
server_events._get_events_success([event]);
assert(inserted);
}());
});
(function test_pointer_event() {
run_test('pointer_event', () => {
var event = {
type: 'pointer',
pointer: 999,
@ -70,7 +70,7 @@ server_events.home_view_loaded();
server_events._get_events_success([event]);
assert.equal(global.pointer.furthest_read, event.pointer);
assert.equal(global.pointer.server_furthest_read, event.pointer);
}());
});
// Start blueslip tests here
@ -100,7 +100,7 @@ var setup = function (results) {
};
};
(function test_event_dispatch_error() {
run_test('event_dispatch_error', () => {
var results = {};
setup(results);
@ -117,10 +117,10 @@ var setup = function (results) {
assert.equal(results.more_info.event.op , 'update');
assert.equal(results.more_info.event.id , 1);
assert.equal(results.more_info.other , undefined);
}());
});
(function test_event_new_message_error() {
run_test('event_new_message_error', () => {
var results = {};
setup(results);
@ -134,9 +134,9 @@ var setup = function (results) {
assert.equal(results.msg, 'Failed to insert new messages\n' +
'insert error');
assert.equal(results.more_info, undefined);
}());
});
(function test_event_edit_message_error() {
run_test('event_edit_message_error', () => {
var results = {};
setup(results);
@ -150,4 +150,4 @@ var setup = function (results) {
assert.equal(results.msg, 'Failed to update messages\n' +
'update error');
assert.equal(results.more_info, undefined);
}());
});

View File

@ -18,7 +18,7 @@ zrequire('settings_bots');
zrequire('Handlebars', 'handlebars');
zrequire('templates');
(function test_generate_zuliprc_uri() {
run_test('generate_zuliprc_uri', () => {
var bot = {
email: "error-bot@zulip.org",
api_key: "QadL788EkiottHmukyhHgePUFHREiu8b",
@ -31,9 +31,9 @@ zrequire('templates');
);
assert.equal(uri, expected);
}());
});
(function test_generate_zuliprc_content() {
run_test('generate_zuliprc_content', () => {
var user = {
email: "admin12@chatting.net",
api_key: "nSlA0mUm7G42LP85lMv7syqFTzDE2q34",
@ -44,9 +44,9 @@ zrequire('templates');
"site=https://chat.example.com\n";
assert.equal(content, expected);
}());
});
(function test_generate_flaskbotrc_content() {
run_test('generate_flaskbotrc_content', () => {
var user = {
email: "vabstest-bot@zulip.com",
api_key: "nSlA0mUm7G42LP85lMv7syqFTzDE2q34",
@ -57,7 +57,7 @@ zrequire('templates');
"site=https://chat.example.com\n";
assert.equal(content, expected);
}());
});
function test_create_bot_type_input_box_toggle(f) {
var create_payload_url = $('#create_payload_url');
@ -88,7 +88,7 @@ function test_create_bot_type_input_box_toggle(f) {
assert(!config_inputbox.visible());
}
(function test_set_up() {
run_test('set_up', () => {
// bunch of stubs
$.validator = { addMethod: function () {} };
@ -117,5 +117,5 @@ function test_create_bot_type_input_box_toggle(f) {
settings_bots.setup_bot_creation_policy_values();
settings_bots.set_up();
}());
});

View File

@ -6,7 +6,7 @@ set_global('muting_ui', {});
var noop = function () {};
(function test_settings() {
run_test('settings', () => {
muting.add_muted_topic('frontend', 'js');
var set_up_ui_called = false;
@ -53,4 +53,4 @@ var noop = function () {};
assert(unmute_called);
assert(set_up_ui_called);
assert.equal(data_called, 2);
}());
});

View File

@ -34,14 +34,14 @@ set_global('templates', {
set_global('overlays', {
});
(function test_unloaded() {
run_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) {
@ -495,7 +495,7 @@ function test_parse_time_limit() {
test_function('501.34', '501.3');
}
(function test_set_up() {
run_test('set_up', () => {
var callbacks = {};
var set_callback = (name) => {
@ -564,9 +564,9 @@ function test_parse_time_limit() {
test_parse_time_limit();
settings_org.render_notifications_stream_ui = stub_render_notifications_stream_ui;
}());
});
(function test_misc() {
run_test('misc', () => {
page_params.is_admin = false;
var stub_notification_disable_parent = $.create('<stub notification_disable parent');
@ -631,4 +631,4 @@ function test_parse_time_limit() {
assert.equal(elem.text(), 'translated: Disabled');
assert(elem.hasClass('text-warning'));
}());
});

View File

@ -38,7 +38,7 @@ function reset_test_setup(pill_container_stub) {
});
}
(function test_can_edit() {
run_test('can_edit', () => {
var me = {
is_admin: false,
};
@ -52,7 +52,7 @@ function reset_test_setup(pill_container_stub) {
return false;
};
settings_user_groups.can_edit(1);
}());
});
var user_group_selector = "#user-groups #1";
var cancel_selector = "#user-groups #1 .cancel";
@ -61,7 +61,7 @@ var name_selector = "#user-groups #1 .name";
var description_selector = "#user-groups #1 .description";
var instructions_selector = "#user-groups #1 .save-instructions";
(function test_populate_user_groups() {
run_test('populate_user_groups', () => {
var realm_user_group = {
id: 1,
name: 'Mobile',
@ -301,8 +301,8 @@ var instructions_selector = "#user-groups #1 .save-instructions";
assert.equal(typeof($('.organization form.admin-user-group-form').get_on_handler("submit")), 'function');
assert.equal(typeof($('#user-groups').get_on_handler('click', '.delete')), 'function');
assert.equal(typeof($('#user-groups').get_on_handler('keypress', '.user-group h4 > span')), 'function');
}());
(function test_with_external_user() {
});
run_test('with_external_user', () => {
var realm_user_group = {
id: 1,
@ -468,9 +468,9 @@ var instructions_selector = "#user-groups #1 .save-instructions";
assert.equal(turned_off['keydown/.pill'], true);
assert.equal(turned_off['keydown/.input'], true);
assert.equal(turned_off['click/whole'], true);
}());
});
(function test_reload() {
run_test('reload', () => {
$('#user-groups').html('Some text');
var populate_user_groups_called = false;
settings_user_groups.populate_user_groups = function () {
@ -479,15 +479,15 @@ var instructions_selector = "#user-groups #1 .save-instructions";
settings_user_groups.reload();
assert(populate_user_groups_called);
assert.equal($('#user-groups').html(), '');
}());
});
(function test_reset() {
run_test('reset', () => {
settings_user_groups.reset();
var result = settings_user_groups.reload();
assert.equal(result, undefined);
}());
});
(function test_on_events() {
run_test('on_events', () => {
settings_user_groups.can_edit = function () {
return true;
@ -828,4 +828,4 @@ var instructions_selector = "#user-groups #1 .save-instructions";
handler.call(fake_this, event);
assert(api_endpoint_called);
}());
}());
});

View File

@ -2,7 +2,7 @@ global.stub_out_jquery();
zrequire('stream_color');
(function test_pick_color() {
run_test('pick_color', () => {
var used_colors = ["#76ce90", "#fae589"];
// Colors are assigned randomly, so this test is a little vague and brittle,
@ -12,4 +12,4 @@ zrequire('stream_color');
assert.notEqual(color, "#76ce90");
assert.notEqual(color, "#fae589");
assert.equal(color.length, 7);
}());
});

View File

@ -17,7 +17,7 @@ zrequire('stream_color');
zrequire('stream_data');
zrequire('marked', 'third/marked/lib/marked');
(function test_basics() {
run_test('basics', () => {
var denmark = {
subscribed: false,
color: 'blue',
@ -78,9 +78,9 @@ zrequire('marked', 'third/marked/lib/marked');
assert(stream_data.get_default_status('Denmark'));
assert(!stream_data.get_default_status('social'));
assert(!stream_data.get_default_status('UNKNOWN'));
}());
});
(function test_renames() {
run_test('renames', () => {
stream_data.clear_subscriptions();
var id = 42;
var sub = {
@ -108,9 +108,9 @@ zrequire('marked', 'third/marked/lib/marked');
var actual_id = stream_data.get_stream_id('Denmark');
assert.equal(actual_id, 42);
}());
});
(function test_unsubscribe() {
run_test('unsubscribe', () => {
stream_data.clear_subscriptions();
var sub = {name: 'devel', subscribed: false, stream_id: 1};
@ -140,9 +140,9 @@ zrequire('marked', 'third/marked/lib/marked');
// make sure subsequent calls work
sub = stream_data.get_sub('devel');
assert(!sub.subscribed);
}());
});
(function test_subscribers() {
run_test('subscribers', () => {
stream_data.clear_subscriptions();
var sub = {name: 'Rome', subscribed: true, stream_id: 1};
@ -274,9 +274,9 @@ zrequire('marked', 'third/marked/lib/marked');
global.blueslip.error = function () {};
ok = stream_data.add_subscriber('Rome', 9999999);
assert(!ok);
}());
});
(function test_is_active() {
run_test('is_active', () => {
stream_data.clear_subscriptions();
var sub = {name: 'pets', subscribed: false, stream_id: 1};
@ -303,9 +303,9 @@ zrequire('marked', 'third/marked/lib/marked');
topic_data.add_message(opts);
assert(stream_data.is_active(sub));
}());
});
(function test_admin_options() {
run_test('admin_options', () => {
function make_sub() {
var sub = {
subscribed: false,
@ -357,9 +357,9 @@ zrequire('marked', 'third/marked/lib/marked');
assert(sub.is_admin);
assert(sub.can_make_public);
assert(!sub.can_make_private);
}());
});
(function test_stream_settings() {
run_test('stream_settings', () => {
var cinnamon = {
stream_id: 1,
name: 'c',
@ -401,9 +401,9 @@ zrequire('marked', 'third/marked/lib/marked');
assert.equal(sub_rows[1].invite_only, false);
assert.equal(sub_rows[2].invite_only, false);
}());
});
(function test_get_non_default_stream_names() {
run_test('get_non_default_stream_names', () => {
var announce = {
stream_id: 101,
name: 'announce',
@ -431,9 +431,9 @@ zrequire('marked', 'third/marked/lib/marked');
var names = stream_data.get_non_default_stream_names();
assert.deepEqual(names, ['public', 'private']);
}());
});
(function test_delete_sub() {
run_test('delete_sub', () => {
var canada = {
stream_id: 101,
name: 'Canada',
@ -460,9 +460,9 @@ zrequire('marked', 'third/marked/lib/marked');
stream_data.delete_sub('does_not_exist');
assert(warned);
blueslip.warn = function () {};
}());
});
(function test_get_subscriber_count() {
run_test('get_subscriber_count', () => {
var india = {
stream_id: 102,
name: 'India',
@ -493,9 +493,9 @@ zrequire('marked', 'third/marked/lib/marked');
var sub = stream_data.get_sub_by_name('India');
delete sub.subscribers;
assert.deepStrictEqual(stream_data.get_subscriber_count('India'), 0);
}());
});
(function test_notifications() {
run_test('notifications', () => {
var india = {
stream_id: 102,
name: 'India',
@ -510,9 +510,9 @@ zrequire('marked', 'third/marked/lib/marked');
assert(stream_data.receives_audible_notifications('India'));
assert(!stream_data.receives_audible_notifications('Indiana'));
}());
});
(function test_in_home_view() {
run_test('in_home_view', () => {
var tony = {
stream_id: 999,
name: 'tony',
@ -532,17 +532,17 @@ zrequire('marked', 'third/marked/lib/marked');
assert(stream_data.name_in_home_view('tony'));
assert(!stream_data.name_in_home_view('jazy'));
assert(!stream_data.name_in_home_view('EEXISTS'));
}());
});
(function test_notifications_in_home_view() {
run_test('notifications_in_home_view', () => {
page_params.notifications_stream = 'tony';
assert(stream_data.notifications_in_home_view());
page_params.notifications_stream = 'jazy';
assert(!stream_data.notifications_in_home_view());
}());
});
(function test_remove_default_stream() {
run_test('remove_default_stream', () => {
var remove_me = {
stream_id: 674,
name: 'remove_me',
@ -555,9 +555,9 @@ zrequire('marked', 'third/marked/lib/marked');
stream_data.remove_default_stream(remove_me.stream_id);
assert(!stream_data.get_default_status('remove_me'));
assert.equal(page_params.realm_default_streams.length, 0);
}());
});
(function test_render_stream_description() {
run_test('render_stream_description', () => {
var desc = {
name: 'no_desc',
stream_id: 1002,
@ -568,16 +568,16 @@ zrequire('marked', 'third/marked/lib/marked');
var sub = stream_data.get_sub_by_name('desc');
stream_data.render_stream_description(sub);
assert.deepStrictEqual(sub.rendered_description, "rendered desc");
}());
});
(function test_canonicalized_name() {
run_test('canonicalized_name', () => {
assert.deepStrictEqual(
stream_data.canonicalized_name('Stream_Bar'),
"stream_bar"
);
}());
});
(function test_create_sub() {
run_test('create_sub', () => {
stream_data.clear_subscriptions();
var india = {
stream_id: 102,
@ -619,9 +619,9 @@ zrequire('marked', 'third/marked/lib/marked');
var antarctica_sub = stream_data.create_sub_from_server_data('Antarctica', antarctica);
assert(antarctica_sub);
assert.equal(antarctica_sub.color, '#76ce90');
}());
});
(function test_initialize_from_page_params() {
run_test('initialize_from_page_params', () => {
function initialize() {
page_params.subscriptions = [{
name: 'subscriptions',
@ -662,9 +662,9 @@ zrequire('marked', 'third/marked/lib/marked');
stream_data.initialize_from_page_params();
assert.equal(page_params.notifications_stream, "foo");
}());
});
(function test_get_newbie_stream() {
run_test('get_newbie_stream', () => {
var newbie = {
name: 'newbie',
stream_id: 234,
@ -692,9 +692,9 @@ zrequire('marked', 'third/marked/lib/marked');
new_members.subscribed = false;
assert.equal(stream_data.get_newbie_stream(), undefined);
}());
});
(function test_invite_streams() {
run_test('invite_streams', () => {
// add default stream
var orie = {
stream_id: 320,
@ -721,4 +721,4 @@ zrequire('marked', 'third/marked/lib/marked');
expected_list.push('Inviter');
assert.deepEqual(stream_data.invite_streams(), expected_list);
}());
});

View File

@ -24,7 +24,7 @@ var frontend = {
};
stream_data.add_sub('Frontend', frontend);
(function test_update_property() {
run_test('update_property', () => {
// Invoke error for non-existent stream/property
with_overrides(function (override) {
var errors = 0;
@ -113,9 +113,9 @@ stream_data.add_sub('Frontend', frontend);
assert.equal(checkbox.prop('checked'), true);
});
}());
});
(function test_marked_subscribed() {
run_test('marked_subscribed', () => {
// Test undefined error
with_overrides(function (override) {
var errors = 0;
@ -241,9 +241,9 @@ stream_data.add_sub('Frontend', frontend);
assert.deepEqual(frontend, args.sub);
});
});
}());
});
(function test_mark_unsubscribed() {
run_test('mark_unsubscribed', () => {
var removed_sub = false;
$(document).on('subscription_remove_done.zulip', function () {
removed_sub = true;
@ -305,4 +305,4 @@ stream_data.add_sub('Frontend', frontend);
assert.equal(updated, true);
assert.equal(event_triggered, true);
});
}());
});

View File

@ -30,7 +30,7 @@ set_global('keydown_util', {
handle: noop,
});
(function test_create_sidebar_row() {
run_test('create_sidebar_row', () => {
// Make a couple calls to create_sidebar_row() and make sure they
// generate the right markup as well as play nice with get_stream_li().
@ -152,7 +152,7 @@ set_global('keydown_util', {
row.remove();
assert(removed);
}());
});
set_global('$', global.make_zjquery());
@ -250,7 +250,7 @@ function elem($obj) {
return {to_$: () => $obj};
}
(function test_zoom_in_and_zoom_out() {
run_test('zoom_in_and_zoom_out', () => {
var helper;
var callbacks;
@ -345,11 +345,11 @@ function elem($obj) {
assert(stream_li1.visible());
assert(stream_li2.visible());
assert($('#streams_list').hasClass('zoom-out'));
}());
});
set_global('$', global.make_zjquery());
(function test_narrowing() {
run_test('narrowing', () => {
initialize_stream_data();
set_global('narrow_state', {
@ -417,23 +417,23 @@ set_global('$', global.make_zjquery());
stream_list.handle_narrow_deactivated();
assert.equal(removed_classes, 'active-filter active-sub-filter');
assert(topics_closed);
}());
});
(function test_focusout_user_filter() {
run_test('focusout_user_filter', () => {
var e = { };
var click_handler = $('.stream-list-filter').get_on_handler('focusout');
click_handler(e);
}());
});
(function test_focus_user_filter() {
run_test('focus_user_filter', () => {
var e = {
stopPropagation: function () {},
};
var click_handler = $('.stream-list-filter').get_on_handler('click');
click_handler(e);
}());
});
(function test_sort_streams() {
run_test('sort_streams', () => {
stream_data.clear_subscriptions();
// Get coverage on early-exit.
@ -486,9 +486,9 @@ set_global('$', global.make_zjquery());
assert(stream_list.stream_sidebar.has_row_for(stream_id));
stream_list.remove_sidebar_row(stream_id);
assert(!stream_list.stream_sidebar.has_row_for(stream_id));
}());
});
(function test_separators_only_pinned_and_dormant() {
run_test('separators_only_pinned_and_dormant', () => {
// Test only pinned and dormant streams
@ -548,9 +548,9 @@ set_global('$', global.make_zjquery());
assert.deepEqual(appended_elems, expected_elems);
}());
});
(function test_separators_only_pinned() {
run_test('separators_only_pinned', () => {
// Test only pinned streams
@ -595,8 +595,8 @@ set_global('$', global.make_zjquery());
assert.deepEqual(appended_elems, expected_elems);
}());
(function test_update_count_in_dom() {
});
run_test('update_count_in_dom', () => {
function make_elem(elem, count_selector, value_selector) {
var count = $(count_selector);
var value = $(value_selector);
@ -663,11 +663,11 @@ set_global('$', global.make_zjquery());
topic: 'lunch',
count: 555,
});
}());
});
narrow_state.active = () => false;
(function test_rename_stream() {
run_test('rename_stream', () => {
const old_stream_id = stream_data.get_stream_id('devel');
const renamed_devel = {
name: 'Development',
@ -701,11 +701,11 @@ narrow_state.active = () => false;
stream_list.rename_stream(renamed_devel);
assert(count_updated);
}());
});
set_global('$', global.make_zjquery());
(function test_refresh_pin() {
run_test('refresh_pin', () => {
initialize_stream_data();
const sub = {
@ -737,9 +737,9 @@ set_global('$', global.make_zjquery());
stream_list.refresh_pinned_or_unpinned_stream(pinned_sub);
assert(scrolled);
}());
});
(function test_create_initial_sidebar_rows() {
run_test('create_initial_sidebar_rows', () => {
initialize_stream_data();
var html_dict = new Dict();
@ -763,4 +763,4 @@ set_global('$', global.make_zjquery());
assert.equal(html_dict.get(1000), '<div>stub-html-devel');
assert.equal(html_dict.get(5000), '<div>stub-html-Denmark');
}());
});

View File

@ -49,7 +49,7 @@ function toggle_filter() {
stream_list.toggle_filter_displayed({preventDefault: noop});
}
(function test_basics() {
run_test('basics', () => {
var cursor_helper;
const input = $('.stream-list-filter');
const header = $.create('header stub');
@ -162,9 +162,9 @@ function toggle_filter() {
stream_list.escape_search();
verify_collapsed();
}());
});
(function test_expanding_sidebar() {
run_test('expanding_sidebar', () => {
$('.app-main .column-left').removeClass('expanded');
const events = [];
@ -181,4 +181,4 @@ function toggle_filter() {
'popovers.hide_all',
'stream_popover.show_streamlist_sidebar',
]);
}());
});

View File

@ -3,10 +3,10 @@ zrequire('stream_data');
zrequire('stream_sort');
var with_overrides = global.with_overrides;
(function test_no_subscribed_streams() {
run_test('no_subscribed_streams', () => {
assert.equal(stream_sort.sort_groups(''), undefined);
assert.equal(stream_sort.first_stream_id(), undefined);
}());
});
const scalene = {
subscribed: true,

View File

@ -21,7 +21,7 @@ zrequire('bootstrap', 'third/bootstrap/js/bootstrap');
subs.stream_name_match_stream_ids = [];
subs.stream_description_match_stream_ids = [];
(function test_filter_table() {
run_test('filter_table', () => {
var denmark = {
subscribed: false,
name: 'Denmark',
@ -152,9 +152,9 @@ subs.stream_description_match_stream_ids = [];
assert.equal(subs.stream_description_match_stream_ids, 0);
assert.equal(subs.stream_name_match_stream_ids[0], 1);
assert.equal(subs.stream_name_match_stream_ids[1], 2);
}());
});
(function test_sub_or_unsub() {
run_test('sub_or_unsub', () => {
var denmark = {
subscribed: false,
name: 'Denmark',
@ -187,5 +187,5 @@ subs.stream_description_match_stream_ids = [];
assert.deepEqual(post_params.data,
{subscriptions: '["Denmark"]'});
}());
});

View File

@ -14,7 +14,7 @@ function render(template_name, args) {
return global.render_template(template_name, args);
}
(function test_finding_partials() {
run_test('finding_partials', () => {
var fns = global.find_included_partials('settings_tab');
assert.deepEqual(fns, [
'account-settings',
@ -25,9 +25,9 @@ function render(template_name, args) {
'attachments-settings',
'muted-topics-settings',
]);
}());
});
(function test_handlebars_bug() {
run_test('handlebars_bug', () => {
// There was a bug in 1.0.9 where identically structured
// blocks get confused, so when foo is false, it still
// renders the foo-is-true block.
@ -49,7 +49,7 @@ function render(template_name, args) {
var output = template({});
assert.equal(output, 'd'); // the buggy version would return 'b'
}());
});
(function actions_popover_content() {
var args = {

View File

@ -6,7 +6,7 @@ set_global('page_params' , {
zrequire('XDate', 'xdate');
zrequire('timerender');
(function test_render_now_returns_today() {
run_test('render_now_returns_today', () => {
var today = new XDate(1555091573000); // Friday 4/12/2019 5:52:53 PM (UTC+0)
var expected = {
time_str: i18n.t('Today'),
@ -17,9 +17,9 @@ zrequire('timerender');
assert.equal(expected.time_str, actual.time_str);
assert.equal(expected.formal_time_str, actual.formal_time_str);
assert.equal(expected.needs_update, actual.needs_update);
}());
});
(function test_render_now_returns_yesterday() {
run_test('render_now_returns_yesterday', () => {
var today = new XDate(1555091573000); // Friday 4/12/2019 5:52:53 PM (UTC+0)
var yesterday = today.clone().addDays(-1);
var expected = {
@ -31,9 +31,9 @@ zrequire('timerender');
assert.equal(expected.time_str, actual.time_str);
assert.equal(expected.formal_time_str, actual.formal_time_str);
assert.equal(expected.needs_update, actual.needs_update);
}());
});
(function test_render_now_returns_year() {
run_test('render_now_returns_year', () => {
var today = new XDate(1555091573000); // Friday 4/12/2019 5:52:53 PM (UTC+0)
var year_ago = today.clone().addYears(-1);
var expected = {
@ -45,9 +45,9 @@ zrequire('timerender');
assert.equal(expected.time_str, actual.time_str);
assert.equal(expected.formal_time_str, actual.formal_time_str);
assert.equal(expected.needs_update, actual.needs_update);
}());
});
(function test_render_now_returns_month_and_day() {
run_test('render_now_returns_month_and_day', () => {
var today = new XDate(1555091573000); // Friday 4/12/2019 5:52:53 PM (UTC+0)
var three_months_ago = today.clone().addMonths(-3, true);
var expected = {
@ -59,9 +59,9 @@ zrequire('timerender');
assert.equal(expected.time_str, actual.time_str);
assert.equal(expected.formal_time_str, actual.formal_time_str);
assert.equal(expected.needs_update, actual.needs_update);
}());
});
(function test_render_now_returns_year_with_year_boundary() {
run_test('render_now_returns_year_with_year_boundary', () => {
var today = new XDate(1555091573000); // Friday 4/12/2019 5:52:53 PM (UTC+0)
var three_months_ago = today.clone().addMonths(-6, true);
var expected = {
@ -73,9 +73,9 @@ zrequire('timerender');
assert.equal(expected.time_str, actual.time_str);
assert.equal(expected.formal_time_str, actual.formal_time_str);
assert.equal(expected.needs_update, actual.needs_update);
}());
});
(function test_render_date_renders_time_html() {
run_test('render_date_renders_time_html', () => {
var today = new XDate(1555091573000); // Friday 4/12/2019 5:52:53 PM (UTC+0)
var message_time = today.clone();
var expected_html = i18n.t('Today');
@ -97,9 +97,9 @@ zrequire('timerender');
assert.equal(expected_html, actual.html());
assert.equal(attrs.get('title'), 'Friday, April 12, 2019');
assert.equal(attrs.get('class'), 'timerender0');
}());
});
(function test_render_date_renders_time_above_html() {
run_test('render_date_renders_time_above_html', () => {
var today = new XDate(1555091573000); // Friday 4/12/2019 5:52:53 PM (UTC+0)
var message_time = today.clone();
var message_time_above = today.clone().addDays(-1);
@ -122,16 +122,16 @@ zrequire('timerender');
timerender.render_date(message_time, message_time_above, today);
assert.deepEqual(appended_val, expected);
}());
});
(function test_get_full_time() {
run_test('get_full_time', () => {
var timestamp = 1495091573; // 5/18/2017 7:12:53 AM (UTC+0)
var expected = '2017-05-18T07:12:53Z'; // ISO 8601 date format
var actual = timerender.get_full_time(timestamp);
assert.equal(expected, actual);
}());
});
(function test_absolute_time_12_hour() {
run_test('absolute_time_12_hour', () => {
set_global('page_params', {
twenty_four_hour_time: false,
});
@ -161,9 +161,9 @@ zrequire('timerender');
expected = 'May 18, 2017 07:12 AM';
actual = timerender.absolute_time(timestamp, today);
assert.equal(expected, actual);
}());
});
(function test_absolute_time_24_hour() {
run_test('absolute_time_24_hour', () => {
set_global('page_params', {
twenty_four_hour_time: true,
});
@ -193,9 +193,9 @@ zrequire('timerender');
expected = 'May 18, 2017 07:12';
actual = timerender.absolute_time(timestamp, today);
assert.equal(expected, actual);
}());
});
(function test_set_full_datetime() {
run_test('set_full_datetime', () => {
var message = {
timestamp: 1495091573, // 2017-5-18 07:12:53 AM (UTC+0)
};
@ -218,9 +218,9 @@ zrequire('timerender');
timerender.set_full_datetime(message, time_element);
var actual = attrs.get('title');
assert.equal(expected, actual);
}());
});
(function test_last_seen_status_from_date() {
run_test('last_seen_status_from_date', () => {
// Set base_dateto to March 1 2016 12.30 AM (months are zero based)
var base_date = new XDate(2016, 2, 1, 0, 30);
@ -270,9 +270,9 @@ zrequire('timerender');
assert_same(function (d) { return d.addYears(-3); },
i18n.t("Last seen on Mar 01, 2013"));
}());
});
(function test_set_full_datetime() {
run_test('set_full_datetime', () => {
var time = new XDate(1549958107000); // Tuesday 2/12/2019 07:55:07 AM (UTC+0)
var time_str = timerender.stringify_time(time);
var expected = '07:55';
@ -288,4 +288,4 @@ zrequire('timerender');
time_str = timerender.stringify_time(time);
expected = '1:55 PM';
assert.equal(expected, time_str);
}());
});

View File

@ -5,7 +5,7 @@ zrequire('unread_ui');
zrequire('top_left_corner');
(function test_narrowing() {
run_test('narrowing', () => {
// activating narrow
var pm_expanded;
@ -45,9 +45,9 @@ zrequire('top_left_corner');
assert(!top_left_corner.get_global_filter_li('private').hasClass('active-filter'));
assert(!top_left_corner.get_global_filter_li('starred').hasClass('active-filter'));
assert(pm_closed);
}());
});
(function test_update_count_in_dom() {
run_test('update_count_in_dom', () => {
function make_elem(elem, count_selector, value_selector) {
var count = $(count_selector);
var value = $(value_selector);
@ -86,4 +86,4 @@ zrequire('top_left_corner');
assert(!$('<mentioned-count>').visible());
assert.equal($('<mentioned-value>').text(), '');
}());
});

View File

@ -2,7 +2,7 @@ zrequire('topic_data');
set_global('channel', {});
(function test_basics() {
run_test('basics', () => {
var stream_id = 55;
topic_data.add_message({
@ -58,9 +58,9 @@ set_global('channel', {});
topic_data.remove_message({
stream_id: 9999999,
});
}());
});
(function test_server_history() {
run_test('server_history', () => {
var stream_id = 66;
topic_data.add_message({
@ -124,11 +124,11 @@ set_global('channel', {});
]);
history = topic_data.get_recent_names(stream_id);
assert.deepEqual(history, ['hist2', 'hist1', 'hist3']);
}());
});
(function test_server_history_end_to_end() {
run_test('server_history_end_to_end', () => {
topic_data.reset();
var stream_id = 99;
@ -158,4 +158,4 @@ set_global('channel', {});
var history = topic_data.get_recent_names(stream_id);
assert.deepEqual(history, ['topic3', 'topic2', 'topic1']);
}());
});

View File

@ -13,7 +13,7 @@ var tg = zrequire('topic_generator');
function is_even(i) { return i % 2 === 0; }
function is_odd(i) { return i % 2 === 1; }
(function test_basics() {
run_test('basics', () => {
var gen = tg.list_generator([10, 20, 30]);
assert.equal(gen.next(), 10);
assert.equal(gen.next(), 20);
@ -78,9 +78,9 @@ function is_odd(i) { return i % 2 === 1; }
gen = tg.map(ints, mult10);
assert.equal(gen.next(), 100);
assert.equal(gen.next(), 200);
}());
});
(function test_reverse() {
run_test('reverse', () => {
var gen = tg.reverse_list_generator([10, 20, 30]);
assert.equal(gen.next(), 30);
assert.equal(gen.next(), 20);
@ -139,9 +139,9 @@ function is_odd(i) { return i % 2 === 1; }
assert.equal(gen.next(), 5);
assert.equal(gen.next(), undefined);
assert.equal(gen.next(), undefined);
}());
});
(function test_fchain() {
run_test('fchain', () => {
var mults = function (n) {
var ret = 0;
return {
@ -184,9 +184,9 @@ function is_odd(i) { return i % 2 === 1; }
ints = tg.list_generator([29, 43]);
gen = tg.fchain(ints, undef);
gen.next();
}());
});
(function test_streams() {
run_test('streams', () => {
function assert_next_stream(curr_stream, expected) {
var actual = tg.get_next_stream(curr_stream);
assert.equal(actual, expected);
@ -211,9 +211,9 @@ function is_odd(i) { return i % 2 === 1; }
assert_prev_stream('test here', 'devel');
assert_prev_stream('announce', 'test here');
}());
});
(function test_topics() {
run_test('topics', () => {
var streams = [1, 2, 3, 4];
var topics = {};
@ -306,9 +306,9 @@ function is_odd(i) { return i % 2 === 1; }
stream: 'muted',
topic: 'ms-topic1',
});
}());
});
(function test_get_next_unread_pm_string() {
run_test('get_next_unread_pm_string', () => {
pm_conversations.recent.get_strings = function () {
return ['1', 'read', '2,3', '4', 'unk'];
};
@ -332,4 +332,4 @@ function is_odd(i) { return i % 2 === 1; }
assert.equal(tg.get_next_unread_pm_string('1'), '2,3');
assert.equal(tg.get_next_unread_pm_string('read'), '2,3');
assert.equal(tg.get_next_unread_pm_string('2,3'), '4');
}());
});

View File

@ -14,7 +14,7 @@ zrequire('stream_data');
zrequire('topic_data');
zrequire('topic_list');
(function test_topic_list_build_widget() {
run_test('topic_list_build_widget', () => {
var stream_id = 555;
topic_data.reset();
@ -100,4 +100,4 @@ zrequire('topic_list');
assert.equal(list_items[1].html(), '<more topics>');
assert(attached_to_parent);
}());
});

View File

@ -40,7 +40,7 @@ function test_with_mock_socket(test_params) {
test_params.check_send_args(send_args);
}
(function test_transmit_message_sockets() {
run_test('transmit_message_sockets', () => {
page_params.use_websockets = true;
global.navigator.userAgent = 'unittest_transmit_message';
@ -86,11 +86,11 @@ function test_with_mock_socket(test_params) {
assert(error_func_checked);
},
});
}());
});
page_params.use_websockets = false;
(function test_transmit_message_ajax() {
run_test('transmit_message_ajax', () => {
var success_func_called;
var success = function () {
@ -128,9 +128,9 @@ page_params.use_websockets = false;
};
transmit.send_message(request, success, error);
assert(error_func_called);
}());
});
(function test_transmit_message_ajax_reload_pending() {
run_test('transmit_message_ajax_reload_pending', () => {
var success = function () { throw 'unexpected success'; };
reload.is_pending = function () {
@ -167,4 +167,4 @@ page_params.use_websockets = false;
transmit.send_message(request, success, error);
assert(!error_func_called);
assert(reload_initiated);
}());
});

View File

@ -21,7 +21,7 @@ stream_data.create_streams([
{name: 'Linux', subscribed: true, color: 'red', stream_id: 2},
]);
(function test_sort_streams() {
run_test('sort_streams', () => {
var popular = {num_items: function () {
return 10;
}};
@ -84,9 +84,9 @@ stream_data.create_streams([
assert.deepEqual(test_streams[3].name, "Ether"); // Unsubscribed and description starts with query
assert.deepEqual(test_streams[4].name, "New"); // Subscribed and no match
assert.deepEqual(test_streams[5].name, "Mew"); // Unsubscribed and no match
}());
});
(function test_sort_languages() {
run_test('sort_languages', () => {
set_global('pygments_data', {langs:
{python: 40, javscript: 50, php: 38, pascal: 29, perl: 22, css: 0},
});
@ -103,7 +103,7 @@ stream_data.create_streams([
test_langs = th.sort_languages(test_langs, "p");
assert.deepEqual(test_langs, ["php", "python", "pascal", "perl", "javascript"]);
}());
});
var matches = [
{
@ -155,7 +155,7 @@ _.each(matches, function (person) {
global.people.add_in_realm(person);
});
(function test_sort_recipients() {
run_test('sort_recipients', () => {
function get_typeahead_result(query, current_stream, current_topic) {
var result = th.sort_recipients(
global.people.get_realm_persons(),
@ -377,9 +377,9 @@ _.each(matches, function (person) {
'b_user_2@zulip.net',
];
assert.deepEqual(recipients_email, expected);
}());
});
(function test_highlight_with_escaping() {
run_test('highlight_with_escaping', () => {
var item = "Denmark";
var query = "Den";
var expected = "<strong>Den</strong>mark";
@ -397,9 +397,9 @@ _.each(matches, function (person) {
expected = "<strong>development h</strong>elp";
result = th.highlight_with_escaping(query, item);
assert.equal(result, expected);
}());
});
(function test_render_person() {
run_test('render_person', () => {
// Test render_person with regular person
var rendered = false;
global.templates.render = function (template_name, args) {
@ -430,9 +430,9 @@ _.each(matches, function (person) {
};
assert.equal(th.render_person(special_person), 'typeahead-item-stub');
assert(rendered);
}());
});
(function test_clear_rendered_person() {
run_test('clear_rendered_person', () => {
var rendered = false;
global.templates.render = function (template_name, args) {
assert.equal(template_name, 'typeahead_list_item');
@ -456,9 +456,9 @@ _.each(matches, function (person) {
assert.equal(th.render_person(matches[5]), 'typeahead-item-stub');
assert(rendered);
}());
});
(function test_render_stream() {
run_test('render_stream', () => {
// Test render_stream with short description
var rendered = false;
var stream = {
@ -493,9 +493,9 @@ _.each(matches, function (person) {
};
assert.equal(th.render_stream(stream), 'typeahead-item-stub');
assert(rendered);
}());
});
(function test_render_emoji() {
run_test('render_emoji', () => {
// Test render_emoji with normal emoji.
var rendered = false;
var emoji = {
@ -544,9 +544,9 @@ _.each(matches, function (person) {
};
assert.equal(th.render_emoji(emoji), 'typeahead-item-stub');
assert(rendered);
}());
});
(function test_sort_emojis() {
run_test('sort_emojis', () => {
var emoji_list = [
{ emoji_name: '+1' },
{ emoji_name: 'thumbs_up' },
@ -559,9 +559,9 @@ _.each(matches, function (person) {
{ emoji_name: '+1' },
{ emoji_name: 'pig' },
]);
}());
});
(function test_sort_recipientbox_typeahead() {
run_test('sort_recipientbox_typeahead', () => {
var recipients = th.sort_recipientbox_typeahead("b, a", matches, ""); // search "a"
var recipients_email = _.map(recipients, function (person) {
return person.email;
@ -589,4 +589,4 @@ _.each(matches, function (person) {
'zman@test.net',
'a_bot@zulip.com',
]);
}());
});

View File

@ -1,7 +1,7 @@
zrequire("util");
zrequire("typing_data");
(function test_basics() {
run_test('basics', () => {
// The typing_data needs to be robust with lists of
// user ids being in arbitrary sorting order and
// possibly in string form instead of integer. So all
@ -44,10 +44,10 @@ zrequire("typing_data");
// test duplicate ids in a groups
typing_data.add_typist([20, 40, 20], 20);
assert.deepEqual(typing_data.get_group_typists([20, 40]), [20]);
}());
});
(function test_timers() {
run_test('timers', () => {
var events = {};
var stub_timer_id = 'timer_id_stub';
@ -118,5 +118,5 @@ zrequire("typing_data");
timer_set: false,
});
}());
});

View File

@ -14,7 +14,7 @@ function returns_time(secs) {
return function () { return make_time(secs); };
}
(function test_basics() {
run_test('basics', () => {
// invalid conversation basically does nothing
var worker = {
@ -277,4 +277,4 @@ function returns_time(secs) {
});
assert(events.idle_callback);
}());
});

View File

@ -31,7 +31,7 @@ var zero_counts = {
pm_count: new Dict(),
};
(function test_empty_counts_while_narrowed() {
run_test('empty_counts_while_narrowed', () => {
narrow_state.active = function () {
return true;
};
@ -41,9 +41,9 @@ var zero_counts = {
var counts = unread.get_counts();
assert.deepEqual(counts, zero_counts);
}());
});
(function test_empty_counts_while_home() {
run_test('empty_counts_while_home', () => {
narrow_state.active = function () {
return false;
};
@ -53,9 +53,9 @@ var zero_counts = {
var counts = unread.get_counts();
assert.deepEqual(counts, zero_counts);
}());
});
(function test_changing_subjects() {
run_test('changing_subjects', () => {
// Summary: change the subject of a message from 'lunch'
// to 'dinner' using update_unread_topics().
var count = unread.num_unread_for_topic('social', 'lunch');
@ -188,13 +188,13 @@ var zero_counts = {
// test coverage
unread.update_unread_topics(sticky_message, {});
}());
});
stream_data.get_stream_id = function () {
return 999;
};
(function test_muting() {
run_test('muting', () => {
stream_data.is_subscribed = function () {
return true;
};
@ -240,9 +240,9 @@ stream_data.get_stream_id = function () {
assert.deepEqual(unread.get_all_msg_ids(), [message.id]);
assert.equal(unread.num_unread_for_stream(unknown_stream_id), 0);
}());
});
(function test_num_unread_for_topic() {
run_test('num_unread_for_topic', () => {
// Test the num_unread_for_topic() function using many
// messages.
unread.declare_bankruptcy();
@ -296,10 +296,10 @@ stream_data.get_stream_id = function () {
msg_ids = unread.get_msg_ids_for_stream(stream_id);
assert.deepEqual(msg_ids, []);
}());
});
(function test_home_messages() {
run_test('home_messages', () => {
narrow_state.active = function () {
return false;
};
@ -353,9 +353,9 @@ stream_data.get_stream_id = function () {
counts = unread.get_counts();
assert.equal(counts.home_unread_messages, 0);
}());
});
(function test_phantom_messages() {
run_test('phantom_messages', () => {
var message = {
id: 999,
type: 'stream',
@ -368,9 +368,9 @@ stream_data.get_stream_id = function () {
unread.mark_as_read(message.id);
var counts = unread.get_counts();
assert.equal(counts.home_unread_messages, 0);
}());
});
(function test_private_messages() {
run_test('private_messages', () => {
narrow_state.active = function () {
return false;
};
@ -407,9 +407,9 @@ stream_data.get_stream_id = function () {
counts = unread.get_counts();
assert.equal(counts.private_message_count, 0);
assert.equal(counts.pm_count.get('999'), 0);
}());
});
(function test_private_messages() {
run_test('private_messages', () => {
var alice = {
email: 'alice@example.com',
user_id: 101,
@ -450,10 +450,10 @@ stream_data.get_stream_id = function () {
assert.deepEqual(unread.get_msg_ids_for_person(bob.user_id), []);
assert.deepEqual(unread.get_msg_ids_for_private(), [message.id]);
assert.deepEqual(unread.get_all_msg_ids(), [message.id]);
}());
});
(function test_mentions() {
run_test('mentions', () => {
narrow_state.active = function () {
return false;
};
@ -483,15 +483,15 @@ stream_data.get_stream_id = function () {
unread.mark_as_read(message.id);
counts = unread.get_counts();
assert.equal(counts.mentioned_message_count, 0);
}());
});
(function test_starring() {
run_test('starring', () => {
// We don't need any setup here, because we just hard code
// this to [] in the code.
assert.deepEqual(unread.get_msg_ids_for_starred(), []);
}());
});
(function test_declare_bankruptcy() {
run_test('declare_bankruptcy', () => {
var message = {
id: 16,
type: 'whatever',
@ -506,16 +506,16 @@ stream_data.get_stream_id = function () {
var counts = unread.get_counts();
assert.deepEqual(counts, zero_counts);
}());
});
(function test_message_unread() {
run_test('message_unread', () => {
// Test some code that might be overly defensive, for line coverage sake.
assert(!unread.message_unread(undefined));
assert(unread.message_unread({unread: true}));
assert(!unread.message_unread({unread: false}));
}());
});
(function test_server_counts() {
run_test('server_counts', () => {
// note that user_id 30 is "me"
page_params.unread_msgs = {
@ -568,9 +568,9 @@ stream_data.get_stream_id = function () {
unread.mark_as_read(34);
assert.equal(unread.num_unread_for_person('4,6,101'), 1);
}());
});
(function test_empty_cases() {
run_test('empty_cases', () => {
unread.declare_bankruptcy();
const stream_id = 999;
@ -580,9 +580,9 @@ stream_data.get_stream_id = function () {
msg_ids = unread.get_msg_ids_for_stream(stream_id);
assert.deepEqual(msg_ids, []);
assert.deepEqual(unread.get_all_msg_ids(), []);
}());
});
(function test_errors() {
run_test('errors', () => {
unread.declare_bankruptcy();
global.blueslip.warn = function () {};
@ -597,5 +597,5 @@ stream_data.get_stream_id = function () {
unread.mark_as_read(message.id);
var counts = unread.get_counts();
assert.equal(counts.private_message_count, 0);
}());
});

View File

@ -24,7 +24,7 @@ zrequire('upload');
var upload_opts = upload.options({ mode: "compose" });
(function test_upload_started() {
run_test('upload_started', () => {
$("#compose-send-button").prop('disabled', false);
$("#compose-send-status").removeClass("alert-info").hide();
$(".compose-send-status-close").one = function (ev_name, handler) {
@ -46,9 +46,9 @@ var upload_opts = upload.options({ mode: "compose" });
assert($("#compose-send-status").hasClass("alert-info"));
assert($("#compose-send-status").visible());
assert.equal($("<p>").text(), 'translated: Uploading…');
}());
});
(function test_progress_updated() {
run_test('progress_updated', () => {
var width_update_checked = false;
$("#compose-upload-bar-1549958107000").width = function (width_percent) {
assert.equal(width_percent, '39%');
@ -56,9 +56,9 @@ var upload_opts = upload.options({ mode: "compose" });
};
upload_opts.progressUpdated(1, {lastModified: 1549958107000}, 39);
assert(width_update_checked);
}());
});
(function test_upload_error() {
run_test('upload_error', () => {
function setup_test() {
$("#compose-send-status").removeClass("alert-error");
$("#compose-send-status").addClass("alert-info");
@ -97,9 +97,9 @@ var upload_opts = upload.options({ mode: "compose" });
test(413, msg_prefix + msg_4);
test(400, 'ちょっと…', {msg: 'ちょっと…'});
test('Do-not-match-any-case', msg_prefix + msg_5);
}());
});
(function test_upload_finish() {
run_test('upload_finish', () => {
function test(i, response, textbox_val) {
var compose_ui_autosize_textarea_checked = false;
var compose_actions_start_checked = false;
@ -172,4 +172,4 @@ var upload_opts = upload.options({ mode: "compose" });
test(-1, {}, '');
test(-1, {uri: 'https://foo.com/uploads/122456'}, msg_1);
test(1, {uri: '/user_uploads/foobar.jpeg'}, msg_2);
}());
});

View File

@ -53,7 +53,7 @@ function initialize() {
initialize();
(function test_updates() {
run_test('updates', () => {
var person;
var isaac = {
@ -141,4 +141,4 @@ initialize();
user_events.update_person({user_id: me.user_id, custom_profile_field: {id: 3, value: 'Value'}});
person = people.get_by_email(me.email);
assert.equal(person.profile_data[3], 'Value');
}());
});

View File

@ -4,7 +4,7 @@ set_global('page_params', {});
zrequire('dict');
zrequire('user_groups');
(function test_user_groups() {
run_test('user_groups', () => {
var students = {
name: 'Students',
id: 0,
@ -92,4 +92,4 @@ zrequire('user_groups');
user_groups.init();
assert.equal(user_groups.get_realm_user_groups().length, 0);
}());
});

View File

@ -32,7 +32,7 @@ var isaac_item = {
people.add_in_realm(isaac);
}());
(function test_create_item() {
run_test('create_item', () => {
function test_create_item(email, current_items, expected_item) {
var item = user_pill.create_item_from_email(email, current_items);
@ -52,13 +52,13 @@ var isaac_item = {
test_create_item('bogus@example.com', [], undefined);
test_create_item('isaac@example.com', [], isaac_item);
test_create_item('isaac@example.com', [isaac_item], undefined);
}());
});
(function test_get_email() {
run_test('get_email', () => {
assert.equal(user_pill.get_email_from_item({email: 'foo@example.com'}), 'foo@example.com');
}());
});
(function test_append() {
run_test('append', () => {
var appended;
var cleared;
@ -85,9 +85,9 @@ var isaac_item = {
assert(appended);
assert(cleared);
}());
});
(function test_get_items() {
run_test('get_items', () => {
var items = [isaac_item, bogus_item];
var pill_widget = {
@ -95,9 +95,9 @@ var isaac_item = {
};
assert.deepEqual(user_pill.get_user_ids(pill_widget), [isaac.user_id]);
}());
});
(function test_typeahead() {
run_test('typeahead', () => {
var items = [isaac_item, bogus_item];
var pill_widget = {
@ -109,4 +109,4 @@ var isaac_item = {
// And then bogus_item is just a red herring to test robustness.
var result = user_pill.typeahead_source(pill_widget);
assert.deepEqual(result, [alice]);
}());
});

View File

@ -4,7 +4,7 @@ set_global('window', {});
zrequire('util');
(function test_CachedValue() {
run_test('CachedValue', () => {
var x = 5;
var cv = new util.CachedValue({
@ -20,27 +20,27 @@ zrequire('util');
cv.reset();
assert.equal(cv.get(), 12);
}());
});
(function test_extract_pm_recipients() {
run_test('extract_pm_recipients', () => {
assert.equal(util.extract_pm_recipients('bob@foo.com, alice@foo.com').length, 2);
assert.equal(util.extract_pm_recipients('bob@foo.com, ').length, 1);
}());
});
(function test_is_pm_recipient() {
run_test('is_pm_recipient', () => {
var message = { reply_to: 'alice@example.com,bOb@exaMple.com,fred@example.com' };
assert(util.is_pm_recipient('alice@example.com', message));
assert(util.is_pm_recipient('bob@example.com', message));
assert(!util.is_pm_recipient('unknown@example.com', message));
}());
});
(function test_rtrim() {
run_test('rtrim', () => {
assert.equal(util.rtrim('foo'), 'foo');
assert.equal(util.rtrim(' foo'), ' foo');
assert.equal(util.rtrim('foo '), 'foo');
}());
});
(function test_lower_bound() {
run_test('lower_bound', () => {
var arr = [10, 20, 30, 40, 50];
assert.equal(util.lower_bound(arr, 5), 0);
assert.equal(util.lower_bound(arr, 10), 0);
@ -59,9 +59,9 @@ zrequire('util');
assert.equal(util.lower_bound(arr, 10, compare), 0);
assert.equal(util.lower_bound(arr, 15, compare), 1);
}());
});
(function test_same_recipient() {
run_test('same_recipient', () => {
assert(util.same_recipient(
{type: 'stream', stream_id: 101, subject: 'Bar'},
{type: 'stream', stream_id: 101, subject: 'bar'}));
@ -95,9 +95,9 @@ zrequire('util');
{type: 'private'}));
assert(!util.same_recipient(undefined, undefined));
}());
});
(function test_robust_uri_decode() {
run_test('robust_uri_decode', () => {
assert.equal(util.robust_uri_decode('xxx%3Ayyy'), 'xxx:yyy');
assert.equal(util.robust_uri_decode('xxx%3'), 'xxx');
@ -107,39 +107,39 @@ zrequire('util');
} catch (e) {
assert(e, 'foo');
}
}());
});
(function test_dumb_strcmp() {
run_test('dumb_strcmp', () => {
Intl.Collator = undefined;
var strcmp = util.make_strcmp();
assert.equal(strcmp('a', 'b'), -1);
assert.equal(strcmp('c', 'c'), 0);
assert.equal(strcmp('z', 'y'), 1);
}());
});
(function test_is_mobile() {
run_test('is_mobile', () => {
global.window.navigator = { userAgent: "Android" };
assert(util.is_mobile());
global.window.navigator = { userAgent: "Not mobile" };
assert(!util.is_mobile());
}());
});
(function test_array_compare() {
run_test('array_compare', () => {
assert(util.array_compare([], []));
assert(util.array_compare([1,2,3], [1,2,3]));
assert(!util.array_compare([1,2], [1,2,3]));
assert(!util.array_compare([1,2,3], [1,2]));
assert(!util.array_compare([1,2,3,4], [1,2,3,5]));
}());
});
(function test_normalize_recipients() {
run_test('normalize_recipients', () => {
assert.equal(
util.normalize_recipients('ZOE@foo.com, bob@foo.com, alice@foo.com, AARON@foo.com '),
'aaron@foo.com,alice@foo.com,bob@foo.com,zoe@foo.com');
}());
});
(function test_random_int() {
run_test('random_int', () => {
var min = 0;
var max = 100;
@ -149,9 +149,9 @@ zrequire('util');
assert(val <= max);
assert.equal(val, Math.floor(val));
});
}());
});
(function test_all_and_everyone_mentions_regexp() {
run_test('all_and_everyone_mentions_regexp', () => {
var messages_with_all_mentions = [
'@**all**',
'some text before @**all** some text after',
@ -224,9 +224,9 @@ zrequire('util');
for (i=0; i<messages_without_stream_mentions.length; i += 1) {
assert(!util.is_all_or_everyone_mentioned(messages_without_stream_mentions[i]));
}
}());
});
(function test_move_array_elements_to_front() {
run_test('move_array_elements_to_front', () => {
var strings = [
'string1',
'string3',
@ -280,4 +280,4 @@ zrequire('util');
for (i = 0; i < emails_actual.length; i += 1) {
assert(emails_actual[i] === emails_expected[i]);
}
}());
});

View File

@ -30,7 +30,7 @@ set_global('blueslip', global.make_zblueslip());
// set_global('blueslip', global.make_zblueslip({debug: true}));
// Similarly, you can ignore tests for errors by passing {debug: true, error: false}.
(function test_basics() {
run_test('basics', () => {
// Let's create a sample piece of code to test:
function throw_an_error() {
blueslip.error('world');
@ -85,4 +85,4 @@ set_global('blueslip', global.make_zblueslip());
throw_a_warning();
assert.equal(blueslip.get_test_logs('warn').length, 1);
blueslip.clear_test_data();
}());
});

View File

@ -27,7 +27,7 @@ The code we are testing lives here:
set_global('$', global.make_zjquery());
(function test_basics() {
run_test('basics', () => {
// Let's create a sample piece of code to test:
function show_my_form() {
@ -56,9 +56,9 @@ set_global('$', global.make_zjquery());
widget.val('42');
assert.equal(widget.val(), '42');
}());
});
(function test_finding_related_objects() {
run_test('finding_related_objects', () => {
// Let's say you have a function like the following:
function update_message_emoji(emoji_src) {
$('#my-message').find('.emoji').attr('src', emoji_src);
@ -95,9 +95,9 @@ set_global('$', global.make_zjquery());
elem.parents('.folder').addClass('active');
assert(my_parents.hasClass('active'));
}());
});
(function test_clicks() {
run_test('clicks', () => {
// We can support basic handlers like click and keydown.
var state = {};
@ -125,9 +125,9 @@ set_global('$', global.make_zjquery());
$('.some-class').keydown();
assert.equal(state.keydown, true);
}());
});
(function test_events() {
run_test('events', () => {
// Zulip's codebase uses jQuery's event API heavily with anonymous
// functions that are hard for naive test code to cover. zjquery
// will come to our rescue.
@ -159,9 +159,9 @@ set_global('$', global.make_zjquery());
// And verify it did what it was supposed to do.
assert.equal(value, 42);
}());
});
(function test_create() {
run_test('create', () => {
// You can create jQuery objects that aren't tied to any particular
// selector, and which just have a name.
@ -173,9 +173,9 @@ set_global('$', global.make_zjquery());
obj2.addClass('.striped');
assert(obj2.hasClass('.striped'));
}());
});
(function test_extensions() {
run_test('extensions', () => {
// You can extend $.fn so that all subsequent objects
// we create get a new function.
@ -196,4 +196,4 @@ set_global('$', global.make_zjquery());
// But we also have area available from general extension.
assert.equal(rect.area(), 35);
}());
});

View File

@ -72,7 +72,7 @@ function short_tb(tb) {
const lines = tb.split('\n');
var i = _.findIndex(lines, (line) => {
return line.includes('run_one_module');
return line.includes('run_test') || line.includes('run_one_module');
});
if (i === -1) {
@ -90,6 +90,13 @@ function run_one_module(file) {
require(file.full_name);
}
global.run_test = (label, f) => {
if (files.length === 1) {
console.info(' test: ' + label);
}
f();
};
try {
files.forEach(function (file) {
global.patch_builtin('setTimeout', noop);