mirror of
https://github.com/zulip/zulip.git
synced 2025-10-24 00:23:49 +00:00
hash_util: Extract functions to be reused without window.
These functions can now be used in other libraries without using window.location.hash in them and directly calling these functions.
This commit is contained in:
@@ -14,7 +14,7 @@ const ui_report = mock_esm("../../static/js/ui_report", {
|
||||
ui_report.displayed_error = true;
|
||||
},
|
||||
});
|
||||
set_global("location", {
|
||||
const location = set_global("location", {
|
||||
protocol: "https:",
|
||||
host: "example.com",
|
||||
pathname: "/",
|
||||
@@ -87,6 +87,9 @@ run_test("test_get_hash_category", () => {
|
||||
assert.deepEqual(hash_util.get_hash_category("#settings/display-settings"), "settings");
|
||||
assert.deepEqual(hash_util.get_hash_category("#drafts"), "drafts");
|
||||
assert.deepEqual(hash_util.get_hash_category("invites"), "invites");
|
||||
|
||||
location.hash = "#settings/your-account";
|
||||
assert.deepEqual(hash_util.get_current_hash_category(), "settings");
|
||||
});
|
||||
|
||||
run_test("test_get_hash_section", () => {
|
||||
@@ -97,6 +100,9 @@ run_test("test_get_hash_section", () => {
|
||||
|
||||
assert.equal(hash_util.get_hash_section("#drafts"), "");
|
||||
assert.equal(hash_util.get_hash_section(""), "");
|
||||
|
||||
location.hash = "#settings/your-account";
|
||||
assert.deepEqual(hash_util.get_current_hash_section(), "your-account");
|
||||
});
|
||||
|
||||
run_test("test_parse_narrow", () => {
|
||||
|
||||
@@ -23,6 +23,14 @@ export function get_hash_section(hash) {
|
||||
return parts[1] || "";
|
||||
}
|
||||
|
||||
export function get_current_hash_category() {
|
||||
return get_hash_category(window.location.hash);
|
||||
}
|
||||
|
||||
export function get_current_hash_section() {
|
||||
return get_hash_section(window.location.hash);
|
||||
}
|
||||
|
||||
const hashReplacements = new Map([
|
||||
["%", "."],
|
||||
["(", ".28"],
|
||||
|
||||
@@ -171,9 +171,9 @@ function do_hashchange_overlay(old_hash) {
|
||||
// background and recent topics seems preferable for that.
|
||||
recent_topics.show();
|
||||
}
|
||||
const base = hash_util.get_hash_category(window.location.hash);
|
||||
const base = hash_util.get_current_hash_category();
|
||||
const old_base = hash_util.get_hash_category(old_hash);
|
||||
const section = hash_util.get_hash_section(window.location.hash);
|
||||
const section = hash_util.get_current_hash_section();
|
||||
|
||||
const coming_from_overlay = hash_util.is_overlay_hash(old_hash || "#");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user