diff --git a/web/tests/hash_util.test.js b/web/tests/hash_util.test.js index 149fb24ee1..4c3cdfea30 100644 --- a/web/tests/hash_util.test.js +++ b/web/tests/hash_util.test.js @@ -2,6 +2,8 @@ const {strict: assert} = require("assert"); +const message_link_test_cases = require("../../zerver/tests/fixtures/message_link_test_cases"); + const {zrequire} = require("./lib/namespace"); const {run_test} = require("./lib/test"); @@ -88,39 +90,12 @@ run_test("get_current_nth_hash_section", () => { }); run_test("test_is_same_server_message_link", () => { - const dm_message_link = "#narrow/dm/9,15-dm/near/43"; - assert.equal(hash_parser.is_same_server_message_link(dm_message_link), true); - - const group_message_link = "#narrow/dm/9,16,15-group/near/68"; - assert.equal(hash_parser.is_same_server_message_link(group_message_link), true); - - const stream_message_link = "#narrow/stream/8-design/topic/desktop/near/82"; - assert.equal(hash_parser.is_same_server_message_link(stream_message_link), true); - - const stream_link = "#narrow/stream/8-design"; - assert.equal(hash_parser.is_same_server_message_link(stream_link), false); - - const topic_link = "#narrow/stream/8-design/topic/desktop"; - assert.equal(hash_parser.is_same_server_message_link(topic_link), false); - - const dm_link = "#narrow/dm/15-John"; - assert.equal(hash_parser.is_same_server_message_link(dm_link), false); - - const search_link = "#narrow/search/database"; - assert.equal(hash_parser.is_same_server_message_link(search_link), false); - - const different_server_message_link = - "https://fakechat.zulip.org/#narrow/dm/8,1848,2369-group/near/1717378"; - assert.equal(hash_parser.is_same_server_message_link(different_server_message_link), false); - - const drafts_link = "#drafts"; - assert.equal(hash_parser.is_same_server_message_link(drafts_link), false); - - const empty_link = "#"; - assert.equal(hash_parser.is_same_server_message_link(empty_link), false); - - const non_zulip_link = "https://www.google.com"; - assert.equal(hash_parser.is_same_server_message_link(non_zulip_link), false); + for (const message_link_test_case of message_link_test_cases) { + assert.equal( + hash_parser.is_same_server_message_link(message_link_test_case.message_link), + message_link_test_case.expected_output, + ); + } }); run_test("build_reload_url", () => { diff --git a/zerver/tests/fixtures/message_link_test_cases.json b/zerver/tests/fixtures/message_link_test_cases.json new file mode 100644 index 0000000000..6cdfad33ff --- /dev/null +++ b/zerver/tests/fixtures/message_link_test_cases.json @@ -0,0 +1,57 @@ +[ + { + "name": "dm_message_link", + "message_link": "#narrow/dm/9,15-dm/near/43", + "expected_output": true + }, + { + "name": "group_message_link", + "message_link": "#narrow/dm/9,16,15-group/near/68", + "expected_output": true + }, + { + "name": "stream_message_link", + "message_link": "#narrow/stream/8-design/topic/desktop/near/82", + "expected_output": true + }, + { + "name": "stream_link", + "message_link": "#narrow/stream/8-design", + "expected_output": false + }, + { + "name": "topic_link", + "message_link": "#narrow/stream/8-design/topic/desktop", + "expected_output": false + }, + { + "name": "dm_link", + "message_link": "#narrow/dm/15-John", + "expected_output": false + }, + { + "name": "search_link", + "message_link": "#narrow/search/database", + "expected_output": false + }, + { + "name": "different_server_message_link", + "message_link": "https://fakechat.zulip.org/#narrow/dm/8,1848,2369-group/near/1717378", + "expected_output": false + }, + { + "name": "drafts_link", + "message_link": "#drafts", + "expected_output": false + }, + { + "name": "empty_link", + "message_link": "#", + "expected_output": false + }, + { + "name": "non_zulip_link", + "message_link": "https://www.google.com", + "expected_output": false + } +]