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:
93
web/tests/example3.test.cjs
Normal file
93
web/tests/example3.test.cjs
Normal file
@@ -0,0 +1,93 @@
|
||||
"use strict";
|
||||
|
||||
const assert = require("node:assert/strict");
|
||||
|
||||
const {make_realm} = require("./lib/example_realm.cjs");
|
||||
const {make_stream} = require("./lib/example_stream.cjs");
|
||||
const {make_message_list} = require("./lib/message_list.cjs");
|
||||
const {zrequire} = require("./lib/namespace.cjs");
|
||||
const {run_test} = require("./lib/test.cjs");
|
||||
|
||||
// In the Zulip app you can narrow your message stream by topic, by
|
||||
// sender, by direct message recipient, by search keywords, etc.
|
||||
// We will discuss narrows more broadly, but first let's test out a
|
||||
// core piece of code that makes things work.
|
||||
|
||||
const {Filter} = zrequire("../src/filter");
|
||||
const {set_realm} = zrequire("state_data");
|
||||
const stream_data = zrequire("stream_data");
|
||||
|
||||
set_realm(make_realm());
|
||||
|
||||
const denmark_stream = make_stream({
|
||||
color: "blue",
|
||||
name: "Denmark",
|
||||
stream_id: 101,
|
||||
subscribed: false,
|
||||
});
|
||||
|
||||
run_test("filter", () => {
|
||||
stream_data.clear_subscriptions();
|
||||
stream_data.add_sub_for_tests(denmark_stream);
|
||||
|
||||
const filter_terms = [
|
||||
{operator: "stream", operand: denmark_stream.stream_id.toString()},
|
||||
{operator: "topic", operand: "copenhagen"},
|
||||
];
|
||||
|
||||
const filter = new Filter(filter_terms);
|
||||
|
||||
const predicate = filter.predicate();
|
||||
|
||||
// We don't need full-fledged messages to test the gist of
|
||||
// our filter. If there are details that are distracting from
|
||||
// your test, you should not feel guilty about removing them.
|
||||
assert.equal(predicate({type: "personal"}), false);
|
||||
|
||||
assert.equal(
|
||||
predicate({
|
||||
type: "stream",
|
||||
stream_id: denmark_stream.stream_id,
|
||||
topic: "does not match filter",
|
||||
}),
|
||||
false,
|
||||
);
|
||||
|
||||
assert.equal(
|
||||
predicate({
|
||||
type: "stream",
|
||||
stream_id: denmark_stream.stream_id,
|
||||
topic: "copenhagen",
|
||||
}),
|
||||
true,
|
||||
);
|
||||
});
|
||||
|
||||
// We have a "narrow" abstraction that sits roughly on top of the
|
||||
// "filter" abstraction. If you are in a narrow, we track the
|
||||
// state with the narrow_state module.
|
||||
|
||||
const narrow_state = zrequire("narrow_state");
|
||||
const message_lists = zrequire("message_lists");
|
||||
|
||||
run_test("narrow_state", () => {
|
||||
stream_data.clear_subscriptions();
|
||||
stream_data.add_sub_for_tests(denmark_stream);
|
||||
message_lists.set_current(undefined);
|
||||
|
||||
// As we often do, first make assertions about the starting
|
||||
// state:
|
||||
|
||||
assert.equal(narrow_state.stream_name(), undefined);
|
||||
|
||||
// Now set up a Filter object.
|
||||
const filter_terms = [
|
||||
{operator: "stream", operand: denmark_stream.stream_id.toString()},
|
||||
{operator: "topic", operand: "copenhagen"},
|
||||
];
|
||||
|
||||
// And here is where we actually change state.
|
||||
message_lists.set_current(make_message_list(filter_terms));
|
||||
assert.equal(narrow_state.stream_name(), "Denmark");
|
||||
assert.equal(narrow_state.topic(), "copenhagen");
|
||||
});
|
||||
Reference in New Issue
Block a user