Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

hash_parser: Add tests for is_overlay_hash, spectator compatibility.

Cesar Montoya45262e0cef36
diff --git a/web/tests/hash_util.test.cjs b/web/tests/hash_util.test.cjs
index 7516fe1c67d..0fd9440afe1 100644
--- a/web/tests/hash_util.test.cjs
+++ b/web/tests/hash_util.test.cjs
@@ -284,3 +284,98 @@ run_test("get_link_hash", () => {
);
assert.equal(hash_util.get_link_hash("bad-url"), "");
});
+
+run_test("test_is_overlay_hash", () => {
+ // All overlay categories should return true.
+ const overlay_hashes = [
+ "#streams/all",
+ "#channels/subscribed",
+ "#drafts",
+ "#groups",
+ "#settings/profile",
+ "#organization/profile",
+ "#invite",
+ "#keyboard-shortcuts",
+ "#message-formatting",
+ "#search-operators",
+ "#about-zulip",
+ "#scheduled",
+ "#reminders",
+ "#user/12345",
+ ];
+ for (const hash of overlay_hashes) {
+ assert.equal(hash_parser.is_overlay_hash(hash), true);
+ }
+
+ // Extra path segments still match on the category.
+ assert.equal(hash_parser.is_overlay_hash("#channels/1/general"), true);
+
+ // Non-overlay hashes should return false.
+ assert.equal(hash_parser.is_overlay_hash("#narrow/channel/99-frontend"), false);
+ assert.equal(hash_parser.is_overlay_hash("#recent"), false);
+ assert.equal(hash_parser.is_overlay_hash("#feed"), false);
+ assert.equal(hash_parser.is_overlay_hash(""), false);
+ assert.equal(hash_parser.is_overlay_hash(undefined), false);
+});
+
+run_test("test_is_an_allowed_web_public_narrow", () => {
+ // The special case: "is" operator with "resolved" operand.
+ assert.equal(hash_parser.is_an_allowed_web_public_narrow("is", "resolved"), true);
+
+ // "is" with other operands is not allowed.
+ assert.equal(hash_parser.is_an_allowed_web_public_narrow("is", "starred"), false);
+ assert.equal(hash_parser.is_an_allowed_web_public_narrow("is", "mentioned"), false);
+
+ // Allowed operators return true regardless of operand.
+ assert.equal(hash_parser.is_an_allowed_web_public_narrow("channel", "anything"), true);
+ assert.equal(hash_parser.is_an_allowed_web_public_narrow("topic", "anything"), true);
+ assert.equal(hash_parser.is_an_allowed_web_public_narrow("sender", "anything"), true);
+ assert.equal(hash_parser.is_an_allowed_web_public_narrow("has", "anything"), true);
+ assert.equal(hash_parser.is_an_allowed_web_public_narrow("search", "anything"), true);
+ assert.equal(hash_parser.is_an_allowed_web_public_narrow("near", "anything"), true);
+ assert.equal(hash_parser.is_an_allowed_web_public_narrow("id", "anything"), true);
+ assert.equal(hash_parser.is_an_allowed_web_public_narrow("with", "anything"), true);
+
+ // Disallowed operators should return false.
+ assert.equal(hash_parser.is_an_allowed_web_public_narrow("dm", "someone"), false);
+ assert.equal(hash_parser.is_an_allowed_web_public_narrow("dm-including", "someone"), false);
+});
+
+run_test("test_is_spectator_compatible", () => {
+ // Non-narrow allowed hashes.
+ assert.equal(hash_parser.is_spectator_compatible(""), true);
+ assert.equal(hash_parser.is_spectator_compatible("#recent"), true);
+ assert.equal(hash_parser.is_spectator_compatible("#recent_topics"), true);
+ assert.equal(hash_parser.is_spectator_compatible("#feed"), true);
+ assert.equal(hash_parser.is_spectator_compatible("#all_messages"), true);
+ assert.equal(hash_parser.is_spectator_compatible("#keyboard-shortcuts"), true);
+ assert.equal(hash_parser.is_spectator_compatible("#message-formatting"), true);
+ assert.equal(hash_parser.is_spectator_compatible("#search-operators"), true);
+ assert.equal(hash_parser.is_spectator_compatible("#about-zulip"), true);
+ assert.equal(hash_parser.is_spectator_compatible("#topics"), true);
+
+ // Narrow hashes with allowed operators.
+ assert.equal(hash_parser.is_spectator_compatible("#narrow/channel/99-frontend"), true);
+ assert.equal(
+ hash_parser.is_spectator_compatible("#narrow/channel/99-frontend/topic/testing"),
+ true,
+ );
+ assert.equal(hash_parser.is_spectator_compatible("#narrow/sender/15"), true);
+ assert.equal(hash_parser.is_spectator_compatible("#narrow/has/link"), true);
+ assert.equal(hash_parser.is_spectator_compatible("#narrow/search/hello"), true);
+ assert.equal(hash_parser.is_spectator_compatible("#narrow/id/42"), true);
+ assert.equal(hash_parser.is_spectator_compatible("#narrow/near/100"), true);
+ assert.equal(hash_parser.is_spectator_compatible("#narrow/with/5"), true);
+
+ // Narrow hashes with disallowed operators.
+ assert.equal(hash_parser.is_spectator_compatible("#narrow/dm/15-dm"), false);
+ assert.equal(hash_parser.is_spectator_compatible("#narrow/is/starred"), false);
+
+ // Narrow with "is/resolved" is allowed via is_an_allowed_web_public_narrow.
+ assert.equal(hash_parser.is_spectator_compatible("#narrow/is/resolved"), true);
+
+ // Hashes that are neither narrow nor in the allowed list.
+ assert.equal(hash_parser.is_spectator_compatible("#settings/profile"), false);
+ assert.equal(hash_parser.is_spectator_compatible("#drafts"), false);
+ assert.equal(hash_parser.is_spectator_compatible("#channels/subscribed"), false);
+});