Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
node tests: Clear data for presence tests.
Steve Howellf5506c78aadc
diff --git a/frontend_tests/node_tests/presence.js b/frontend_tests/node_tests/presence.jsindex 3131f52bc3f..289a6f166c4 100644--- a/frontend_tests/node_tests/presence.js+++ b/frontend_tests/node_tests/presence.js@@ -74,11 +74,18 @@ people.add_active_user(john);people.add_active_user(jane);people.initialize_current_user(me.user_id);-run_test("my user", () => {+function test(label, f) {+ run_test(label, (override) => {+ presence.clear_internal_data();+ f(override);+ });+}++test("my user", () => {assert.equal(presence.get_status(me.user_id), "active");});-run_test("unknown user", (override) => {+test("unknown user", (override) => {const unknown_user_id = 999;const now = 888888;const presences = {};@@ -98,7 +105,7 @@ run_test("unknown user", (override) => {presence.set_info(presences, now);});-run_test("status_from_raw", () => {+test("status_from_raw", () => {const status_from_raw = presence.status_from_raw;const now = 5000;@@ -135,7 +142,7 @@ run_test("status_from_raw", () => {});});-run_test("set_presence_info", () => {+test("set_presence_info", () => {const presences = {};const now = 5000;const recent = now + 1 - OFFLINE_THRESHOLD_SECS;@@ -210,7 +217,7 @@ run_test("set_presence_info", () => {assert.equal(presence.get_status(jane.user_id), "idle");});-run_test("falsy values", () => {+test("falsy values", () => {/*When a user does not have a relevant active timestamp,the server just leaves off the `active_timestamp` field@@ -252,7 +259,7 @@ run_test("falsy values", () => {}});-run_test("big realms", () => {+test("big realms", () => {const presences = {};const now = 5000;@@ -271,7 +278,7 @@ run_test("big realms", () => {people.get_active_human_count = get_active_human_count;});-run_test("last_active_date", () => {+test("last_active_date", () => {const unknown_id = 42;presence.presence_info.clear();presence.presence_info.set(alice.user_id, {last_active: 500});@@ -282,7 +289,7 @@ run_test("last_active_date", () => {assert.deepEqual(presence.last_active_date(alice.user_id), new Date(500 * 1000));});-run_test("update_info_from_event", () => {+test("update_info_from_event", () => {let info;info = {diff --git a/static/js/presence.js b/static/js/presence.jsindex 2d22ef0dd5b..f00cab18194 100644--- a/static/js/presence.js+++ b/static/js/presence.js@@ -14,6 +14,12 @@ import * as server_events from "./server_events";const raw_info = new Map();export const presence_info = new Map();+// We use this internally and export it for testing convenience.+export function clear_internal_data() {+ raw_info.clear();+ presence_info.clear();+}+/* Mark users as offline after 140 seconds since their last checkin,* Keep in sync with zerver/tornado/event_queue.py:receiver_is_idle*/@@ -148,8 +154,7 @@ export function set_info(presences, server_timestamp) {}*/- raw_info.clear();- presence_info.clear();+ clear_internal_data();for (const [user_id_str, info] of Object.entries(presences)) {const user_id = Number.parseInt(user_id_str, 10);