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.

node tests: Clean up pm_conversations.

Steve Howell71ccb99531b2
diff --git a/frontend_tests/node_tests/pm_conversations.js b/frontend_tests/node_tests/pm_conversations.js
index 0df2ae440af..6f469368fc5 100644
--- a/frontend_tests/node_tests/pm_conversations.js
+++ b/frontend_tests/node_tests/pm_conversations.js
@@ -5,8 +5,14 @@ const {strict: assert} = require("assert");
const {zrequire} = require("../zjsunit/namespace");
const {run_test} = require("../zjsunit/test");
+const people = zrequire("people");
const pmc = zrequire("pm_conversations");
+function initialize_recents(params) {
+ pmc.recent.clear_for_testing();
+ pmc.recent.initialize(params);
+}
+
run_test("partners", () => {
const user1_id = 1;
const user2_id = 2;
@@ -20,8 +26,6 @@ run_test("partners", () => {
assert.equal(pmc.is_partner(user3_id), true);
});
-const people = zrequire("people");
-
run_test("insert_recent_private_message", () => {
const params = {
recent_private_conversations: [
@@ -31,7 +35,7 @@ run_test("insert_recent_private_message", () => {
],
};
people.initialize_current_user(15);
- pmc.recent.initialize(params);
+ initialize_recents(params);
assert.deepEqual(pmc.recent.get(), [
{user_ids_string: "2,11", max_message_id: 150},
diff --git a/static/js/pm_conversations.js b/static/js/pm_conversations.js
index bc8d0bbef17..ccf99ee3d46 100644
--- a/static/js/pm_conversations.js
+++ b/static/js/pm_conversations.js
@@ -18,6 +18,12 @@ class RecentPrivateMessages {
recent_message_ids = new FoldDict(); // key is user_ids_string
recent_private_messages = [];
+ clear_for_testing() {
+ // Because we only export the singleton, we need this for tests.
+ this.recent_message_ids.clear();
+ this.recent_private_messages.length = 0;
+ }
+
insert(user_ids, message_id) {
if (user_ids.length === 0) {
// The server sends [] for self-PMs.