mirror of
https://github.com/zulip/zulip.git
synced 2026-06-24 21:08:25 +08:00
The extracted logic is in linkifier.js. We have decided to name it linkifier.js instead of realm_linkifier.js because in future when we will add stream-level linkifiers, we'll likely want them to be managed by this same file.
959 lines
34 KiB
JavaScript
959 lines
34 KiB
JavaScript
"use strict";
|
|
|
|
const {strict: assert} = require("assert");
|
|
|
|
const {mock_cjs, mock_esm, set_global, with_field, zrequire} = require("../zjsunit/namespace");
|
|
const {make_stub} = require("../zjsunit/stub");
|
|
const {run_test} = require("../zjsunit/test");
|
|
const blueslip = require("../zjsunit/zblueslip");
|
|
const $ = require("../zjsunit/zjquery");
|
|
const {page_params} = require("../zjsunit/zpage_params");
|
|
|
|
const noop = () => {};
|
|
|
|
const events = require("./lib/events");
|
|
|
|
const event_fixtures = events.fixtures;
|
|
const test_message = events.test_message;
|
|
const test_user = events.test_user;
|
|
const typing_person1 = events.typing_person1;
|
|
|
|
set_global("setTimeout", (func) => func());
|
|
|
|
mock_cjs("jquery", $);
|
|
const activity = mock_esm("../../static/js/activity");
|
|
const alert_words_ui = mock_esm("../../static/js/alert_words_ui");
|
|
const attachments_ui = mock_esm("../../static/js/attachments_ui");
|
|
const bot_data = mock_esm("../../static/js/bot_data");
|
|
const composebox_typeahead = mock_esm("../../static/js/composebox_typeahead");
|
|
const emoji_picker = mock_esm("../../static/js/emoji_picker");
|
|
const hotspots = mock_esm("../../static/js/hotspots");
|
|
const linkifiers = mock_esm("../../static/js/linkifiers");
|
|
const message_edit = mock_esm("../../static/js/message_edit");
|
|
const message_events = mock_esm("../../static/js/message_events");
|
|
const message_list = mock_esm("../../static/js/message_list");
|
|
const message_lists = mock_esm("../../static/js/message_lists");
|
|
const muting_ui = mock_esm("../../static/js/muting_ui");
|
|
const night_mode = mock_esm("../../static/js/night_mode");
|
|
const notifications = mock_esm("../../static/js/notifications");
|
|
const reactions = mock_esm("../../static/js/reactions");
|
|
const realm_icon = mock_esm("../../static/js/realm_icon");
|
|
const realm_logo = mock_esm("../../static/js/realm_logo");
|
|
const realm_playground = mock_esm("../../static/js/realm_playground");
|
|
const reload = mock_esm("../../static/js/reload");
|
|
const scroll_bar = mock_esm("../../static/js/scroll_bar");
|
|
const settings_account = mock_esm("../../static/js/settings_account");
|
|
const settings_bots = mock_esm("../../static/js/settings_bots");
|
|
const settings_display = mock_esm("../../static/js/settings_display");
|
|
const settings_emoji = mock_esm("../../static/js/settings_emoji");
|
|
const settings_exports = mock_esm("../../static/js/settings_exports");
|
|
const settings_invites = mock_esm("../../static/js/settings_invites");
|
|
const settings_linkifiers = mock_esm("../../static/js/settings_linkifiers");
|
|
const settings_playgrounds = mock_esm("../../static/js/settings_playgrounds");
|
|
const settings_notifications = mock_esm("../../static/js/settings_notifications");
|
|
const settings_org = mock_esm("../../static/js/settings_org");
|
|
const settings_profile_fields = mock_esm("../../static/js/settings_profile_fields");
|
|
const settings_streams = mock_esm("../../static/js/settings_streams");
|
|
const settings_user_groups = mock_esm("../../static/js/settings_user_groups");
|
|
const settings_users = mock_esm("../../static/js/settings_users");
|
|
const stream_data = mock_esm("../../static/js/stream_data");
|
|
const stream_events = mock_esm("../../static/js/stream_events");
|
|
const submessage = mock_esm("../../static/js/submessage");
|
|
const typing_events = mock_esm("../../static/js/typing_events");
|
|
const ui = mock_esm("../../static/js/ui");
|
|
const unread_ops = mock_esm("../../static/js/unread_ops");
|
|
const user_events = mock_esm("../../static/js/user_events");
|
|
const user_groups = mock_esm("../../static/js/user_groups");
|
|
mock_esm("../../static/js/compose");
|
|
mock_esm("../../static/js/giphy");
|
|
|
|
const electron_bridge = set_global("electron_bridge", {});
|
|
|
|
message_lists.current = {};
|
|
message_lists.home = {};
|
|
|
|
// page_params is highly coupled to dispatching now
|
|
|
|
page_params.test_suite = false;
|
|
page_params.is_admin = true;
|
|
page_params.realm_description = "already set description";
|
|
|
|
// For data-oriented modules, just use them, don't stub them.
|
|
const alert_words = zrequire("alert_words");
|
|
const stream_topic_history = zrequire("stream_topic_history");
|
|
const stream_list = zrequire("stream_list");
|
|
const message_helper = zrequire("message_helper");
|
|
const message_store = zrequire("message_store");
|
|
const people = zrequire("people");
|
|
const starred_messages = zrequire("starred_messages");
|
|
const user_status = zrequire("user_status");
|
|
|
|
const emoji = zrequire("../shared/js/emoji");
|
|
|
|
const server_events_dispatch = zrequire("server_events_dispatch");
|
|
|
|
function dispatch(ev) {
|
|
server_events_dispatch.dispatch_normal_event(ev);
|
|
}
|
|
|
|
people.init();
|
|
people.add_active_user(test_user);
|
|
|
|
message_helper.process_new_message(test_message);
|
|
|
|
const realm_emoji = {};
|
|
const emoji_codes = zrequire("../generated/emoji/emoji_codes.json");
|
|
|
|
emoji.initialize({realm_emoji, emoji_codes});
|
|
|
|
function assert_same(actual, expected) {
|
|
// This helper prevents us from getting false positives
|
|
// where actual and expected are both undefined.
|
|
assert(expected !== undefined);
|
|
assert.deepEqual(actual, expected);
|
|
}
|
|
|
|
run_test("alert_words", (override) => {
|
|
alert_words.initialize({alert_words: []});
|
|
assert(!alert_words.has_alert_word("fire"));
|
|
assert(!alert_words.has_alert_word("lunch"));
|
|
|
|
override(alert_words_ui, "render_alert_words_ui", noop);
|
|
const event = event_fixtures.alert_words;
|
|
dispatch(event);
|
|
|
|
assert.deepEqual(alert_words.get_word_list(), ["fire", "lunch"]);
|
|
assert(alert_words.has_alert_word("fire"));
|
|
assert(alert_words.has_alert_word("lunch"));
|
|
});
|
|
|
|
run_test("attachments", (override) => {
|
|
const event = event_fixtures.attachment__add;
|
|
const stub = make_stub();
|
|
// attachments_ui is hard to test deeply
|
|
override(attachments_ui, "update_attachments", stub.f);
|
|
dispatch(event);
|
|
assert.equal(stub.num_calls, 1);
|
|
assert_same(stub.get_args("event").event, event);
|
|
});
|
|
|
|
run_test("user groups", (override) => {
|
|
let event = event_fixtures.user_group__add;
|
|
override(settings_user_groups, "reload", noop);
|
|
{
|
|
const stub = make_stub();
|
|
override(user_groups, "add", stub.f);
|
|
dispatch(event);
|
|
assert.equal(stub.num_calls, 1);
|
|
const args = stub.get_args("group");
|
|
assert_same(args.group, event.group);
|
|
}
|
|
|
|
event = event_fixtures.user_group__remove;
|
|
{
|
|
const stub = make_stub();
|
|
override(user_groups, "get_user_group_from_id", stub.f);
|
|
override(user_groups, "remove", noop);
|
|
dispatch(event);
|
|
assert.equal(stub.num_calls, 1);
|
|
const args = stub.get_args("group_id");
|
|
assert_same(args.group_id, event.group_id);
|
|
}
|
|
|
|
event = event_fixtures.user_group__add_members;
|
|
{
|
|
const stub = make_stub();
|
|
override(user_groups, "add_members", stub.f);
|
|
dispatch(event);
|
|
assert.equal(stub.num_calls, 1);
|
|
const args = stub.get_args("group_id", "user_ids");
|
|
assert_same(args.group_id, event.group_id);
|
|
assert_same(args.user_ids, event.user_ids);
|
|
}
|
|
|
|
event = event_fixtures.user_group__remove_members;
|
|
{
|
|
const stub = make_stub();
|
|
override(user_groups, "remove_members", stub.f);
|
|
dispatch(event);
|
|
assert.equal(stub.num_calls, 1);
|
|
const args = stub.get_args("group_id", "user_ids");
|
|
assert_same(args.group_id, event.group_id);
|
|
assert_same(args.user_ids, event.user_ids);
|
|
}
|
|
|
|
event = event_fixtures.user_group__update;
|
|
{
|
|
const stub = make_stub();
|
|
override(user_groups, "update", stub.f);
|
|
dispatch(event);
|
|
assert.equal(stub.num_calls, 1);
|
|
const args = stub.get_args("event");
|
|
assert_same(args.event.group_id, event.group_id);
|
|
assert_same(args.event.data.name, event.data.name);
|
|
assert_same(args.event.data.description, event.data.description);
|
|
}
|
|
|