snapshot of https://github.com/zulip/zulip.git @ 48c69911c7dd4e03b20552eb3bd77ad8151c1357 (2026-09-15)
Some checks failed
Code scanning / CodeQL (push) Failing after 15s
Zulip production suite / Ubuntu 22.04 production build (push) Failing after 26s
Zulip production suite / Debian 12 production install with custom db name and user (push) Has been skipped
Zulip production suite / Ubuntu 22.04 production install and PostgreSQL upgrade with pgroonga (push) Has been skipped
Zulip production suite / Ubuntu 24.04 production install (push) Has been skipped
Zulip production suite / Ubuntu 26.04 production install (push) Has been skipped
Zulip production suite / Debian 13 production install (push) Has been skipped
Zulip production suite / 7.0 Version Upgrade (push) Has been skipped
Zulip production suite / 8.0 Version Upgrade (push) Has been skipped
Zulip production suite / 6.0 Version Upgrade (push) Has been skipped
Zulip production suite / 10.0 Version Upgrade (push) Has been skipped
Zulip production suite / 9.0 Version Upgrade (push) Has been skipped
Zulip production suite / 12.0 Version Upgrade (push) Has been skipped
Zulip production suite / 11.0 Version Upgrade (push) Has been skipped
GitHub Actions Security Analysis with zizmor / zizmor (push) Failing after 3s
Zulip CI / Debian 12 (Python 3.11, backend + documentation) (push) Failing after 26s
Zulip CI / Ubuntu 22.04 (Python 3.10, backend + frontend) (push) Failing after 3s
Zulip CI / Ubuntu 24.04 (Python 3.12, backend) (push) Failing after 25s
Zulip CI / Ubuntu 26.04 (Python 3.14, backend) (push) Failing after 25s
Zulip CI / Debian 13 (Python 3.13, backend) (push) Failing after 28s
Zulip production suite / Required jobs (push) Has been cancelled
Zulip CI / Required jobs (push) Has been cancelled
API Documentation Update Check / check-feature-level-updated (push) Has been cancelled
API Documentation Update Check / notify-if-api-docs-changed (push) Has been cancelled
Some checks failed
Code scanning / CodeQL (push) Failing after 15s
Zulip production suite / Ubuntu 22.04 production build (push) Failing after 26s
Zulip production suite / Debian 12 production install with custom db name and user (push) Has been skipped
Zulip production suite / Ubuntu 22.04 production install and PostgreSQL upgrade with pgroonga (push) Has been skipped
Zulip production suite / Ubuntu 24.04 production install (push) Has been skipped
Zulip production suite / Ubuntu 26.04 production install (push) Has been skipped
Zulip production suite / Debian 13 production install (push) Has been skipped
Zulip production suite / 7.0 Version Upgrade (push) Has been skipped
Zulip production suite / 8.0 Version Upgrade (push) Has been skipped
Zulip production suite / 6.0 Version Upgrade (push) Has been skipped
Zulip production suite / 10.0 Version Upgrade (push) Has been skipped
Zulip production suite / 9.0 Version Upgrade (push) Has been skipped
Zulip production suite / 12.0 Version Upgrade (push) Has been skipped
Zulip production suite / 11.0 Version Upgrade (push) Has been skipped
GitHub Actions Security Analysis with zizmor / zizmor (push) Failing after 3s
Zulip CI / Debian 12 (Python 3.11, backend + documentation) (push) Failing after 26s
Zulip CI / Ubuntu 22.04 (Python 3.10, backend + frontend) (push) Failing after 3s
Zulip CI / Ubuntu 24.04 (Python 3.12, backend) (push) Failing after 25s
Zulip CI / Ubuntu 26.04 (Python 3.14, backend) (push) Failing after 25s
Zulip CI / Debian 13 (Python 3.13, backend) (push) Failing after 28s
Zulip production suite / Required jobs (push) Has been cancelled
Zulip CI / Required jobs (push) Has been cancelled
API Documentation Update Check / check-feature-level-updated (push) Has been cancelled
API Documentation Update Check / notify-if-api-docs-changed (push) Has been cancelled
This commit is contained in:
111
web/tests/example2.test.cjs
Normal file
111
web/tests/example2.test.cjs
Normal file
@@ -0,0 +1,111 @@
|
||||
"use strict";
|
||||
|
||||
const assert = require("node:assert/strict");
|
||||
|
||||
const {make_stream} = require("./lib/example_stream.cjs");
|
||||
const {make_user} = require("./lib/example_user.cjs");
|
||||
const {zrequire} = require("./lib/namespace.cjs");
|
||||
const {run_test} = require("./lib/test.cjs");
|
||||
|
||||
// Hopefully the basic patterns for testing data-oriented modules
|
||||
// are starting to become apparent. To reinforce that, we will present
|
||||
// few more examples that also expose you to some of our core
|
||||
// data objects. Also, we start testing some objects that have
|
||||
// deeper dependencies.
|
||||
|
||||
const message_helper = zrequire("message_helper");
|
||||
const message_store = zrequire("message_store");
|
||||
const people = zrequire("people");
|
||||
const stream_data = zrequire("stream_data");
|
||||
const stream_topic_history = zrequire("stream_topic_history");
|
||||
const unread = zrequire("unread");
|
||||
const {initialize_user_settings} = zrequire("user_settings");
|
||||
|
||||
// It's typical to set up a little bit of data at the top of a
|
||||
// test module, but you can also do this within tests. Here we
|
||||
// will set up things at the top.
|
||||
|
||||
initialize_user_settings({user_settings: {}});
|
||||
|
||||
const isaac = make_user({
|
||||
email: "isaac@example.com",
|
||||
user_id: 30,
|
||||
full_name: "Isaac Newton",
|
||||
});
|
||||
|
||||
const denmark_stream = make_stream({
|
||||
color: "blue",
|
||||
name: "Denmark",
|
||||
stream_id: 101,
|
||||
subscribed: false,
|
||||
});
|
||||
|
||||
const messages = {
|
||||
isaac_to_denmark_stream: {
|
||||
id: 400,
|
||||
sender_id: isaac.user_id,
|
||||
stream_id: denmark_stream.stream_id,
|
||||
type: "stream",
|
||||
flags: ["has_alert_word"],
|
||||
subject: "copenhagen",
|
||||
reactions: [],
|
||||
submessages: [],
|
||||
// note we don't have every field that a "real" message
|
||||
// would have, and that can be fine
|
||||
},
|
||||
};
|
||||
|
||||
// We aren't going to modify isaac in our tests, so we will
|
||||
// create him at the top.
|
||||
people.add_active_user(isaac);
|
||||
|
||||
// We are going to test a core module called messages_store.js next.
|
||||
// This is an example of a deep unit test, where our dependencies
|
||||
// are easy to test.
|
||||
|
||||
run_test("message_store", () => {
|
||||
message_store.clear_for_testing();
|
||||
stream_data.clear_subscriptions();
|
||||
stream_data.add_sub_for_tests(denmark_stream);
|
||||
|
||||
const in_message = {...messages.isaac_to_denmark_stream};
|
||||
|
||||
assert.equal(in_message.alerted, undefined);
|
||||
|
||||
// Let's add a message into our message_store via
|
||||
// message_helper.process_new_message.
|
||||
assert.equal(message_store.get(in_message.id), undefined);
|
||||
message_helper.process_new_message({
|
||||
type: "server_message",
|
||||
raw_message: in_message,
|
||||
});
|
||||
const message = message_store.get(in_message.id);
|
||||
assert.equal(message.alerted, true);
|
||||
|
||||
// There are more side effects.
|
||||
const topic_names = stream_topic_history.get_recent_topic_names(denmark_stream.stream_id);
|
||||
assert.deepEqual(topic_names, ["copenhagen"]);
|
||||
});
|
||||
|
||||
// Tracking unread messages is a very fundamental part of the Zulip
|
||||
// app, and we use the unread object to track unread messages.
|
||||
|
||||
run_test("unread", () => {
|
||||
unread.declare_bankruptcy();
|
||||
stream_data.clear_subscriptions();
|
||||
stream_data.add_sub_for_tests(denmark_stream);
|
||||
|
||||
const stream_id = denmark_stream.stream_id;
|
||||
const topic_name = "copenhagen";
|
||||
|
||||
assert.equal(unread.num_unread_for_topic(stream_id, topic_name), 0);
|
||||
|
||||
let in_message = {...messages.isaac_to_denmark_stream};
|
||||
in_message = message_helper.process_new_message({
|
||||
type: "server_message",
|
||||
raw_message: in_message,
|
||||
});
|
||||
|
||||
unread.process_loaded_messages([in_message.message]);
|
||||
assert.equal(unread.num_unread_for_topic(stream_id, topic_name), 1);
|
||||
});
|
||||
Reference in New Issue
Block a user