Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
hash_util: Extract functions to be reused without `window`.
Aman Agrawale7129af8acf8
diff --git a/frontend_tests/node_tests/hash_util.js b/frontend_tests/node_tests/hash_util.jsindex ab923692138..179b7dfc00e 100644--- a/frontend_tests/node_tests/hash_util.js+++ b/frontend_tests/node_tests/hash_util.js@@ -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", () => {diff --git a/static/js/hash_util.js b/static/js/hash_util.jsindex ddae9db1050..ad40d9a8160 100644--- a/static/js/hash_util.js+++ b/static/js/hash_util.js@@ -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"],diff --git a/static/js/hashchange.js b/static/js/hashchange.jsindex f25df9cfd8f..eb7b5552776 100644--- a/static/js/hashchange.js+++ b/static/js/hashchange.js@@ -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 || "#");