2020-08-01 03:43:15 +02:00
|
|
|
"use strict";
|
|
|
|
|
2020-11-30 23:46:45 +01:00
|
|
|
const {strict: assert} = require("assert");
|
|
|
|
|
2023-02-22 23:04:10 +01:00
|
|
|
const {mock_esm, set_global, zrequire} = require("./lib/namespace");
|
|
|
|
const {run_test} = require("./lib/test");
|
|
|
|
const blueslip = require("./lib/zblueslip");
|
|
|
|
const $ = require("./lib/zjquery");
|
|
|
|
const {user_settings} = require("./lib/zpage_params");
|
2020-12-01 00:02:16 +01:00
|
|
|
|
2022-01-25 11:36:19 +01:00
|
|
|
let $window_stub;
|
|
|
|
set_global("to_$", () => $window_stub);
|
2020-07-15 01:29:15 +02:00
|
|
|
|
|
|
|
set_global("document", "document-stub");
|
2021-02-10 04:53:22 +01:00
|
|
|
const history = set_global("history", {});
|
2020-07-15 01:29:15 +02:00
|
|
|
|
2023-02-22 23:04:10 +01:00
|
|
|
const admin = mock_esm("../src/admin");
|
2023-10-06 01:19:21 +02:00
|
|
|
const drafts_overlay_ui = mock_esm("../src/drafts_overlay_ui");
|
2023-02-22 23:04:10 +01:00
|
|
|
const info_overlay = mock_esm("../src/info_overlay");
|
|
|
|
const message_viewport = mock_esm("../src/message_viewport");
|
|
|
|
const overlays = mock_esm("../src/overlays");
|
2023-05-02 18:25:39 +02:00
|
|
|
const popovers = mock_esm("../src/popovers");
|
2023-09-06 23:14:37 +02:00
|
|
|
const recent_view_ui = mock_esm("../src/recent_view_ui");
|
2023-02-22 23:04:10 +01:00
|
|
|
const settings = mock_esm("../src/settings");
|
2024-06-12 12:04:08 +02:00
|
|
|
mock_esm("../src/settings_data", {
|
|
|
|
user_can_create_public_streams: () => true,
|
|
|
|
});
|
2023-02-22 23:04:10 +01:00
|
|
|
const stream_settings_ui = mock_esm("../src/stream_settings_ui");
|
|
|
|
const ui_util = mock_esm("../src/ui_util");
|
|
|
|
const ui_report = mock_esm("../src/ui_report");
|
2021-03-06 17:37:51 +01:00
|
|
|
set_global("favicon", {});
|
2020-07-15 01:29:15 +02:00
|
|
|
|
2021-03-22 16:09:12 +01:00
|
|
|
const browser_history = zrequire("browser_history");
|
2020-12-01 23:21:38 +01:00
|
|
|
const people = zrequire("people");
|
|
|
|
const hash_util = zrequire("hash_util");
|
|
|
|
const hashchange = zrequire("hashchange");
|
2024-06-05 10:51:22 +02:00
|
|
|
const message_view = zrequire("../src/message_view");
|
2020-12-01 23:21:38 +01:00
|
|
|
const stream_data = zrequire("stream_data");
|
2024-04-12 13:45:46 +02:00
|
|
|
const {Filter} = zrequire("../src/filter");
|
2020-12-01 23:21:38 +01:00
|
|
|
|
2024-08-03 03:05:34 +02:00
|
|
|
const devel_id = 100;
|
|
|
|
const devel = {
|
|
|
|
name: "devel",
|
|
|
|
stream_id: devel_id,
|
|
|
|
color: "blue",
|
|
|
|
subscribed: true,
|
|
|
|
};
|
|
|
|
stream_data.add_sub(devel);
|
|
|
|
|
2023-12-22 00:26:14 +01:00
|
|
|
run_test("terms_round_trip", () => {
|
|
|
|
let terms;
|
2019-11-02 00:06:25 +01:00
|
|
|
let hash;
|
|
|
|
let narrow;
|
2014-02-19 22:19:16 +01:00
|
|
|
|
2023-12-22 00:26:14 +01:00
|
|
|
terms = [
|
2024-08-03 03:05:34 +02:00
|
|
|
{operator: "stream", operand: devel_id.toString()},
|
2020-07-15 01:29:15 +02:00
|
|
|
{operator: "topic", operand: "algol"},
|
2014-02-19 22:19:16 +01:00
|
|
|
];
|
2023-12-22 00:26:14 +01:00
|
|
|
hash = hash_util.search_terms_to_hash(terms);
|
2024-08-03 03:05:34 +02:00
|
|
|
assert.equal(hash, "#narrow/stream/100-devel/topic/algol");
|
2014-02-19 22:19:16 +01:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
narrow = hash_util.parse_narrow(hash.split("/"));
|
2017-01-05 22:04:33 +01:00
|
|
|
assert.deepEqual(narrow, [
|
2024-08-03 03:05:34 +02:00
|
|
|
{operator: "stream", operand: devel_id.toString(), negated: false},
|
2020-07-15 01:29:15 +02:00
|
|
|
{operator: "topic", operand: "algol", negated: false},
|
2017-01-05 22:04:33 +01:00
|
|
|
]);
|
|
|
|
|
2023-12-22 00:26:14 +01:00
|
|
|
terms = [
|
2024-08-03 03:05:34 +02:00
|
|
|
{operator: "stream", operand: devel_id.toString()},
|
2020-07-15 01:29:15 +02:00
|
|
|
{operator: "topic", operand: "visual c++", negated: true},
|
2014-02-19 22:19:16 +01:00
|
|
|
];
|
2023-12-22 00:26:14 +01:00
|
|
|
hash = hash_util.search_terms_to_hash(terms);
|
2024-08-03 03:05:34 +02:00
|
|
|
assert.equal(hash, "#narrow/stream/100-devel/-topic/visual.20c.2B.2B");
|
2017-01-05 22:04:33 +01:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
narrow = hash_util.parse_narrow(hash.split("/"));
|
2017-01-05 22:04:33 +01:00
|
|
|
assert.deepEqual(narrow, [
|
2024-08-03 03:05:34 +02:00
|
|
|
{operator: "stream", operand: devel_id.toString(), negated: false},
|
2020-07-15 01:29:15 +02:00
|
|
|
{operator: "topic", operand: "visual c++", negated: true},
|
2017-01-05 22:04:33 +01:00
|
|
|
]);
|
|
|
|
|
2018-02-15 21:02:47 +01:00
|
|
|
// test new encodings, where we have a stream id
|
2024-08-03 03:05:34 +02:00
|
|
|
const florida_id = 987;
|
2019-11-02 00:06:25 +01:00
|
|
|
const florida_stream = {
|
2020-07-15 01:29:15 +02:00
|
|
|
name: "Florida, USA",
|
2024-08-03 03:05:34 +02:00
|
|
|
stream_id: florida_id,
|
2018-02-15 21:02:47 +01:00
|
|
|
};
|
2020-02-09 22:02:55 +01:00
|
|
|
stream_data.add_sub(florida_stream);
|
2024-08-03 03:05:34 +02:00
|
|
|
terms = [{operator: "stream", operand: florida_id.toString()}];
|
2023-12-22 00:26:14 +01:00
|
|
|
hash = hash_util.search_terms_to_hash(terms);
|
2020-07-15 01:29:15 +02:00
|
|
|
assert.equal(hash, "#narrow/stream/987-Florida.2C-USA");
|
|
|
|
narrow = hash_util.parse_narrow(hash.split("/"));
|
2024-08-03 03:05:34 +02:00
|
|
|
assert.deepEqual(narrow, [
|
|
|
|
{operator: "stream", operand: florida_id.toString(), negated: false},
|
|
|
|
]);
|
2018-05-15 15:59:50 +02:00
|
|
|
});
|
|
|
|
|
2024-04-12 13:45:46 +02:00
|
|
|
run_test("stream_to_channel_rename", () => {
|
|
|
|
let terms;
|
|
|
|
let hash;
|
|
|
|
let narrow;
|
|
|
|
let filter;
|
|
|
|
|
2024-04-24 21:00:16 +02:00
|
|
|
// Confirm the URLs generated from search terms use "stream" and "streams"
|
|
|
|
// and that the new Filter has the new "channel" and "channels" operators.
|
2024-08-03 03:05:34 +02:00
|
|
|
terms = [{operator: "channel", operand: devel_id.toString()}];
|
2024-04-12 13:45:46 +02:00
|
|
|
hash = hash_util.search_terms_to_hash(terms);
|
2024-08-03 03:05:34 +02:00
|
|
|
assert.equal(hash, "#narrow/stream/100-devel");
|
2024-04-12 13:45:46 +02:00
|
|
|
narrow = hash_util.parse_narrow(hash.split("/"));
|
2024-08-03 03:05:34 +02:00
|
|
|
assert.deepEqual(narrow, [{operator: "stream", operand: devel_id.toString(), negated: false}]);
|
2024-04-12 13:45:46 +02:00
|
|
|
filter = new Filter(narrow);
|
2024-08-03 03:05:34 +02:00
|
|
|
assert.deepEqual(filter.terms(), [
|
|
|
|
{operator: "channel", operand: devel_id.toString(), negated: false},
|
|
|
|
]);
|
2024-04-12 13:45:46 +02:00
|
|
|
|
|
|
|
terms = [{operator: "channels", operand: "public"}];
|
|
|
|
hash = hash_util.search_terms_to_hash(terms);
|
|
|
|
assert.equal(hash, "#narrow/streams/public");
|
|
|
|
narrow = hash_util.parse_narrow(hash.split("/"));
|
|
|
|
assert.deepEqual(narrow, [{operator: "streams", operand: "public", negated: false}]);
|
|
|
|
filter = new Filter(narrow);
|
|
|
|
assert.deepEqual(filter.terms(), [{operator: "channels", operand: "public", negated: false}]);
|
2024-04-24 21:00:16 +02:00
|
|
|
|
|
|
|
// Confirm that a narrow URL with "channel" and an enocoded stream/channel ID,
|
|
|
|
// will be decoded correctly.
|
2024-08-03 03:05:34 +02:00
|
|
|
const test_stream_id = 34;
|
2024-04-24 21:00:16 +02:00
|
|
|
const test_channel = {
|
|
|
|
name: "decode",
|
2024-08-03 03:05:34 +02:00
|
|
|
stream_id: test_stream_id,
|
2024-04-24 21:00:16 +02:00
|
|
|
};
|
|
|
|
stream_data.add_sub(test_channel);
|
|
|
|
hash = "#narrow/channel/34-decode";
|
|
|
|
narrow = hash_util.parse_narrow(hash.split("/"));
|
2024-08-03 03:05:34 +02:00
|
|
|
assert.deepEqual(narrow, [
|
|
|
|
{operator: "channel", operand: test_stream_id.toString(), negated: false},
|
|
|
|
]);
|
2024-04-24 21:00:16 +02:00
|
|
|
filter = new Filter(narrow);
|
2024-08-03 03:05:34 +02:00
|
|
|
assert.deepEqual(filter.terms(), [
|
|
|
|
{operator: "channel", operand: test_stream_id.toString(), negated: false},
|
|
|
|
]);
|
2024-04-12 13:45:46 +02:00
|
|
|
});
|
|
|
|
|
2023-12-22 00:26:14 +01:00
|
|
|
run_test("terms_trailing_slash", () => {
|
2024-08-03 03:05:34 +02:00
|
|
|
const hash = "#narrow/stream/100-devel/topic/algol/";
|
2020-07-15 01:29:15 +02:00
|
|
|
const narrow = hash_util.parse_narrow(hash.split("/"));
|
2018-05-15 15:59:50 +02:00
|
|
|
assert.deepEqual(narrow, [
|
2024-08-03 03:05:34 +02:00
|
|
|
{operator: "stream", operand: devel_id.toString(), negated: false},
|
2020-07-15 01:29:15 +02:00
|
|
|
{operator: "topic", operand: "algol", negated: false},
|
2018-02-15 21:02:47 +01:00
|
|
|
]);
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|
2017-01-19 03:53:50 +01:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
run_test("people_slugs", () => {
|
2023-12-22 00:26:14 +01:00
|
|
|
let terms;
|
2019-11-02 00:06:25 +01:00
|
|
|
let hash;
|
2023-04-11 21:04:33 +02:00
|
|
|
let narrow;
|
2017-01-19 03:53:50 +01:00
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const alice = {
|
2020-07-15 01:29:15 +02:00
|
|
|
email: "alice@example.com",
|
2017-01-19 03:53:50 +01:00
|
|
|
user_id: 42,
|
2020-07-15 01:29:15 +02:00
|
|
|
full_name: "Alice Smith",
|
2017-01-19 03:53:50 +01:00
|
|
|
};
|
|
|
|
|
2020-05-26 22:34:15 +02:00
|
|
|
people.add_active_user(alice);
|
2023-12-22 00:26:14 +01:00
|
|
|
terms = [{operator: "sender", operand: "alice@example.com"}];
|
|
|
|
hash = hash_util.search_terms_to_hash(terms);
|
2022-10-25 14:38:45 +02:00
|
|
|
assert.equal(hash, "#narrow/sender/42-Alice-Smith");
|
2023-04-11 21:04:33 +02:00
|
|
|
narrow = hash_util.parse_narrow(hash.split("/"));
|
2020-07-15 00:34:28 +02:00
|
|
|
assert.deepEqual(narrow, [{operator: "sender", operand: "alice@example.com", negated: false}]);
|
2017-01-19 03:53:50 +01:00
|
|
|
|
2023-12-22 00:26:14 +01:00
|
|
|
terms = [{operator: "dm", operand: "alice@example.com"}];
|
|
|
|
hash = hash_util.search_terms_to_hash(terms);
|
2023-04-11 21:04:33 +02:00
|
|
|
assert.equal(hash, "#narrow/dm/42-Alice-Smith");
|
|
|
|
narrow = hash_util.parse_narrow(hash.split("/"));
|
|
|
|
assert.deepEqual(narrow, [{operator: "dm", operand: "alice@example.com", negated: false}]);
|
|
|
|
|
|
|
|
// Even though we renamed "pm-with" to "dm", preexisting
|
|
|
|
// links/URLs with "pm-with" operator are handled correctly.
|
2023-12-22 00:26:14 +01:00
|
|
|
terms = [{operator: "pm-with", operand: "alice@example.com"}];
|
|
|
|
hash = hash_util.search_terms_to_hash(terms);
|
2022-10-25 14:38:45 +02:00
|
|
|
assert.equal(hash, "#narrow/pm-with/42-Alice-Smith");
|
2023-04-11 21:04:33 +02:00
|
|
|
narrow = hash_util.parse_narrow(hash.split("/"));
|
|
|
|
assert.deepEqual(narrow, [{operator: "pm-with", operand: "alice@example.com", negated: false}]);
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|
2018-04-11 13:14:39 +02:00
|
|
|
|
2023-10-07 01:08:53 +02:00
|
|
|
function test_helper({override, override_rewire, change_tab}) {
|
2019-11-02 00:06:25 +01:00
|
|
|
let events = [];
|
|
|
|
let narrow_terms;
|
2018-04-11 13:14:39 +02:00
|
|
|
|
2021-02-11 01:42:59 +01:00
|
|
|
function stub(module, func_name) {
|
|
|
|
module[func_name] = () => {
|
|
|
|
events.push([module, func_name]);
|
2018-04-11 13:14:39 +02:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2024-06-12 10:48:34 +02:00
|
|
|
function stub_with_args(module, func_name) {
|
|
|
|
module[func_name] = (...args) => {
|
|
|
|
events.push([module, func_name, args]);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
stub_with_args(admin, "launch");
|
2023-04-15 18:52:44 +02:00
|
|
|
stub(admin, "build_page");
|
2023-10-06 01:19:21 +02:00
|
|
|
stub(drafts_overlay_ui, "launch");
|
2021-02-11 01:42:59 +01:00
|
|
|
stub(message_viewport, "stop_auto_scrolling");
|
|
|
|
stub(overlays, "close_for_hash_change");
|
|
|
|
stub(settings, "launch");
|
2023-04-15 18:52:44 +02:00
|
|
|
stub(settings, "build_page");
|
2021-07-09 15:51:31 +02:00
|
|
|
stub(stream_settings_ui, "launch");
|
2021-02-11 01:42:59 +01:00
|
|
|
stub(ui_util, "blur_active_element");
|
2022-02-25 19:27:25 +01:00
|
|
|
stub(ui_report, "error");
|
2018-04-11 13:14:39 +02:00
|
|
|
|
2021-03-14 11:01:58 +01:00
|
|
|
if (change_tab) {
|
2024-06-05 10:51:22 +02:00
|
|
|
override_rewire(message_view, "show", (terms) => {
|
2021-03-14 11:01:58 +01:00
|
|
|
narrow_terms = terms;
|
2024-06-05 10:51:22 +02:00
|
|
|
events.push("message_view.show");
|
2021-03-14 11:01:58 +01:00
|
|
|
});
|
2018-04-11 13:14:39 +02:00
|
|
|
|
2021-03-14 11:01:58 +01:00
|
|
|
override(info_overlay, "show", (name) => {
|
|
|
|
events.push("info: " + name);
|
|
|
|
});
|
|
|
|
}
|
2018-04-11 13:14:39 +02:00
|
|
|
|
|
|
|
return {
|
2022-11-17 23:33:43 +01:00
|
|
|
clear_events() {
|
2018-04-11 13:14:39 +02:00
|
|
|
events = [];
|
|
|
|
},
|
2022-11-17 23:33:43 +01:00
|
|
|
assert_events(expected_events) {
|
2021-03-14 11:01:58 +01:00
|
|
|
assert.deepEqual(events, expected_events);
|
2018-04-11 13:14:39 +02:00
|
|
|
},
|
2020-07-02 01:41:40 +02:00
|
|
|
get_narrow_terms: () => narrow_terms,
|
2018-04-11 13:14:39 +02:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2023-10-07 01:08:53 +02:00
|
|
|
run_test("hash_interactions", ({override, override_rewire}) => {
|
2022-01-25 11:36:19 +01:00
|
|
|
$window_stub = $.create("window-stub");
|
2023-10-23 09:02:57 +02:00
|
|
|
user_settings.web_home_view = "recent_topics";
|
2021-03-14 11:01:58 +01:00
|
|
|
|
2023-10-07 01:08:53 +02:00
|
|
|
const helper = test_helper({override, override_rewire, change_tab: true});
|
2018-04-11 13:14:39 +02:00
|
|
|
|
2023-09-06 23:14:37 +02:00
|
|
|
let recent_view_ui_shown = false;
|
|
|
|
override(recent_view_ui, "show", () => {
|
|
|
|
recent_view_ui_shown = true;
|
2021-06-19 06:58:15 +02:00
|
|
|
});
|
2023-05-02 18:25:39 +02:00
|
|
|
let hide_all_called = false;
|
|
|
|
override(popovers, "hide_all", () => {
|
|
|
|
hide_all_called = true;
|
|
|
|
});
|
2021-06-19 06:58:15 +02:00
|
|
|
window.location.hash = "#unknown_hash";
|
2018-04-11 13:14:39 +02:00
|
|
|
|
2021-03-22 16:09:12 +01:00
|
|
|
browser_history.clear_for_testing();
|
2018-04-11 13:14:39 +02:00
|
|
|
hashchange.initialize();
|
2023-10-23 09:02:57 +02:00
|
|
|
// If it's an unknown hash it should show the home view.
|
2023-09-06 23:14:37 +02:00
|
|
|
assert.equal(recent_view_ui_shown, true);
|
2023-05-02 18:25:39 +02:00
|
|
|
assert.equal(hide_all_called, true);
|
2021-06-19 06:58:15 +02:00
|
|
|
helper.assert_events([
|
|
|
|
[overlays, "close_for_hash_change"],
|
|
|
|
[message_viewport, "stop_auto_scrolling"],
|
|
|
|
]);
|
|
|
|
|
2024-04-23 20:58:34 +02:00
|
|
|
window.location.hash = "#feed";
|
2023-05-02 18:25:39 +02:00
|
|
|
hide_all_called = false;
|
2021-06-19 06:58:15 +02:00
|
|
|
|
|
|
|
helper.clear_events();
|
2022-01-25 11:36:19 +01:00
|
|
|
$window_stub.trigger("hashchange");
|
2023-05-02 18:25:39 +02:00
|
|
|
assert.equal(hide_all_called, true);
|
2018-04-11 13:14:39 +02:00
|
|
|
helper.assert_events([
|
2021-02-11 01:42:59 +01:00
|
|
|
[overlays, "close_for_hash_change"],
|
|
|
|
[message_viewport, "stop_auto_scrolling"],
|
2024-06-05 10:51:22 +02:00
|
|
|
"message_view.show",
|
2018-04-11 13:14:39 +02:00
|
|
|
]);
|
|
|
|
|
|
|
|
helper.clear_events();
|
2022-01-25 11:36:19 +01:00
|
|
|
$window_stub.trigger("hashchange");
|
2018-04-11 13:14:39 +02:00
|
|
|
helper.assert_events([
|
2021-02-11 01:42:59 +01:00
|
|
|
[overlays, "close_for_hash_change"],
|
|
|
|
[message_viewport, "stop_auto_scrolling"],
|
2024-06-05 10:51:22 +02:00
|
|
|
"message_view.show",
|
2018-04-11 13:14:39 +02:00
|
|
|
]);
|
|
|
|
|
2022-10-24 12:18:09 +02:00
|
|
|
// Test old "#recent_topics" hash redirects to "#recent".
|
2023-09-06 23:14:37 +02:00
|
|
|
recent_view_ui_shown = false;
|
2022-10-24 12:18:09 +02:00
|
|
|
window.location.hash = "#recent_topics";
|
|
|
|
|
|
|
|
helper.clear_events();
|
|
|
|
$window_stub.trigger("hashchange");
|
2023-09-06 23:14:37 +02:00
|
|
|
assert.equal(recent_view_ui_shown, true);
|
2022-10-24 12:18:09 +02:00
|
|
|
helper.assert_events([
|
|
|
|
[overlays, "close_for_hash_change"],
|
|
|
|
[message_viewport, "stop_auto_scrolling"],
|
|
|
|
]);
|
|
|
|
assert.equal(window.location.hash, "#recent");
|
|
|
|
|
2024-08-03 03:05:34 +02:00
|
|
|
const denmark_id = 1;
|
|
|
|
stream_data.add_sub({
|
|
|
|
subscribed: true,
|
|
|
|
name: "Denmark",
|
|
|
|
stream_id: denmark_id,
|
|
|
|
});
|
2020-07-15 01:29:15 +02:00
|
|
|
window.location.hash = "#narrow/stream/Denmark";
|
2018-04-11 13:14:39 +02:00
|
|
|
|
|
|
|
helper.clear_events();
|
2022-01-25 11:36:19 +01:00
|
|
|
$window_stub.trigger("hashchange");
|
2018-04-11 13:14:39 +02:00
|
|
|
helper.assert_events([
|
2021-02-11 01:42:59 +01:00
|
|
|
[overlays, "close_for_hash_change"],
|
|
|
|
[message_viewport, "stop_auto_scrolling"],
|
2024-06-05 10:51:22 +02:00
|
|
|
"message_view.show",
|
2018-04-11 13:14:39 +02:00
|
|
|
]);
|
2019-11-02 00:06:25 +01:00
|
|
|
let terms = helper.get_narrow_terms();
|
2024-08-03 03:05:34 +02:00
|
|
|
assert.equal(terms[0].operand, denmark_id.toString());
|
2018-04-11 13:14:39 +02:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
window.location.hash = "#narrow";
|
2018-04-11 13:14:39 +02:00
|
|
|
|
|
|
|
helper.clear_events();
|
2022-01-25 11:36:19 +01:00
|
|
|
$window_stub.trigger("hashchange");
|
2018-04-11 13:14:39 +02:00
|
|
|
helper.assert_events([
|
2021-02-11 01:42:59 +01:00
|
|
|
[overlays, "close_for_hash_change"],
|
|
|
|
[message_viewport, "stop_auto_scrolling"],
|
2024-06-05 10:51:22 +02:00
|
|
|
"message_view.show",
|
2018-04-11 13:14:39 +02:00
|
|
|
]);
|
|
|
|
terms = helper.get_narrow_terms();
|
|
|
|
assert.equal(terms.length, 0);
|
|
|
|
|
2022-02-25 19:27:25 +01:00
|
|
|
// Test an invalid narrow hash
|
|
|
|
window.location.hash = "#narrow/foo.foo";
|
|
|
|
|
|
|
|
helper.clear_events();
|
2022-01-25 11:36:19 +01:00
|
|
|
$window_stub.trigger("hashchange");
|
2022-02-25 19:27:25 +01:00
|
|
|
helper.assert_events([
|
|
|
|
[overlays, "close_for_hash_change"],
|
|
|
|
[message_viewport, "stop_auto_scrolling"],
|
|
|
|
[ui_report, "error"],
|
|
|
|
]);
|
|
|
|
|
2024-04-30 13:30:24 +02:00
|
|
|
window.location.hash = "#channels/subscribed";
|
2018-04-11 13:14:39 +02:00
|
|
|
|
|
|
|
helper.clear_events();
|
2022-01-25 11:36:19 +01:00
|
|
|
$window_stub.trigger("hashchange");
|
2021-02-11 01:42:59 +01:00
|
|
|
helper.assert_events([
|
|
|
|
[overlays, "close_for_hash_change"],
|
2021-07-09 15:51:31 +02:00
|
|
|
[stream_settings_ui, "launch"],
|
2021-02-11 01:42:59 +01:00
|
|
|
]);
|
2018-04-11 13:14:39 +02:00
|
|
|
|
2023-09-06 23:14:37 +02:00
|
|
|
recent_view_ui_shown = false;
|
2021-06-28 05:08:55 +02:00
|
|
|
window.location.hash = "#reload:send_after_reload=0...";
|
|
|
|
|
|
|
|
helper.clear_events();
|
2022-01-25 11:36:19 +01:00
|
|
|
$window_stub.trigger("hashchange");
|
2021-06-28 05:08:55 +02:00
|
|
|
helper.assert_events([]);
|
2023-10-23 09:02:57 +02:00
|
|
|
// If it's reload hash it shouldn't show the home view.
|
2023-09-06 23:14:37 +02:00
|
|
|
assert.equal(recent_view_ui_shown, false);
|
2021-06-28 05:08:55 +02:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
window.location.hash = "#keyboard-shortcuts/whatever";
|
2018-04-11 13:14:39 +02:00
|
|
|
|
|
|
|
helper.clear_events();
|
2022-01-25 11:36:19 +01:00
|
|
|
$window_stub.trigger("hashchange");
|
2021-02-11 01:42:59 +01:00
|
|
|
helper.assert_events([[overlays, "close_for_hash_change"], "info: keyboard-shortcuts"]);
|
2018-04-11 13:14:39 +02:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
window.location.hash = "#message-formatting/whatever";
|
2018-04-11 13:14:39 +02:00
|
|
|
|
|
|
|
helper.clear_events();
|
2022-01-25 11:36:19 +01:00
|
|
|
$window_stub.trigger("hashchange");
|
2021-02-11 01:42:59 +01:00
|
|
|
helper.assert_events([[overlays, "close_for_hash_change"], "info: message-formatting"]);
|
2018-04-11 13:14:39 +02:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
window.location.hash = "#search-operators/whatever";
|
2018-04-11 13:14:39 +02:00
|
|
|
|
|
|
|
helper.clear_events();
|
2022-01-25 11:36:19 +01:00
|
|
|
$window_stub.trigger("hashchange");
|
2021-02-11 01:42:59 +01:00
|
|
|
helper.assert_events([[overlays, "close_for_hash_change"], "info: search-operators"]);
|
2018-04-11 13:14:39 +02:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
window.location.hash = "#drafts";
|
2018-04-11 13:14:39 +02:00
|
|
|
|
|
|
|
helper.clear_events();
|
2022-01-25 11:36:19 +01:00
|
|
|
$window_stub.trigger("hashchange");
|
2021-02-11 01:42:59 +01:00
|
|
|
helper.assert_events([
|
|
|
|
[overlays, "close_for_hash_change"],
|
2023-10-06 01:19:21 +02:00
|
|
|
[drafts_overlay_ui, "launch"],
|
2021-02-11 01:42:59 +01:00
|
|
|
]);
|
2018-04-11 13:14:39 +02:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
window.location.hash = "#settings/alert-words";
|
2018-04-11 13:14:39 +02:00
|
|
|
|
|
|
|
helper.clear_events();
|
2022-01-25 11:36:19 +01:00
|
|
|
$window_stub.trigger("hashchange");
|
2021-02-11 01:42:59 +01:00
|
|
|
helper.assert_events([
|
|
|
|
[overlays, "close_for_hash_change"],
|
2023-04-15 18:52:44 +02:00
|
|
|
[settings, "build_page"],
|
|
|
|
[admin, "build_page"],
|
2021-02-11 01:42:59 +01:00
|
|
|
[settings, "launch"],
|
|
|
|
]);
|
2018-04-11 13:14:39 +02:00
|
|
|
|
2024-05-30 11:28:49 +02:00
|
|
|
window.location.hash = "#organization/users/active";
|
2024-06-12 10:59:52 +02:00
|
|
|
|
|
|
|
helper.clear_events();
|
|
|
|
$window_stub.trigger("hashchange");
|
|
|
|
helper.assert_events([
|
|
|
|
[overlays, "close_for_hash_change"],
|
|
|
|
[settings, "build_page"],
|
|
|
|
[admin, "build_page"],
|
2024-05-30 11:28:49 +02:00
|
|
|
[admin, "launch", ["users", "active"]],
|
2024-06-12 10:59:52 +02:00
|
|
|
]);
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
window.location.hash = "#organization/user-list-admin";
|
2018-04-11 13:14:39 +02:00
|
|
|
|
2024-06-12 10:59:52 +02:00
|
|
|
// Check whether `user-list-admin` is redirect to `users`, we
|
|
|
|
// cannot test the exact hashchange here, since the section url
|
|
|
|
// takes effect in `admin.launch` and that's why we're checking
|
|
|
|
// the arguments passed to `admin.launch`.
|
2018-04-11 13:14:39 +02:00
|
|
|
helper.clear_events();
|
2022-01-25 11:36:19 +01:00
|
|
|
$window_stub.trigger("hashchange");
|
2021-02-11 01:42:59 +01:00
|
|
|
helper.assert_events([
|
|
|
|
[overlays, "close_for_hash_change"],
|
2023-04-15 18:52:44 +02:00
|
|
|
[settings, "build_page"],
|
|
|
|
[admin, "build_page"],
|
2024-05-30 11:28:49 +02:00
|
|
|
[admin, "launch", ["users", "active"]],
|
2021-02-11 01:42:59 +01:00
|
|
|
]);
|
2018-04-11 13:14:39 +02:00
|
|
|
|
|
|
|
helper.clear_events();
|
2021-03-22 16:09:12 +01:00
|
|
|
browser_history.exit_overlay();
|
2018-04-11 13:14:39 +02:00
|
|
|
|
2021-02-11 01:42:59 +01:00
|
|
|
helper.assert_events([[ui_util, "blur_active_element"]]);
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|
2018-04-11 13:14:39 +02:00
|
|
|
|
2024-05-11 13:04:38 +02:00
|
|
|
run_test("update_hash_to_match_filter", ({override, override_rewire}) => {
|
2023-10-07 01:08:53 +02:00
|
|
|
const helper = test_helper({override, override_rewire});
|
2018-04-11 13:14:39 +02:00
|
|
|
|
2023-12-22 00:26:14 +01:00
|
|
|
let terms = [{operator: "is", operand: "dm"}];
|
2018-04-11 13:14:39 +02:00
|
|
|
|
2023-05-25 22:30:20 +02:00
|
|
|
blueslip.expect("error", "browser does not support pushState");
|
2024-06-05 10:51:22 +02:00
|
|
|
message_view.update_hash_to_match_filter(new Filter(terms));
|
2018-12-06 22:59:05 +01:00
|
|
|
|
2021-02-11 01:42:59 +01:00
|
|
|
helper.assert_events([[message_viewport, "stop_auto_scrolling"]]);
|
2023-04-07 14:03:34 +02:00
|
|
|
assert.equal(window.location.hash, "#narrow/is/dm");
|
2018-04-11 13:14:39 +02:00
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
let url_pushed;
|
2023-06-29 21:59:08 +02:00
|
|
|
override(history, "pushState", (_state, _title, url) => {
|
2018-04-11 13:14:39 +02:00
|
|
|
url_pushed = url;
|
2021-03-14 11:01:58 +01:00
|
|
|
});
|
2018-04-11 13:14:39 +02:00
|
|
|
|
2023-12-22 00:26:14 +01:00
|
|
|
terms = [{operator: "is", operand: "starred"}];
|
2018-04-11 13:14:39 +02:00
|
|
|
|
|
|
|
helper.clear_events();
|
2024-06-05 10:51:22 +02:00
|
|
|
message_view.update_hash_to_match_filter(new Filter(terms));
|
2021-02-11 01:42:59 +01:00
|
|
|
helper.assert_events([[message_viewport, "stop_auto_scrolling"]]);
|
2021-10-14 00:23:21 +02:00
|
|
|
assert.equal(url_pushed, "http://zulip.zulipdev.com/#narrow/is/starred");
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|