lint: Add JS indentation eslint rules for node_tests.

The only difference between this as the main project's lint rules is
that we dont have the OuterIIFE setting.
This commit is contained in:
Tim Abbott 2018-05-06 18:30:13 -07:00
parent ed299feb00
commit 6e149a7594
30 changed files with 490 additions and 443 deletions

View File

@ -1,5 +1,12 @@
{
"rules": {
"indent": 0
"indent": ["error", 4, {
"ArrayExpression": "first",
"ObjectExpression": "first",
"SwitchCase": 0,
"CallExpression": {"arguments": "first"},
"FunctionExpression": {"parameters": "first"},
"FunctionDeclaration": {"parameters": "first"}
}]
}
}

View File

@ -266,18 +266,18 @@ presence.presence_info = presence_info;
activity.huddle_fraction_present(huddle),
'0.50');
huddle = 'alice@zulip.com,fred@zulip.com,jill@zulip.com,mark@zulip.com';
huddle = people.emails_strings_to_user_ids_string(huddle);
presence_info = {};
presence_info[alice.user_id] = { status: 'idle' };
presence_info[fred.user_id] = { status: 'idle' }; // does not count as present
// jill not in list
presence_info[mark.user_id] = { status: 'offline' }; // does not count
presence.presence_info = presence_info;
huddle = 'alice@zulip.com,fred@zulip.com,jill@zulip.com,mark@zulip.com';
huddle = people.emails_strings_to_user_ids_string(huddle);
presence_info = {};
presence_info[alice.user_id] = { status: 'idle' };
presence_info[fred.user_id] = { status: 'idle' }; // does not count as present
// jill not in list
presence_info[mark.user_id] = { status: 'offline' }; // does not count
presence.presence_info = presence_info;
assert.equal(
activity.huddle_fraction_present(huddle),
false);
assert.equal(
activity.huddle_fraction_present(huddle),
false);
}());
presence.presence_info = {};
@ -307,7 +307,8 @@ reset_setup();
compose_fade.set_focused_recipient("private");
const users = activity.build_user_sidebar();
assert.deepEqual(users, [{
assert.deepEqual(users, [
{
name: 'Fred Flintstone',
href: '#narrow/pm-with/2-fred',
user_id: fred.user_id,
@ -839,45 +840,44 @@ reset_setup();
}());
(function test_initialize() {
$.stub_selector('html', {
on: function (name, func) {
func();
},
});
$(window).focus = func => func();
$(window).idle = () => {};
$.stub_selector('html', {
on: function (name, func) {
func();
},
});
$(window).focus = func => func();
$(window).idle = () => {};
channel.post = function (payload) {
payload.success({});
};
global.server_events = {
check_for_unsuspend: function () {},
};
activity.has_focus = false;
activity.initialize();
assert(!activity.new_user_input);
assert(!$('#zephyr-mirror-error').hasClass('show'));
assert.equal(page_params.presences, undefined);
assert(activity.has_focus);
$(window).idle = function (params) {
params.onIdle();
};
channel.post = function (payload) {
payload.success({
zephyr_mirror_active: false,
});
};
global.setInterval = (func) => func();
channel.post = function (payload) {
payload.success({});
};
global.server_events = {
check_for_unsuspend: function () {},
};
activity.has_focus = false;
activity.initialize();
assert(!activity.new_user_input);
assert(!$('#zephyr-mirror-error').hasClass('show'));
assert.equal(page_params.presences, undefined);
assert(activity.has_focus);
$(window).idle = function (params) {
params.onIdle();
};
channel.post = function (payload) {
payload.success({
zephyr_mirror_active: false,
});
};
global.setInterval = (func) => func();
activity.initialize();
assert($('#zephyr-mirror-error').hasClass('show'));
assert(!activity.new_user_input);
assert(!activity.has_focus);
// Now execute the reload-in-progress code path
reload.is_in_progress = function () {
return true;
};
activity.initialize();
activity.initialize();
assert($('#zephyr-mirror-error').hasClass('show'));
assert(!activity.new_user_input);
assert(!activity.has_focus);
// Now execute the reload-in-progress code path
reload.is_in_progress = function () {
return true;
};
activity.initialize();
}());

View File

@ -18,30 +18,62 @@ global.people.add({
global.people.initialize_current_user(42);
const regular_message = { sender_email: 'another@zulip.com', content: '<p>a message</p>'};
const own_message = { sender_email: 'tester@zulip.com', content: '<p>hey this message alertone</p>',
alerted: true };
const other_message = { sender_email: 'another@zulip.com', content: '<p>another alertone message</p>',
alerted: true };
const caps_message = { sender_email: 'another@zulip.com', content: '<p>another ALERTtwo message</p>',
alerted: true };
const alertwordboundary_message = { sender_email: 'another@zulip.com',
content: '<p>another alertthreemessage</p>', alerted: false };
const multialert_message = { sender_email: 'another@zulip.com', content:
'<p>another alertthreemessage alertone and then alerttwo</p>',
alerted: true };
const unsafe_word_message = { sender_email: 'another@zulip.com', content: '<p>gotta al*rt.*s all</p>',
alerted: true };
const alert_in_url_message = { sender_email: 'another@zulip.com', content: '<p>http://www.google.com/alertone/me</p>',
alerted: true };
const question_word_message = { sender_email: 'another@zulip.com', content: '<p>still alertone? me</p>',
alerted: true };
const regular_message = {
sender_email: 'another@zulip.com',
content: '<p>a message</p>',
};
const own_message = {
sender_email: 'tester@zulip.com',
content: '<p>hey this message alertone</p>',
alerted: true,
};
const other_message = {
sender_email: 'another@zulip.com',
content: '<p>another alertone message</p>',
alerted: true,
};
const caps_message = {
sender_email: 'another@zulip.com',
content: '<p>another ALERTtwo message</p>',
alerted: true,
};
const alertwordboundary_message = {
sender_email: 'another@zulip.com',
content: '<p>another alertthreemessage</p>',
alerted: false,
};
const multialert_message = {
sender_email: 'another@zulip.com',
content: '<p>another alertthreemessage alertone and then alerttwo</p>',
alerted: true,
};
const unsafe_word_message = {
sender_email: 'another@zulip.com',
content: '<p>gotta al*rt.*s all</p>',
alerted: true,
};
const alert_in_url_message = {
sender_email: 'another@zulip.com',
content: '<p>http://www.google.com/alertone/me</p>',
alerted: true,
};
const question_word_message = {
sender_email: 'another@zulip.com',
content: '<p>still alertone? me</p>',
alerted: true,
};
const alert_domain_message = { sender_email: 'another@zulip.com', content: '<p>now with link <a href="http://www.alerttwo.us/foo/bar" target="_blank" title="http://www.alerttwo.us/foo/bar">www.alerttwo.us/foo/bar</a></p>',
alerted: true };
const alert_domain_message = {
sender_email: 'another@zulip.com',
content: '<p>now with link <a href="http://www.alerttwo.us/foo/bar" target="_blank" title="http://www.alerttwo.us/foo/bar">www.alerttwo.us/foo/bar</a></p>',
alerted: true,
};
// This test ensure we are not mucking up rendered HTML content.
const message_with_emoji = { sender_email: 'another@zulip.com', content: '<p>I <img alt=":heart:" class="emoji" src="/static/generated/emoji/images/emoji/unicode/2764.png" title="heart"> emoji!</p>',
alerted: true };
const message_with_emoji = {
sender_email: 'another@zulip.com',
content: '<p>I <img alt=":heart:" class="emoji" src="/static/generated/emoji/images/emoji/unicode/2764.png" title="heart"> emoji!</p>',
alerted: true,
};
(function test_notifications() {
assert(!alert_words.notifies(regular_message));

View File

@ -280,7 +280,8 @@ function test_with_mock_ajax(test_params) {
};
blueslip.set_test_data('warn',
'The length of pending_requests is over 50. Most likely they are not being correctly removed.');
'The length of pending_requests is over 50. ' +
'Most likely they are not being correctly removed.');
_.times(50, function () {
channel.post({});
});

View File

@ -516,18 +516,18 @@ people.add(bob);
};
transmit.send_message = function (payload, success) {
var single_msg = {
type: 'private',
content: '[foobar](/user_uploads/123456)',
sender_id: 101,
queue_id: undefined,
stream: '',
subject: '',
to: '["alice@example.com"]',
reply_to: 'alice@example.com',
private_message_recipient: 'alice@example.com',
to_user_ids: '31',
local_id: 1,
locally_echoed: true,
type: 'private',
content: '[foobar](/user_uploads/123456)',
sender_id: 101,
queue_id: undefined,
stream: '',
subject: '',
to: '["alice@example.com"]',
reply_to: 'alice@example.com',
private_message_recipient: 'alice@example.com',
to_user_ids: '31',
local_id: 1,
locally_echoed: true,
};
assert.deepEqual(payload, single_msg);
payload.id = stub_state.local_id_counter;
@ -624,7 +624,7 @@ people.add(bob);
assert(!echo_error_msg_checked);
assert.equal($("#compose-send-button").prop('disabled'), false);
assert.equal($('#compose-error-msg').html(),
'Error sending message: Server says 408');
'Error sending message: Server says 408');
assert.equal($("#compose-textarea").val(), 'foobarfoobar');
assert($("#compose-textarea").is_focused());
assert($("#compose-send-status").visible());
@ -917,7 +917,7 @@ function test_raw_file_drop(raw_drop_func) {
var data = {
mentioned: {
email: 'foo@bar.com',
email: 'foo@bar.com',
},
};
@ -977,8 +977,8 @@ function test_raw_file_drop(raw_drop_func) {
data = {
mentioned: {
email: 'foo@bar.com',
full_name: 'Foo Barson',
email: 'foo@bar.com',
full_name: 'Foo Barson',
},
};
@ -1035,7 +1035,7 @@ function test_raw_file_drop(raw_drop_func) {
(function test_compose_all_everyone_confirm_clicked() {
var handler = $("#compose-all-everyone")
.get_on_handler('click', '.compose-all-everyone-confirm');
.get_on_handler('click', '.compose-all-everyone-confirm');
setup_parents_and_mock_remove('compose-all-everyone',
'compose-all-everyone',
@ -1059,7 +1059,7 @@ function test_raw_file_drop(raw_drop_func) {
(function test_compose_invite_users_clicked() {
var handler = $("#compose_invite_users")
.get_on_handler('click', '.compose_invite_link');
.get_on_handler('click', '.compose_invite_link');
var subscription = {
stream_id: 102,
name: 'test',
@ -1124,7 +1124,7 @@ function test_raw_file_drop(raw_drop_func) {
(function test_compose_invite_close_clicked() {
var handler = $("#compose_invite_users")
.get_on_handler('click', '.compose_invite_close');
.get_on_handler('click', '.compose_invite_close');
setup_parents_and_mock_remove('compose_invite_users_close',
'compose_invite_close',
@ -1146,7 +1146,7 @@ function test_raw_file_drop(raw_drop_func) {
(function test_compose_not_subscribed_clicked() {
var handler = $("#compose-send-status")
.get_on_handler('click', '.sub_unsub_button');
.get_on_handler('click', '.sub_unsub_button');
var subscription = {
stream_id: 102,
name: 'test',
@ -1176,7 +1176,7 @@ function test_raw_file_drop(raw_drop_func) {
(function test_compose_not_subscribed_close_clicked() {
var handler = $("#compose-send-status")
.get_on_handler('click', '#compose_not_subscribed_close');
.get_on_handler('click', '#compose_not_subscribed_close');
setup_parents_and_mock_remove('compose_user_not_subscribed_close',
'compose_not_subscribed_close',
@ -1222,33 +1222,33 @@ function test_raw_file_drop(raw_drop_func) {
compose_state.set_message_type('stream');
var checks = [
(function () {
var called;
templates.render = function (template_name, context) {
called = true;
assert.equal(template_name, 'compose_private_stream_alert');
assert.equal(context.stream_name, 'Denmark');
return 'fake-compose_private_stream_alert-template';
};
return function () { assert(called); };
}()),
(function () {
var called;
templates.render = function (template_name, context) {
called = true;
assert.equal(template_name, 'compose_private_stream_alert');
assert.equal(context.stream_name, 'Denmark');
return 'fake-compose_private_stream_alert-template';
};
return function () { assert(called); };
}()),
(function () {
var called;
$("#compose_private_stream_alert").append = function (html) {
called = true;
assert.equal(html, 'fake-compose_private_stream_alert-template');
};
return function () { assert(called); };
}()),
(function () {
var called;
$("#compose_private_stream_alert").append = function (html) {
called = true;
assert.equal(html, 'fake-compose_private_stream_alert-template');
};
return function () { assert(called); };
}()),
];
data = {
stream: {
invite_only: true,
name: 'Denmark',
subscribers: Dict.from_array([1]),
},
stream: {
invite_only: true,
name: 'Denmark',
subscribers: Dict.from_array([1]),
},
};
handler({}, data);
@ -1260,7 +1260,7 @@ function test_raw_file_drop(raw_drop_func) {
(function test_attach_files_compose_clicked() {
var handler = $("#compose")
.get_on_handler("click", "#attach_files");
.get_on_handler("click", "#attach_files");
$('#file_input').clone = function (param) {
assert(param);
};
@ -1334,7 +1334,7 @@ function test_raw_file_drop(raw_drop_func) {
function test_post_error(error_callback) {
error_callback();
assert.equal($("#preview_content").html(),
'translated: Failed to generate preview');
'translated: Failed to generate preview');
}
function mock_channel_post(msg) {
@ -1364,7 +1364,7 @@ function test_raw_file_drop(raw_drop_func) {
}
var handler = $("#compose")
.get_on_handler("click", "#markdown_preview");
.get_on_handler("click", "#markdown_preview");
// Tests start here
$("#compose-textarea").val('');
@ -1373,7 +1373,7 @@ function test_raw_file_drop(raw_drop_func) {
handler(event);
assert.equal($("#preview_content").html(),
'translated: Nothing to preview');
'translated: Nothing to preview');
assert_visibilities();
var make_indicator_called = false;
@ -1409,12 +1409,12 @@ function test_raw_file_drop(raw_drop_func) {
assert(apply_markdown_called);
assert_visibilities();
assert.equal($("#preview_content").html(),
'Server: foobarfoobar');
'Server: foobarfoobar');
}());
(function test_undo_markdown_preview_clicked() {
var handler = $("#compose")
.get_on_handler("click", "#undo_markdown_preview");
.get_on_handler("click", "#undo_markdown_preview");
$("#compose-textarea").hide();
$("#undo_markdown_preview").show();

View File

@ -369,8 +369,10 @@ user_pill.get_user_ids = function () {
assert.deepEqual(actual_value, expected_value);
// options.highlighter()
options.query = 'De'; // Beginning of "Denmark", one of the streams
// provided in stream_list through .source().
// Beginning of "Denmark", one of the streams
// provided in stream_list through .source().
options.query = 'De';
actual_value = options.highlighter('Denmark');
expected_value = '<strong>Denmark</strong>';
assert.equal(actual_value, expected_value);
@ -751,9 +753,9 @@ user_pill.get_user_ids = function () {
pm_recipient_blur_called = true;
};
page_params.enter_sends = false; // We manually specify it the first
// time because the click_func
// doesn't exist yet.
page_params.enter_sends = false;
// We manually specify it the first time because the click_func
// doesn't exist yet.
$("#stream").select(noop);
$("#subject").select(noop);
$("#private_message_recipient").select(noop);
@ -1164,7 +1166,7 @@ user_pill.get_user_ids = function () {
}
assert_emoji_matches('da',[{emoji_name: "tada", emoji_url: "TBD", codepoint: "1f389"},
{emoji_name: "panda_face", emoji_url: "TBD", codepoint: "1f43c"}]);
{emoji_name: "panda_face", emoji_url: "TBD", codepoint: "1f43c"}]);
assert_emoji_matches('da_', []);
assert_emoji_matches('da ', []);
assert_emoji_matches('panda ', [{emoji_name: "panda_face", emoji_url: "TBD", codepoint: "1f43c"}]);

View File

@ -95,33 +95,33 @@ var draft_2 = {
localStorage.clear();
(function test_addDraft() {
stub_timestamp(1, function () {
var expected = _.clone(draft_1);
expected.updatedAt = 1;
var id = draft_model.addDraft(_.clone(draft_1));
stub_timestamp(1, function () {
var expected = _.clone(draft_1);
expected.updatedAt = 1;
var id = draft_model.addDraft(_.clone(draft_1));
assert.deepEqual(ls.get("drafts")[id], expected);
});
assert.deepEqual(ls.get("drafts")[id], expected);
});
}());
localStorage.clear();
(function test_editDraft() {
stub_timestamp(2, function () {
ls.set("drafts", { id1: draft_1 });
var expected = _.clone(draft_2);
expected.updatedAt = 2;
draft_model.editDraft("id1", _.clone(draft_2));
stub_timestamp(2, function () {
ls.set("drafts", { id1: draft_1 });
var expected = _.clone(draft_2);
expected.updatedAt = 2;
draft_model.editDraft("id1", _.clone(draft_2));
assert.deepEqual(ls.get("drafts").id1, expected);
});
assert.deepEqual(ls.get("drafts").id1, expected);
});
}());
localStorage.clear();
(function test_deleteDraft() {
ls.set("drafts", { id1: draft_1 });
draft_model.deleteDraft("id1");
ls.set("drafts", { id1: draft_1 });
draft_model.deleteDraft("id1");
assert.deepEqual(ls.get("drafts"), {});
assert.deepEqual(ls.get("drafts"), {});
}());
}());

View File

@ -102,7 +102,7 @@ zrequire('util');
var expected = t.expected;
original = original.replace(/(<original>)/g, shortcut);
expected = expected.replace(/(<original>)/g, shortcut)
.replace(/(<converted>)/g, converted_value);
.replace(/(<converted>)/g, converted_value);
var result = emoji.translate_emoticons_to_names(original);
assert.equal(result, expected);
});

View File

@ -623,20 +623,20 @@ function make_jquery_helper() {
function fake_jquery(selector) {
switch (selector) {
case '#stream_filters li.highlighted_stream':
return jquery_elem();
case '.stream-list-filter':
return stream_list_filter;
case '#stream_filters li.narrow-filter':
return jquery_elem();
case 'ul#stream_filters li':
return jquery_elem();
case '.stream-filters-label':
return jquery_elem();
case '#stream_filters':
return stream_filters;
default:
throw Error('unknown selector: ' + selector);
case '#stream_filters li.highlighted_stream':
return jquery_elem();
case '.stream-list-filter':
return stream_list_filter;
case '#stream_filters li.narrow-filter':
return jquery_elem();
case 'ul#stream_filters li':
return jquery_elem();
case '.stream-filters-label':
return jquery_elem();
case '#stream_filters':
return stream_filters;
default:
throw Error('unknown selector: ' + selector);
}
}

View File

@ -193,9 +193,9 @@ function sort_button(opts) {
function data(sel) {
switch (sel) {
case "sort": return opts.sort_type;
case "sort-prop": return opts.prop_name;
default: throw Error('unknown selector: ' + sel);
case "sort": return opts.sort_type;
case "sort-prop": return opts.prop_name;
default: throw Error('unknown selector: ' + sel);
}
}

View File

@ -47,7 +47,7 @@ set_global('page_params', {
set_global('blueslip', global.make_zblueslip());
set_global('Image', function () {
return {};
return {};
});
emoji.initialize();
@ -147,44 +147,43 @@ markdown.initialize();
var bugdown_data = global.read_fixture_data('markdown_test_cases.json');
(function test_bugdown_detection() {
var no_markup = [
"This is a plaintext message",
"This is a plaintext: message",
"This is a :plaintext message",
"This is a :plaintext message: message",
"Contains a not an image.jpeg/ok file",
"Contains a not an http://www.google.com/ok/image.png/stop file",
"No png to be found here, a png",
"No user mention **leo**",
"No user mention @what there",
"No group mention *hamletcharacters*",
"We like to code\n~~~\ndef code():\n we = \"like to do\"\n~~~",
"This is a\nmultiline :emoji: here\n message",
"This is an :emoji: message",
"User Mention @**leo**",
"User Mention @**leo f**",
"User Mention @**leo with some name**",
"Group Mention @*hamletcharacters*",
"Stream #**Verona**",
"This contains !gravatar(leo@zulip.com)",
"And an avatar !avatar(leo@zulip.com) is here",
];
"This is a plaintext message",
"This is a plaintext: message",
"This is a :plaintext message",
"This is a :plaintext message: message",
"Contains a not an image.jpeg/ok file",
"Contains a not an http://www.google.com/ok/image.png/stop file",
"No png to be found here, a png",
"No user mention **leo**",
"No user mention @what there",
"No group mention *hamletcharacters*",
"We like to code\n~~~\ndef code():\n we = \"like to do\"\n~~~",
"This is a\nmultiline :emoji: here\n message",
"This is an :emoji: message",
"User Mention @**leo**",
"User Mention @**leo f**",
"User Mention @**leo with some name**",
"Group Mention @*hamletcharacters*",
"Stream #**Verona**",
"This contains !gravatar(leo@zulip.com)",
"And an avatar !avatar(leo@zulip.com) is here",
];
var markup = [
"Contains a https://zulip.com/image.png file",
"Contains a https://zulip.com/image.jpg file",
"https://zulip.com/image.jpg",
"also https://zulip.com/image.jpg",
"https://zulip.com/image.jpg too",
"Contains a zulip.com/foo.jpeg file",
"Contains a https://zulip.com/image.png file",
"twitter url https://twitter.com/jacobian/status/407886996565016579",
"https://twitter.com/jacobian/status/407886996565016579",
"then https://twitter.com/jacobian/status/407886996565016579",
"twitter url http://twitter.com/jacobian/status/407886996565016579",
"youtube url https://www.youtube.com/watch?v=HHZ8iqswiCw&feature=youtu.be&a",
];
"Contains a https://zulip.com/image.png file",
"Contains a https://zulip.com/image.jpg file",
"https://zulip.com/image.jpg",
"also https://zulip.com/image.jpg",
"https://zulip.com/image.jpg too",
"Contains a zulip.com/foo.jpeg file",
"Contains a https://zulip.com/image.png file",
"twitter url https://twitter.com/jacobian/status/407886996565016579",
"https://twitter.com/jacobian/status/407886996565016579",
"then https://twitter.com/jacobian/status/407886996565016579",
"twitter url http://twitter.com/jacobian/status/407886996565016579",
"youtube url https://www.youtube.com/watch?v=HHZ8iqswiCw&feature=youtu.be&a",
];
no_markup.forEach(function (content) {
assert.equal(markdown.contains_backend_only_syntax(content), false);
@ -305,14 +304,14 @@ var bugdown_data = global.read_fixture_data('markdown_test_cases.json');
{input: 'T\n#**Denmark**',
expected: '<p>T<br>\n<a class="stream" data-stream-id="1" href="http://zulip.zulipdev.com/#narrow/stream/1-Denmark">#Denmark</a></p>'},
{input: 'T\n@**Cordelia Lear**',
expected: '<p>T<br>\n<span class="user-mention" data-user-id="101">@Cordelia Lear</span></p>'},
expected: '<p>T<br>\n<span class="user-mention" data-user-id="101">@Cordelia Lear</span></p>'},
{input: 'T\n@hamletcharacters',
expected: '<p>T<br>\n@hamletcharacters</p>'},
{input: 'T\n@*hamletcharacters*',
expected: '<p>T<br>\n<span class="user-group-mention" data-user-group-id="1">@hamletcharacters</span></p>'},
{input: 'T\n@*notagroup*',
expected: '<p>T<br>\n@*notagroup*</p>'},
{input: 'T\n@*backend*',
{input: 'T\n@*backend*',
expected: '<p>T<br>\n<span class="user-group-mention" data-user-group-id="2">@Backend</span></p>'},
{input: '@*notagroup*',
expected: '<p>@*notagroup*</p>'},
@ -324,7 +323,7 @@ var bugdown_data = global.read_fixture_data('markdown_test_cases.json');
{input: ':)',
expected: '<p><span class="emoji emoji-1f603" title="smiley">:smiley:</span></p>',
translate_emoticons: true},
// Test HTML Escape in Custom Zulip Rules
// Test HTML Escape in Custom Zulip Rules
{input: '@**<h1>The Rogue One</h1>**',
expected: '<p>@**&lt;h1&gt;The Rogue One&lt;/h1&gt;**</p>'},
{input: '#**<h1>The Rogue One</h1>**',

View File

@ -199,18 +199,18 @@ var with_overrides = global.with_overrides; // make lint happy
var list = new MessageList(table, filter);
var items = [
{
id: 1,
sender_id: 3,
},
{
id: 2,
sender_id: 3,
},
{
id: 3,
sender_id: 6,
},
{
id: 1,
sender_id: 3,
},
{
id: 2,
sender_id: 3,
},
{
id: 3,
sender_id: 6,
},
];
list.append(items);
@ -246,8 +246,9 @@ var with_overrides = global.with_overrides; // make lint happy
list = new MessageList(table, filter);
list.append([{id:10}, {id:20}, {id:30}, {id:20.02}, {id:20.03}, {id:40},
{id:50}, {id: 50.01}, {id: 50.02}, {id:60}]);
list.append([
{id:10}, {id:20}, {id:30}, {id:20.02}, {id:20.03}, {id:40},
{id:50}, {id: 50.01}, {id: 50.02}, {id:60}]);
list._local_only= {20.02: {id:20.02}, 20.03: {id:20.03},
50.01: {id: 50.01}, 50.02: {id: 50.02}};

View File

@ -12,7 +12,7 @@ zrequire('message_list');
var noop = function () {};
set_global('page_params', {
twenty_four_hour_time: false,
twenty_four_hour_time: false,
});
set_global('home_msg_list', null);
set_global('feature_flags', {twenty_four_hour_time: false});
@ -275,7 +275,7 @@ set_global('rows', {
assert_message_groups_list_equal(result.append_groups, []);
assert_message_groups_list_equal(result.prepend_groups, []);
assert_message_groups_list_equal(result.rerender_groups,
[build_message_group([message2, message1])]);
[build_message_group([message2, message1])]);
assert_message_list_equal(result.append_messages, []);
assert_message_list_equal(result.rerender_messages, []);
}());

View File

@ -64,96 +64,96 @@ stream_data.add_sub('stream_two', two);
// Case 1: If the message was sent by this user,
// DO NOT notify the user
// In this test, all other circumstances should trigger notification
// EXCEPT sent_by_me, which should trump them
assert.equal(notifications.message_is_notifiable({
id: 10,
content: 'message number 1',
sent_by_me: true,
notification_sent: false,
mentioned_me_directly: true,
type: 'stream',
stream: 'stream_two',
stream_id: 20,
subject: 'topic_two',
}), false);
// In this test, all other circumstances should trigger notification
// EXCEPT sent_by_me, which should trump them
assert.equal(notifications.message_is_notifiable({
id: 10,
content: 'message number 1',
sent_by_me: true,
notification_sent: false,
mentioned_me_directly: true,
type: 'stream',
stream: 'stream_two',
stream_id: 20,
subject: 'topic_two',
}), false);
// Case 2: If the user has already been sent a notificaton about this message,
// DO NOT notify the user
// In this test, all other circumstances should trigger notification
// EXCEPT notification_sent, which should trump them
// (ie: it mentions user, it's not muted, etc)
assert.equal(notifications.message_is_notifiable({
id: 20,
content: 'message number 2',
sent_by_me: false,
notification_sent: true,
mentioned_me_directly: true,
type: 'stream',
stream: 'stream_two',
stream_id: 20,
subject: 'topic_two',
}), false);
// In this test, all other circumstances should trigger notification
// EXCEPT notification_sent, which should trump them
// (ie: it mentions user, it's not muted, etc)
assert.equal(notifications.message_is_notifiable({
id: 20,
content: 'message number 2',
sent_by_me: false,
notification_sent: true,
mentioned_me_directly: true,
type: 'stream',
stream: 'stream_two',
stream_id: 20,
subject: 'topic_two',
}), false);
// Case 3: If a message mentions the user directly,
// DO notify the user
// Mentioning trumps muting
assert.equal(notifications.message_is_notifiable({
id: 30,
content: 'message number three',
sent_by_me: false,
notification_sent: false,
mentioned_me_directly: true,
type: 'stream',
stream: 'stream_one',
stream_id: 10,
subject: 'topic_three',
}), true);
// Mentioning trumps muting
assert.equal(notifications.message_is_notifiable({
id: 30,
content: 'message number three',
sent_by_me: false,
notification_sent: false,
mentioned_me_directly: true,
type: 'stream',
stream: 'stream_one',
stream_id: 10,
subject: 'topic_three',
}), true);
// Mentioning should trigger notification in unmuted topic
assert.equal(notifications.message_is_notifiable({
id: 40,
content: 'message number 4',
sent_by_me: false,
notification_sent: false,
mentioned_me_directly: true,
type: 'stream',
stream: 'stream_two',
stream_id: 20,
subject: 'topic_two',
}), true);
// Mentioning should trigger notification in unmuted topic
assert.equal(notifications.message_is_notifiable({
id: 40,
content: 'message number 4',
sent_by_me: false,
notification_sent: false,
mentioned_me_directly: true,
type: 'stream',
stream: 'stream_two',
stream_id: 20,
subject: 'topic_two',
}), true);
// Case 4: If a message is in a muted stream
// and does not mention the user DIRECTLY,
// DO NOT notify the user
assert.equal(notifications.message_is_notifiable({
id: 50,
content: 'message number 5',
sent_by_me: false,
notification_sent: false,
mentioned_me_directly: false,
type: 'stream',
stream: 'stream_one',
stream_id: 10,
subject: 'topic_one',
}), false);
assert.equal(notifications.message_is_notifiable({
id: 50,
content: 'message number 5',
sent_by_me: false,
notification_sent: false,
mentioned_me_directly: false,
type: 'stream',
stream: 'stream_one',
stream_id: 10,
subject: 'topic_one',
}), false);
// Case 5
// If none of the above cases apply
// (ie: topic is not muted, message does not mention user,
// no notification sent before, message not sent by user),
// return true to pass it to notifications settings
assert.equal(notifications.message_is_notifiable({
id: 60,
content: 'message number 6',
sent_by_me: false,
notification_sent: false,
mentioned_me_directly: false,
type: 'stream',
stream: 'stream_two',
stream_id: 20,
subject: 'topic_two',
}), true);
// If none of the above cases apply
// (ie: topic is not muted, message does not mention user,
// no notification sent before, message not sent by user),
// return true to pass it to notifications settings
assert.equal(notifications.message_is_notifiable({
id: 60,
content: 'message number 6',
sent_by_me: false,
notification_sent: false,
mentioned_me_directly: false,
type: 'stream',
stream: 'stream_two',
stream_id: 20,
subject: 'topic_two',
}), true);
}());
@ -191,7 +191,7 @@ stream_data.add_sub('stream_two', two);
},
});
var message_1 = {
var message_1 = {
id: 1000,
content: '@-mentions the user',
sent_by_me: false,

View File

@ -242,7 +242,7 @@ initialize();
}());
(function test_filtered_users() {
var charles = {
var charles = {
email: 'charles@example.com',
user_id: 301,
full_name: 'Charles Dickens',
@ -391,9 +391,9 @@ initialize();
};
assert.equal(people.pm_with_url(message), '#narrow/pm-with/451,452-group');
assert.equal(people.pm_reply_to(message),
'athens@example.com,charles@example.com');
'athens@example.com,charles@example.com');
assert.equal(people.small_avatar_url(message),
'charles.com/foo.png&s=50');
'charles.com/foo.png&s=50');
message = {
type: 'private',
@ -405,16 +405,16 @@ initialize();
};
assert.equal(people.pm_with_url(message), '#narrow/pm-with/452-athens');
assert.equal(people.pm_reply_to(message),
'athens@example.com');
'athens@example.com');
assert.equal(people.small_avatar_url(message),
'legacy.png&s=50');
'legacy.png&s=50');
message = {
avatar_url: undefined,
sender_id: maria.user_id,
};
assert.equal(people.small_avatar_url(message),
'https://secure.gravatar.com/avatar/md5-athens@example.com?d=identicon&s=50'
'https://secure.gravatar.com/avatar/md5-athens@example.com?d=identicon&s=50'
);
message = {
@ -423,7 +423,7 @@ initialize();
sender_id: 9999999,
};
assert.equal(people.small_avatar_url(message),
'https://secure.gravatar.com/avatar/md5-foo@example.com?d=identicon&s=50'
'https://secure.gravatar.com/avatar/md5-foo@example.com?d=identicon&s=50'
);
message = {
@ -616,7 +616,8 @@ initialize();
// Test shim where we can still retrieve user info using the
// old email.
blueslip.set_test_data('warn',
'Obsolete email passed to get_by_email: FOO@example.com new email = bar@example.com');
'Obsolete email passed to get_by_email: ' +
'FOO@example.com new email = bar@example.com');
person = people.get_by_email(old_email);
assert.equal(person.user_id, user_id);
assert.equal(blueslip.get_test_logs('warn').length, 1);

View File

@ -127,40 +127,40 @@ function make_image_stubber() {
templates.render = function (fn, opts) {
switch (fn) {
case 'user_info_popover':
assert.deepEqual(opts, {
class: 'message-info-popover',
});
return 'popover-html';
case 'user_info_popover':
assert.deepEqual(opts, {
class: 'message-info-popover',
});
return 'popover-html';
case 'user_info_popover_title':
assert.deepEqual(opts, {
user_avatar: 'avatar/alice@example.com',
});
return 'title-html';
case 'user_info_popover_title':
assert.deepEqual(opts, {
user_avatar: 'avatar/alice@example.com',
});
return 'title-html';
case 'user_info_popover_content':
assert.deepEqual(opts, {
user_full_name: 'Alice Smith',
user_email: 'alice@example.com',
user_id: 42,
user_time: undefined,
presence_status: 'offline',
user_last_seen_time_status: 'translated: Unknown',
pm_with_uri: '#narrow/pm-with/42-alice',
sent_by_uri: '#narrow/sender/42-alice',
narrowed: false,
private_message_class: 'respond_personal_button',
show_user_profile: false,
is_me: false,
is_active: true,
is_bot: undefined,
is_sender_popover: true,
});
return 'content-html';
case 'user_info_popover_content':
assert.deepEqual(opts, {
user_full_name: 'Alice Smith',
user_email: 'alice@example.com',
user_id: 42,
user_time: undefined,
presence_status: 'offline',
user_last_seen_time_status: 'translated: Unknown',
pm_with_uri: '#narrow/pm-with/42-alice',
sent_by_uri: '#narrow/sender/42-alice',
narrowed: false,
private_message_class: 'respond_personal_button',
show_user_profile: false,
is_me: false,
is_active: true,
is_bot: undefined,
is_sender_popover: true,
});
return 'content-html';
default:
throw Error('unrecognized template: ' + fn);
default:
throw Error('unrecognized template: ' + fn);
}
};

View File

@ -159,15 +159,15 @@ people.initialize_current_user(me.user_id);
presence.set_info(presences, base_time);
assert.deepEqual(presence.presence_info[alice.user_id],
{ status: 'active', mobile: false, last_active: 500}
{ status: 'active', mobile: false, last_active: 500}
);
assert.deepEqual(presence.presence_info[fred.user_id],
{ status: 'idle', mobile: false, last_active: 500}
{ status: 'idle', mobile: false, last_active: 500}
);
assert.deepEqual(presence.presence_info[zoe.user_id],
{ status: 'offline', mobile: false, last_active: undefined}
{ status: 'offline', mobile: false, last_active: undefined}
);
assert(!presence.presence_info[bot.user_id]);

View File

@ -158,43 +158,43 @@ set_global('current_msg_list', {
result.sort(function (a, b) { return a.count - b.count; });
var expected_result = [
{
emoji_name: 'frown',
reaction_type: 'unicode_emoji',
emoji_code: '1f626',
local_id: 'unicode_emoji,frown,1f626',
count: 1,
user_ids: [7],
title: 'Cali reacted with :frown:',
emoji_alt_code: false,
class: 'message_reaction',
},
{
emoji_name: 'inactive_realm_emoji',
reaction_type: 'realm_emoji',
emoji_code: '992',
local_id: 'realm_emoji,inactive_realm_emoji,992',
count: 1,
user_ids: [5],
title: 'You (click to remove) reacted with :inactive_realm_emoji:',
emoji_alt_code: false,
is_realm_emoji: true,
url: 'TBD',
class: 'message_reaction reacted',
},
{
emoji_name: 'smile',
reaction_type: 'unicode_emoji',
emoji_code: '1f604',
local_id: 'unicode_emoji,smile,1f604',
count: 2,
user_ids: [5, 6],
title: 'You (click to remove) and Bob van Roberts reacted with :smile:',
emoji_alt_code: false,
class: 'message_reaction reacted',
},
];
assert.deepEqual(result, expected_result);
{
emoji_name: 'frown',
reaction_type: 'unicode_emoji',
emoji_code: '1f626',
local_id: 'unicode_emoji,frown,1f626',
count: 1,
user_ids: [7],
title: 'Cali reacted with :frown:',
emoji_alt_code: false,
class: 'message_reaction',
},
{
emoji_name: 'inactive_realm_emoji',
reaction_type: 'realm_emoji',
emoji_code: '992',
local_id: 'realm_emoji,inactive_realm_emoji,992',
count: 1,
user_ids: [5],
title: 'You (click to remove) reacted with :inactive_realm_emoji:',
emoji_alt_code: false,
is_realm_emoji: true,
url: 'TBD',
class: 'message_reaction reacted',
},
{
emoji_name: 'smile',
reaction_type: 'unicode_emoji',
emoji_code: '1f604',
local_id: 'unicode_emoji,smile,1f604',
count: 2,
user_ids: [5, 6],
title: 'You (click to remove) and Bob van Roberts reacted with :smile:',
emoji_alt_code: false,
class: 'message_reaction reacted',
},
];
assert.deepEqual(result, expected_result);
}());
(function test_sending() {

View File

@ -248,9 +248,9 @@ topic_data.reset();
};
set_global('activity', {
get_huddles: function () {
return [];
},
get_huddles: function () {
return [];
},
});
var ted =
@ -382,9 +382,9 @@ topic_data.reset();
assert.deepEqual(suggestions.strings, expected);
set_global('activity', {
get_huddles: function () {
return ['101,42', '101,103,42'];
},
get_huddles: function () {
return ['101,42', '101,103,42'];
},
});
// Simulate a past huddle which should now prioritize ted over alice
@ -560,8 +560,8 @@ init();
global.stream_data.get_stream_id = function (stream_name) {
switch (stream_name) {
case 'office': return office_id;
case 'devel': return devel_id;
case 'office': return office_id;
case 'devel': return devel_id;
}
};
@ -758,9 +758,9 @@ init();
return suggestions.lookup_table[q].description;
}
assert.equal(describe('pm-with:ted@zulip.com'),
"Private messages with <strong>Te</strong>d Smith &lt;<strong>te</strong>d@zulip.com&gt;");
"Private messages with <strong>Te</strong>d Smith &lt;<strong>te</strong>d@zulip.com&gt;");
assert.equal(describe('sender:ted@zulip.com'),
"Sent by <strong>Te</strong>d Smith &lt;<strong>te</strong>d@zulip.com&gt;");
"Sent by <strong>Te</strong>d Smith &lt;<strong>te</strong>d@zulip.com&gt;");
suggestions = search.get_suggestions('Ted '); // note space

View File

@ -1,9 +1,10 @@
set_global("page_params", {
realm_uri: "https://chat.example.com",
realm_embedded_bots: [{name: "converter", config: {}},
{name:"giphy", config: {key: "12345678"}},
{name:"foobot", config: {bar: "baz", qux: "quux"}},
],
realm_embedded_bots: [
{name: "converter", config: {}},
{name:"giphy", config: {key: "12345678"}},
{name:"foobot", config: {bar: "baz", qux: "quux"}},
],
});
set_global("avatar", {});

View File

@ -167,7 +167,7 @@ function createSaveButtons(subsection) {
var props = {};
props.hidden = false;
save_btn_controls.fadeIn = () => {
props.hidden = false;
props.hidden = false;
};
save_btn_controls.fadeOut = () => {
props.hidden = true;
@ -473,7 +473,8 @@ function test_parse_time_limit() {
global.page_params.realm_message_content_edit_limit_seconds =
settings_org.parse_time_limit(elem);
assert.equal(expected_value,
settings_org.get_realm_time_limits_in_minutes('realm_message_content_edit_limit_seconds'));
settings_org.get_realm_time_limits_in_minutes(
'realm_message_content_edit_limit_seconds'));
};
test_function('0.01', '0');
@ -570,7 +571,7 @@ function test_parse_time_limit() {
var stub_notification_disable_parent = $.create('<stub notification_disable parent');
stub_notification_disable_parent.set_find_results('.notification-disable',
$.create('<disable link>'));
$.create('<disable link>'));
page_params.realm_name_changes_disabled = false;
settings_account.update_name_change_display();

View File

@ -255,7 +255,7 @@ var instructions_selector = "#user-groups #1 .save-instructions";
return bob;
}
assert.equal(user_email,
'Expected user email to be of Alice or Iago here.');
'Expected user email to be of Alice or Iago here.');
};
pills.onPillCreate = function (handler) {
assert.equal(typeof(handler), 'function');
@ -380,7 +380,7 @@ var instructions_selector = "#user-groups #1 .save-instructions";
var turned_off = {};
pill_container_stub.off = function (event_name, sel) {
if (sel === undefined) {
sel = 'whole';
sel = 'whole';
}
turned_off[event_name + '/' + sel] = true;
};

View File

@ -513,25 +513,25 @@ zrequire('marked', 'third/marked/lib/marked');
}());
(function test_in_home_view() {
var tony = {
stream_id: 999,
name: 'tony',
subscribed: true,
in_home_view: true,
};
var tony = {
stream_id: 999,
name: 'tony',
subscribed: true,
in_home_view: true,
};
var jazy = {
stream_id: 500,
name: 'jazy',
subscribed: false,
in_home_view: false,
};
var jazy = {
stream_id: 500,
name: 'jazy',
subscribed: false,
in_home_view: false,
};
stream_data.add_sub('tony', tony);
stream_data.add_sub('jazy', jazy);
assert(stream_data.name_in_home_view('tony'));
assert(!stream_data.name_in_home_view('jazy'));
assert(!stream_data.name_in_home_view('EEXISTS'));
stream_data.add_sub('tony', tony);
stream_data.add_sub('jazy', jazy);
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() {

View File

@ -166,12 +166,12 @@ stream_data.add_sub('Frontend', frontend);
set_global('message_util', { do_unread_count_updates: noop });
// Test jQuery event
global.with_stub(function (stub) {
$(document).on('subscription_add_done.zulip', stub.f);
stream_events.mark_subscribed(frontend, [], '');
var args = stub.get_args('event');
assert.equal(args.event.sub.stream_id, 1);
});
global.with_stub(function (stub) {
$(document).on('subscription_add_done.zulip', stub.f);
stream_events.mark_subscribed(frontend, [], '');
var args = stub.get_args('event');
assert.equal(args.event.sub.stream_id, 1);
});
// Test bookend update
with_overrides(function (override) {

View File

@ -173,7 +173,7 @@ subs.stream_description_match_stream_ids = [];
subs.sub_or_unsub(denmark);
assert.equal(post_params.url, '/json/users/me/subscriptions');
assert.deepEqual(post_params.data,
{subscriptions: '[{"name":"Denmark"}]'});
{subscriptions: '[{"name":"Denmark"}]'});
global.channel.post = undefined;
@ -185,7 +185,7 @@ subs.stream_description_match_stream_ids = [];
subs.sub_or_unsub(denmark);
assert.equal(post_params.url, '/json/users/me/subscriptions');
assert.deepEqual(post_params.data,
{subscriptions: '["Denmark"]'});
{subscriptions: '["Denmark"]'});
}());

View File

@ -143,9 +143,10 @@ function render(template_name, args) {
// When the logged in user is admin
_.each(streams, function (stream) {
var args = {stream: {name: stream, invite_only: false},
can_modify: true,
};
var args = {
stream: {name: stream, invite_only: false},
can_modify: true,
};
html += render('admin_default_streams_list', args);
});
html += "</table>";
@ -155,9 +156,10 @@ function render(template_name, args) {
// When the logged in user is not admin
html = '<table>';
_.each(streams, function (stream) {
var args = {stream: {name: stream, invite_only: false},
can_modify: false,
};
var args = {
stream: {name: stream, invite_only: false},
can_modify: false,
};
html += render('admin_default_streams_list', args);
});
html += "</table>";
@ -596,7 +598,7 @@ function render(template_name, args) {
(function compose_private_stream_alert() {
var args = {
stream_name: 'Denmark',
stream_name: 'Denmark',
};
var html = render('compose_private_stream_alert', args);
assert($(html).hasClass('compose_private_stream_alert'));
@ -947,11 +949,11 @@ function render(template_name, args) {
],
};
var html = render('message_edit_history', {
edited_messages: message.edit_history,
});
edited_messages: message.edit_history,
});
var edited_message = $(html).find("div.messagebox-content");
assert.equal(edited_message.text().trim(),
"1468132659\n Let's go to lunchdinner!\n Edited by Alice");
"1468132659\n Let's go to lunchdinner!\n Edited by Alice");
}());
(function message_reaction() {

View File

@ -270,10 +270,10 @@ function is_odd(i) { return i % 2 === 1; }
topic_data.get_recent_names = function (stream_id) {
switch (stream_id) {
case muted_stream_id:
return ['ms-topic1', 'ms-topic2'];
case devel_stream_id:
return ['muted', 'python'];
case muted_stream_id:
return ['ms-topic1', 'ms-topic2'];
case devel_stream_id:
return ['muted', 'python'];
}
return [];

View File

@ -141,11 +141,11 @@ page_params.use_websockets = false;
reload.initiate = function (opts) {
reload_initiated = true;
assert.deepEqual(opts, {
immediate: true,
save_pointer: true,
save_narrow: true,
save_compose: true,
send_after_reload: true,
immediate: true,
save_pointer: true,
save_narrow: true,
save_compose: true,
send_after_reload: true,
});
};

View File

@ -177,7 +177,7 @@ _.each(matches, function (person) {
'a_user@zulip.org',
'zman@test.net',
'a_bot@zulip.com',
]);
]);
// Typeahead for private message [query, "", ""]
assert.deepEqual(get_typeahead_result("a", "", ""), [
@ -188,7 +188,7 @@ _.each(matches, function (person) {
'b_user_3@zulip.net',
'zman@test.net',
'b_bot@example.com',
]);
]);
var subscriber_email_1 = "b_user_2@zulip.net";
var subscriber_email_2 = "b_user_3@zulip.net";

View File

@ -77,11 +77,11 @@ zrequire('user_groups');
user_groups.add_members(all.id, [5, 4]);
assert.deepEqual(user_groups.get_user_group_from_id(all.id).members,
Dict.from_array([1, 2, 3, 5, 4]));
Dict.from_array([1, 2, 3, 5, 4]));
user_groups.remove_members(all.id, [1, 4]);
assert.deepEqual(user_groups.get_user_group_from_id(all.id).members,
Dict.from_array([2, 3, 5]));
Dict.from_array([2, 3, 5]));
assert(user_groups.is_user_group(admins));
var object = {