2020-08-01 03:43:15 +02:00
|
|
|
"use strict";
|
|
|
|
|
2024-10-09 00:25:41 +02:00
|
|
|
const assert = require("node:assert/strict");
|
2020-11-30 23:46:45 +01:00
|
|
|
|
2020-07-25 02:02:35 +02:00
|
|
|
const _ = require("lodash");
|
|
|
|
|
2023-02-22 23:04:10 +01:00
|
|
|
const {mock_esm, zrequire} = require("./lib/namespace");
|
|
|
|
const {run_test} = require("./lib/test");
|
2020-12-01 00:02:16 +01:00
|
|
|
|
2023-02-22 23:04:10 +01:00
|
|
|
mock_esm("../src/message_store", {
|
2022-10-14 17:37:47 +02:00
|
|
|
get() {
|
|
|
|
return {
|
|
|
|
stream_id: 556,
|
|
|
|
topic: "general",
|
|
|
|
};
|
|
|
|
},
|
|
|
|
});
|
2023-02-22 23:04:10 +01:00
|
|
|
const user_topics = mock_esm("../src/user_topics", {
|
2021-02-24 17:24:06 +01:00
|
|
|
is_topic_muted() {
|
|
|
|
return false;
|
|
|
|
},
|
2023-08-25 16:07:32 +02:00
|
|
|
is_topic_followed() {
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
is_topic_unmuted_or_followed() {
|
2023-04-22 18:14:26 +02:00
|
|
|
return false;
|
|
|
|
},
|
2021-03-07 13:57:14 +01:00
|
|
|
});
|
2023-02-22 23:04:10 +01:00
|
|
|
const narrow_state = mock_esm("../src/narrow_state", {
|
2021-03-07 13:57:14 +01:00
|
|
|
topic() {},
|
2024-03-20 23:26:23 +01:00
|
|
|
stream_id() {},
|
2021-03-07 13:57:14 +01:00
|
|
|
});
|
2021-03-06 17:37:51 +01:00
|
|
|
|
2024-10-09 22:44:13 +02:00
|
|
|
const {set_realm} = zrequire("state_data");
|
2021-03-07 13:57:14 +01:00
|
|
|
const stream_data = zrequire("stream_data");
|
2021-02-10 04:53:22 +01:00
|
|
|
const stream_topic_history = zrequire("stream_topic_history");
|
2020-07-15 01:29:15 +02:00
|
|
|
const topic_list_data = zrequire("topic_list_data");
|
2021-03-07 13:57:14 +01:00
|
|
|
const unread = zrequire("unread");
|
2016-11-05 16:36:30 +01:00
|
|
|
|
2024-10-09 22:44:13 +02:00
|
|
|
set_realm({});
|
|
|
|
|
2020-01-18 12:06:56 +01:00
|
|
|
const general = {
|
|
|
|
stream_id: 556,
|
2020-07-15 01:29:15 +02:00
|
|
|
name: "general",
|
2020-01-18 12:06:56 +01:00
|
|
|
};
|
2018-12-13 22:26:10 +01:00
|
|
|
|
2020-02-09 22:02:55 +01:00
|
|
|
stream_data.add_sub(general);
|
2016-11-05 16:36:30 +01:00
|
|
|
|
2023-04-12 13:22:52 +02:00
|
|
|
function get_list_info(zoom, search) {
|
2020-01-18 12:06:56 +01:00
|
|
|
const stream_id = general.stream_id;
|
2023-04-12 13:22:52 +02:00
|
|
|
const zoomed = zoom === undefined ? false : zoom;
|
|
|
|
const search_term = search === undefined ? "" : search;
|
|
|
|
return topic_list_data.get_list_info(stream_id, zoomed, search_term);
|
2020-01-18 12:06:56 +01:00
|
|
|
}
|
|
|
|
|
2021-03-12 23:47:39 +01:00
|
|
|
function test(label, f) {
|
2022-07-10 01:06:33 +02:00
|
|
|
run_test(label, (helpers) => {
|
2021-03-12 23:47:39 +01:00
|
|
|
stream_topic_history.reset();
|
2022-07-10 01:06:33 +02:00
|
|
|
f(helpers);
|
2021-03-12 23:47:39 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-06-16 14:38:37 +02:00
|
|
|
test("get_list_info w/real stream_topic_history", ({override}) => {
|
2020-01-18 14:03:08 +01:00
|
|
|
let list_info;
|
2020-01-18 12:06:56 +01:00
|
|
|
const empty_list_info = get_list_info();
|
|
|
|
|
|
|
|
assert.deepEqual(empty_list_info, {
|
|
|
|
items: [],
|
2022-08-21 23:05:56 +02:00
|
|
|
more_topics_have_unread_mention_messages: false,
|
2020-01-18 12:06:56 +01:00
|
|
|
more_topics_unreads: 0,
|
2023-05-02 02:24:11 +02:00
|
|
|
more_topics_unread_count_muted: false,
|
2020-01-18 12:06:56 +01:00
|
|
|
num_possible_topics: 0,
|
2017-07-24 22:16:13 +02:00
|
|
|
});
|
|
|
|
|
2021-06-08 18:42:06 +02:00
|
|
|
function add_topic_message(topic_name, message_id) {
|
2020-03-22 18:40:05 +01:00
|
|
|
stream_topic_history.add_message({
|
2020-01-18 12:06:56 +01:00
|
|
|
stream_id: general.stream_id,
|
2020-07-20 22:18:43 +02:00
|
|
|
topic_name,
|
2021-06-08 18:42:06 +02:00
|
|
|
message_id,
|
2020-01-18 12:06:56 +01:00
|
|
|
});
|
js: Automatically convert _.each to for…of.
This commit was automatically generated by the following script,
followed by lint --fix and a few small manual lint-related cleanups.
import * as babelParser from "recast/parsers/babel";
import * as recast from "recast";
import * as tsParser from "recast/parsers/typescript";
import { builders as b, namedTypes as n } from "ast-types";
import { Context } from "ast-types/lib/path-visitor";
import K from "ast-types/gen/kinds";
import { NodePath } from "ast-types/lib/node-path";
import assert from "assert";
import fs from "fs";
import path from "path";
import process from "process";
const checkExpression = (node: n.Node): node is K.ExpressionKind =>
n.Expression.check(node);
const checkStatement = (node: n.Node): node is K.StatementKind =>
n.Statement.check(node);
for (const file of process.argv.slice(2)) {
console.log("Parsing", file);
const ast = recast.parse(fs.readFileSync(file, { encoding: "utf8" }), {
parser: path.extname(file) === ".ts" ? tsParser : babelParser,
});
let changed = false;
let inLoop = false;
let replaceReturn = false;
const visitLoop = (...args: string[]) =>
function(this: Context, path: NodePath) {
for (const arg of args) {
this.visit(path.get(arg));
}
const old = { inLoop };
inLoop = true;
this.visit(path.get("body"));
inLoop = old.inLoop;
return false;
};
recast.visit(ast, {
visitDoWhileStatement: visitLoop("test"),
visitExpressionStatement(path) {
const { expression, comments } = path.node;
let valueOnly;
if (
n.CallExpression.check(expression) &&
n.MemberExpression.check(expression.callee) &&
!expression.callee.computed &&
n.Identifier.check(expression.callee.object) &&
expression.callee.object.name === "_" &&
n.Identifier.check(expression.callee.property) &&
["each", "forEach"].includes(expression.callee.property.name) &&
[2, 3].includes(expression.arguments.length) &&
checkExpression(expression.arguments[0]) &&
(n.FunctionExpression.check(expression.arguments[1]) ||
n.ArrowFunctionExpression.check(expression.arguments[1])) &&
[1, 2].includes(expression.arguments[1].params.length) &&
n.Identifier.check(expression.arguments[1].params[0]) &&
((valueOnly = expression.arguments[1].params[1] === undefined) ||
n.Identifier.check(expression.arguments[1].params[1])) &&
(expression.arguments[2] === undefined ||
n.ThisExpression.check(expression.arguments[2]))
) {
const old = { inLoop, replaceReturn };
inLoop = false;
replaceReturn = true;
this.visit(
path
.get("expression")
.get("arguments")
.get(1)
.get("body")
);
inLoop = old.inLoop;
replaceReturn = old.replaceReturn;
const [right, { body, params }] = expression.arguments;
const loop = b.forOfStatement(
b.variableDeclaration("let", [
b.variableDeclarator(
valueOnly ? params[0] : b.arrayPattern([params[1], params[0]])
),
]),
valueOnly
? right
: b.callExpression(
b.memberExpression(right, b.identifier("entries")),
[]
),
checkStatement(body) ? body : b.expressionStatement(body)
);
loop.comments = comments;
path.replace(loop);
changed = true;
}
this.traverse(path);
},
visitForStatement: visitLoop("init", "test", "update"),
visitForInStatement: visitLoop("left", "right"),
visitForOfStatement: visitLoop("left", "right"),
visitFunction(path) {
this.visit(path.get("params"));
const old = { replaceReturn };
replaceReturn = false;
this.visit(path.get("body"));
replaceReturn = old.replaceReturn;
return false;
},
visitReturnStatement(path) {
if (replaceReturn) {
assert(!inLoop); // could use labeled continue if this ever fires
const { argument, comments } = path.node;
if (argument === null) {
const s = b.continueStatement();
s.comments = comments;
path.replace(s);
} else {
const s = b.expressionStatement(argument);
s.comments = comments;
path.replace(s, b.continueStatement());
}
return false;
}
this.traverse(path);
},
visitWhileStatement: visitLoop("test"),
});
if (changed) {
console.log("Writing", file);
fs.writeFileSync(file, recast.print(ast).code, { encoding: "utf8" });
}
}
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-02-06 06:19:47 +01:00
|
|
|
}
|
2023-02-10 20:48:04 +01:00
|
|
|
for (const i of _.range(10)) {
|
2021-07-01 10:19:59 +02:00
|
|
|
let topic_name;
|
|
|
|
// All odd topics are resolved.
|
|
|
|
if (i % 2) {
|
|
|
|
topic_name = "✔ topic ";
|
|
|
|
} else {
|
|
|
|
topic_name = "topic ";
|
|
|
|
}
|
|
|
|
add_topic_message(topic_name + i, 1000 + i);
|
2021-06-08 18:42:06 +02:00
|
|
|
}
|
2020-01-18 12:06:56 +01:00
|
|
|
|
2024-03-20 23:26:23 +01:00
|
|
|
override(narrow_state, "topic", () => "topic 11");
|
|
|
|
override(narrow_state, "stream_id", () => 556);
|
|
|
|
|
|
|
|
list_info = get_list_info();
|
|
|
|
assert.equal(list_info.items.length, 8);
|
|
|
|
assert.equal(list_info.more_topics_unreads, 0);
|
|
|
|
assert.equal(list_info.more_topics_have_unread_mention_messages, false);
|
|
|
|
assert.equal(list_info.num_possible_topics, 11);
|
|
|
|
assert.deepEqual(list_info.items[0], {
|
|
|
|
topic_name: "topic 11",
|
|
|
|
topic_resolved_prefix: "",
|
|
|
|
topic_display_name: "topic 11",
|
|
|
|
unread: 0,
|
|
|
|
is_zero: true,
|
2024-07-03 22:53:31 +02:00
|
|
|
stream_id: 556,
|
2024-03-20 23:26:23 +01:00
|
|
|
is_muted: false,
|
|
|
|
is_followed: false,
|
|
|
|
is_unmuted_or_followed: false,
|
|
|
|
is_active_topic: true,
|
2024-10-03 18:37:58 +02:00
|
|
|
url: "#narrow/channel/556-general/topic/topic.2011",
|
2024-03-20 23:26:23 +01:00
|
|
|
contains_unread_mention: false,
|
|
|
|
});
|
|
|
|
|
2021-02-24 17:24:06 +01:00
|
|
|
override(narrow_state, "topic", () => "topic 6");
|
2020-01-18 14:03:08 +01:00
|
|
|
|
|
|
|
list_info = get_list_info();
|
2023-02-10 20:48:04 +01:00
|
|
|
assert.equal(list_info.items.length, 8);
|
2020-01-18 12:06:56 +01:00
|
|
|
assert.equal(list_info.more_topics_unreads, 0);
|
2022-08-21 23:05:56 +02:00
|
|
|
assert.equal(list_info.more_topics_have_unread_mention_messages, false);
|
2023-02-10 20:48:04 +01:00
|
|
|
assert.equal(list_info.num_possible_topics, 10);
|
2020-01-18 12:06:56 +01:00
|
|
|
|
|
|
|
assert.deepEqual(list_info.items[0], {
|
2022-08-21 23:05:56 +02:00
|
|
|
contains_unread_mention: false,
|
2023-02-10 20:48:04 +01:00
|
|
|
is_active_topic: false,
|
2020-01-18 12:06:56 +01:00
|
|
|
is_muted: false,
|
2023-08-25 16:07:32 +02:00
|
|
|
is_followed: false,
|
|
|
|
is_unmuted_or_followed: false,
|
2020-01-18 12:06:56 +01:00
|
|
|
is_zero: true,
|
2024-07-03 22:53:31 +02:00
|
|
|
stream_id: 556,
|
2023-02-10 20:48:04 +01:00
|
|
|
topic_display_name: "topic 9",
|
|
|
|
topic_name: "✔ topic 9",
|
|
|
|
topic_resolved_prefix: "✔ ",
|
2020-01-18 12:06:56 +01:00
|
|
|
unread: 0,
|
2024-10-03 18:37:58 +02:00
|
|
|
url: "#narrow/channel/556-general/topic/.E2.9C.94.20topic.209",
|
2020-01-18 12:06:56 +01:00
|
|
|
});
|
2020-01-18 14:03:08 +01:00
|
|
|
|
2021-07-01 10:19:59 +02:00
|
|
|
assert.deepEqual(list_info.items[1], {
|
2022-08-21 23:05:56 +02:00
|
|
|
contains_unread_mention: false,
|
2021-07-01 10:19:59 +02:00
|
|
|
is_active_topic: false,
|
|
|
|
is_muted: false,
|
2023-08-25 16:07:32 +02:00
|
|
|
is_followed: false,
|
|
|
|
is_unmuted_or_followed: false,
|
2021-07-01 10:19:59 +02:00
|
|
|
is_zero: true,
|
2024-07-03 22:53:31 +02:00
|
|
|
stream_id: 556,
|
2023-02-10 20:48:04 +01:00
|
|
|
topic_display_name: "topic 8",
|
|
|
|
topic_name: "topic 8",
|
|
|
|
topic_resolved_prefix: "",
|
2021-07-01 10:19:59 +02:00
|
|
|
unread: 0,
|
2024-10-03 18:37:58 +02:00
|
|
|
url: "#narrow/channel/556-general/topic/topic.208",
|
2021-07-01 10:19:59 +02:00
|
|
|
});
|
2021-06-08 18:42:06 +02:00
|
|
|
|
2023-04-12 13:22:52 +02:00
|
|
|
// If we zoom in, our results are based on topic filter.
|
|
|
|
// If topic search input is empty, we show all 10 topics.
|
2020-01-18 14:03:08 +01:00
|
|
|
const zoomed = true;
|
|
|
|
list_info = get_list_info(zoomed);
|
2023-02-10 20:48:04 +01:00
|
|
|
assert.equal(list_info.items.length, 10);
|
2020-01-18 14:03:08 +01:00
|
|
|
assert.equal(list_info.more_topics_unreads, 0);
|
2022-08-21 23:05:56 +02:00
|
|
|
assert.equal(list_info.more_topics_have_unread_mention_messages, false);
|
2023-02-10 20:48:04 +01:00
|
|
|
assert.equal(list_info.num_possible_topics, 10);
|
2021-06-08 18:42:06 +02:00
|
|
|
|
|
|
|
add_topic_message("After Brooklyn", 1008);
|
|
|
|
add_topic_message("Catering", 1009);
|
2023-04-12 13:22:52 +02:00
|
|
|
|
|
|
|
// When topic search input is not empty, we show topics
|
|
|
|
// based on the search term.
|
|
|
|
const search_term = "b,c";
|
|
|
|
list_info = get_list_info(zoomed, search_term);
|
2021-06-08 18:42:06 +02:00
|
|
|
assert.equal(list_info.items.length, 2);
|
|
|
|
assert.equal(list_info.more_topics_unreads, 0);
|
2022-08-21 23:05:56 +02:00
|
|
|
assert.equal(list_info.more_topics_have_unread_mention_messages, false);
|
2021-06-08 18:42:06 +02:00
|
|
|
assert.equal(list_info.num_possible_topics, 2);
|
2020-01-18 12:06:56 +01:00
|
|
|
});
|
|
|
|
|
2022-07-10 01:06:33 +02:00
|
|
|
test("get_list_info unreads", ({override}) => {
|
2020-01-18 12:06:56 +01:00
|
|
|
let list_info;
|
|
|
|
|
2022-07-10 01:06:33 +02:00
|
|
|
let message_id = 0;
|
2023-02-10 20:48:04 +01:00
|
|
|
for (let i = 15; i >= 0; i -= 1) {
|
2022-07-10 01:06:33 +02:00
|
|
|
stream_topic_history.add_message({
|
|
|
|
stream_id: general.stream_id,
|
|
|
|
message_id: (message_id += 1),
|
|
|
|
topic_name: `topic ${i}`,
|
|
|
|
});
|
|
|
|
}
|
2020-01-18 12:06:56 +01:00
|
|
|
|
2022-07-10 01:06:33 +02:00
|
|
|
function add_unreads(topic, count) {
|
|
|
|
unread.process_loaded_messages(
|
|
|
|
Array.from({length: count}, () => ({
|
|
|
|
id: (message_id += 1),
|
|
|
|
stream_id: general.stream_id,
|
|
|
|
topic,
|
|
|
|
type: "stream",
|
|
|
|
unread: true,
|
|
|
|
})),
|
|
|
|
);
|
|
|
|
}
|
2020-01-18 12:06:56 +01:00
|
|
|
|
2022-08-21 23:05:56 +02:00
|
|
|
function add_unreads_with_mention(topic, count) {
|
|
|
|
unread.process_loaded_messages(
|
|
|
|
Array.from({length: count}, () => ({
|
|
|
|
id: (message_id += 1),
|
|
|
|
stream_id: general.stream_id,
|
|
|
|
topic,
|
|
|
|
type: "stream",
|
|
|
|
unread: true,
|
|
|
|
mentioned: true,
|
|
|
|
mentioned_me_directly: true,
|
|
|
|
})),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-01-18 12:06:56 +01:00
|
|
|
/*
|
2023-02-10 20:48:04 +01:00
|
|
|
We have 16 topics, but we only show up
|
|
|
|
to 12 topics, depending on how many have
|
|
|
|
unread counts. We only show a max of 8
|
2020-01-18 12:06:56 +01:00
|
|
|
fully-read topics.
|
|
|
|
|
2023-02-10 20:48:04 +01:00
|
|
|
So first we'll get 10 topics, where 2 are
|
2020-01-18 12:06:56 +01:00
|
|
|
unread.
|
|
|
|
*/
|
2023-02-10 20:48:04 +01:00
|
|
|
add_unreads("topic 14", 1);
|
|
|
|
add_unreads("topic 13", 1);
|
2020-01-18 12:06:56 +01:00
|
|
|
|
2022-08-21 23:05:56 +02:00
|
|
|
/*
|
2023-02-10 20:48:04 +01:00
|
|
|
We added 1 unread message in 'topic 14',
|
2022-08-21 23:05:56 +02:00
|
|
|
but now we would add a unread message
|
|
|
|
with `mention` for user, to test
|
|
|
|
`more_topics_have_unread_mention_messages`.
|
|
|
|
*/
|
2023-02-10 20:48:04 +01:00
|
|
|
add_unreads_with_mention("topic 14", 1);
|
2022-08-21 23:05:56 +02:00
|
|
|
|
2020-01-18 12:06:56 +01:00
|
|
|
list_info = get_list_info();
|
2023-02-10 20:48:04 +01:00
|
|
|
assert.equal(list_info.items.length, 10);
|
2020-01-18 12:06:56 +01:00
|
|
|
assert.equal(list_info.more_topics_unreads, 0);
|
2022-08-21 23:05:56 +02:00
|
|
|
assert.equal(list_info.more_topics_have_unread_mention_messages, false);
|
2023-02-10 20:48:04 +01:00
|
|
|
assert.equal(list_info.num_possible_topics, 16);
|
2020-01-18 12:06:56 +01:00
|
|
|
|
|
|
|
assert.deepEqual(
|
2020-07-02 01:39:34 +02:00
|
|
|
list_info.items.map((li) => li.topic_name),
|
2023-02-10 20:48:04 +01:00
|
|
|
[
|
|
|
|
"topic 0",
|
|
|
|
"topic 1",
|
|
|
|
"topic 2",
|
|
|
|
"topic 3",
|
|
|
|
"topic 4",
|
|
|
|
"topic 5",
|
|
|
|
"topic 6",
|
|
|
|
"topic 7",
|
|
|
|
"topic 13",
|
|
|
|
"topic 14",
|
|
|
|
],
|
2020-07-15 00:34:28 +02:00
|
|
|
);
|
2020-01-18 12:06:56 +01:00
|
|
|
|
2023-02-10 20:48:04 +01:00
|
|
|
add_unreads("topic 12", 1);
|
|
|
|
add_unreads("topic 11", 1);
|
|
|
|
add_unreads("topic 10", 1);
|
2020-01-18 12:06:56 +01:00
|
|
|
|
|
|
|
list_info = get_list_info();
|
2023-02-10 20:48:04 +01:00
|
|
|
assert.equal(list_info.items.length, 12);
|
|
|
|
assert.equal(list_info.more_topics_unreads, 2);
|
2022-08-21 23:05:56 +02:00
|
|
|
assert.equal(list_info.more_topics_have_unread_mention_messages, true);
|
2023-02-10 20:48:04 +01:00
|
|
|
assert.equal(list_info.num_possible_topics, 16);
|
2020-01-18 12:06:56 +01:00
|
|
|
|
|
|
|
assert.deepEqual(
|
2020-07-02 01:39:34 +02:00
|
|
|
list_info.items.map((li) => li.topic_name),
|
2023-02-10 20:48:04 +01:00
|
|
|
[
|
|
|
|
"topic 0",
|
|
|
|
"topic 1",
|
|
|
|
"topic 2",
|
|
|
|
"topic 3",
|
|
|
|
"topic 4",
|
|
|
|
"topic 5",
|
|
|
|
"topic 6",
|
|
|
|
"topic 7",
|
|
|
|
"topic 10",
|
|
|
|
"topic 11",
|
|
|
|
"topic 12",
|
|
|
|
"topic 13",
|
|
|
|
],
|
2020-07-15 00:34:28 +02:00
|
|
|
);
|
2020-01-18 12:48:04 +01:00
|
|
|
|
2023-02-10 20:48:04 +01:00
|
|
|
add_unreads("topic 9", 1);
|
|
|
|
add_unreads("topic 8", 1);
|
2020-01-18 12:48:04 +01:00
|
|
|
|
2023-02-10 20:48:04 +01:00
|
|
|
add_unreads("topic 4", 1);
|
2022-08-14 15:33:13 +02:00
|
|
|
override(user_topics, "is_topic_muted", (stream_id, topic_name) => {
|
2020-01-18 12:48:04 +01:00
|
|
|
assert.equal(stream_id, general.stream_id);
|
2020-07-15 01:29:15 +02:00
|
|
|
return topic_name === "topic 4";
|
2021-02-24 17:24:06 +01:00
|
|
|
});
|
2020-01-18 12:48:04 +01:00
|
|
|
|
2023-04-19 21:59:46 +02:00
|
|
|
// muting the stream and unmuting the topic 5
|
|
|
|
// this should make topic 5 at top in items array
|
|
|
|
general.is_muted = true;
|
|
|
|
add_unreads("topic 5", 1);
|
2023-08-25 18:20:02 +02:00
|
|
|
override(user_topics, "is_topic_unmuted_or_followed", (stream_id, topic_name) => {
|
2023-04-19 21:59:46 +02:00
|
|
|
assert.equal(stream_id, general.stream_id);
|
|
|
|
return topic_name === "topic 5";
|
|
|
|
});
|
|
|
|
|
2020-01-18 12:48:04 +01:00
|
|
|
list_info = get_list_info();
|
2023-02-10 20:48:04 +01:00
|
|
|
assert.equal(list_info.items.length, 12);
|
|
|
|
assert.equal(list_info.more_topics_unreads, 3);
|
2022-08-21 23:05:56 +02:00
|
|
|
assert.equal(list_info.more_topics_have_unread_mention_messages, true);
|
2023-02-10 20:48:04 +01:00
|
|
|
assert.equal(list_info.num_possible_topics, 16);
|
2023-05-02 02:24:11 +02:00
|
|
|
assert.equal(list_info.more_topics_unread_count_muted, false);
|
2020-01-18 12:48:04 +01:00
|
|
|
|
|
|
|
assert.deepEqual(
|
2020-07-02 01:39:34 +02:00
|
|
|
list_info.items.map((li) => li.topic_name),
|
2023-02-10 20:48:04 +01:00
|
|
|
[
|
2023-04-19 21:59:46 +02:00
|
|
|
"topic 5",
|
2023-02-10 20:48:04 +01:00
|
|
|
"topic 0",
|
|
|
|
"topic 1",
|
|
|
|
"topic 2",
|
|
|
|
"topic 3",
|
|
|
|
"topic 6",
|
|
|
|
"topic 7",
|
|
|
|
"topic 8",
|
|
|
|
"topic 9",
|
|
|
|
"topic 10",
|
|
|
|
"topic 11",
|
|
|
|
"topic 12",
|
|
|
|
],
|
2020-07-15 00:34:28 +02:00
|
|
|
);
|
2023-05-02 02:24:11 +02:00
|
|
|
|
|
|
|
// Now test with topics 4/8/9, all the ones with unreads, being muted.
|
|
|
|
override(user_topics, "is_topic_muted", (stream_id, topic_name) => {
|
|
|
|
assert.equal(stream_id, general.stream_id);
|
|
|
|
return ["topic 4", "topic 8", "topic 9"].includes(topic_name);
|
|
|
|
});
|
|
|
|
list_info = get_list_info();
|
|
|
|
assert.equal(list_info.items.length, 12);
|
|
|
|
assert.equal(list_info.more_topics_unreads, 3);
|
2024-05-17 09:42:44 +02:00
|
|
|
// Topic 14 now makes it above the "show all topics" fold.
|
2023-05-02 02:24:11 +02:00
|
|
|
assert.equal(list_info.more_topics_have_unread_mention_messages, false);
|
|
|
|
assert.equal(list_info.num_possible_topics, 16);
|
|
|
|
assert.equal(list_info.more_topics_unread_count_muted, true);
|
|
|
|
assert.deepEqual(
|
|
|
|
list_info.items.map((li) => li.topic_name),
|
|
|
|
[
|
|
|
|
"topic 5",
|
|
|
|
"topic 0",
|
|
|
|
"topic 1",
|
|
|
|
"topic 2",
|
|
|
|
"topic 3",
|
|
|
|
"topic 6",
|
|
|
|
"topic 7",
|
|
|
|
"topic 10",
|
|
|
|
"topic 11",
|
|
|
|
"topic 12",
|
|
|
|
"topic 13",
|
|
|
|
"topic 14",
|
|
|
|
],
|
|
|
|
);
|
|
|
|
|
|
|
|
add_unreads_with_mention("topic 8", 1);
|
|
|
|
list_info = get_list_info();
|
|
|
|
assert.equal(list_info.items.length, 12);
|
|
|
|
assert.equal(list_info.more_topics_unreads, 4);
|
|
|
|
// Topic 8's new mention gets counted here.
|
|
|
|
assert.equal(list_info.more_topics_have_unread_mention_messages, true);
|
|
|
|
assert.equal(list_info.num_possible_topics, 16);
|
|
|
|
assert.equal(list_info.more_topics_unread_count_muted, true);
|
|
|
|
assert.deepEqual(
|
|
|
|
list_info.items.map((li) => li.topic_name),
|
|
|
|
[
|
|
|
|
"topic 5",
|
|
|
|
"topic 0",
|
|
|
|
"topic 1",
|
|
|
|
"topic 2",
|
|
|
|
"topic 3",
|
|
|
|
"topic 6",
|
|
|
|
"topic 7",
|
|
|
|
"topic 10",
|
|
|
|
"topic 11",
|
|
|
|
"topic 12",
|
|
|
|
"topic 13",
|
|
|
|
"topic 14",
|
|
|
|
],
|
|
|
|
);
|
|
|
|
|
|
|
|
// Adding an additional older unmuted topic with unreads should
|
|
|
|
// result in just the unmuted unreads being counted.
|
|
|
|
add_unreads("topic 15", 15);
|
|
|
|
list_info = get_list_info();
|
|
|
|
assert.equal(list_info.items.length, 12);
|
|
|
|
assert.equal(list_info.more_topics_unreads, 15);
|
|
|
|
assert.equal(list_info.more_topics_have_unread_mention_messages, true);
|
|
|
|
assert.equal(list_info.num_possible_topics, 16);
|
|
|
|
assert.equal(list_info.more_topics_unread_count_muted, false);
|
|
|
|
assert.deepEqual(
|
|
|
|
list_info.items.map((li) => li.topic_name),
|
|
|
|
[
|
|
|
|
"topic 5",
|
|
|
|
"topic 0",
|
|
|
|
"topic 1",
|
|
|
|
"topic 2",
|
|
|
|
"topic 3",
|
|
|
|
"topic 6",
|
|
|
|
"topic 7",
|
|
|
|
"topic 10",
|
|
|
|
"topic 11",
|
|
|
|
"topic 12",
|
|
|
|
"topic 13",
|
|
|
|
"topic 14",
|
|
|
|
],
|
|
|
|
);
|
2020-01-18 12:06:56 +01:00
|
|
|
});
|
left-sidebar: Use -, _, :, and / as additional topic word separators.
Previously, only spaces were used as word separators when searching
for topics. This meant that searching for "support" would not find a
topic named "topic_support" or "topic/support," which could lead to
unexpected results.
To address this, hyphen (-), underscore (_), colon (:), and slash (/)
have been added as additional word separators for topic filtering in
the left sidebar, as these characters are commonly used as separators
in topic names.
Fixes: #31844
2024-10-03 11:06:30 +02:00
|
|
|
|
|
|
|
test("get_list_info with specific topics and searches", () => {
|
|
|
|
let list_info;
|
|
|
|
|
|
|
|
function add_topic_message(topic_name, message_id) {
|
|
|
|
stream_topic_history.add_message({
|
|
|
|
stream_id: general.stream_id,
|
|
|
|
topic_name,
|
|
|
|
message_id,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
add_topic_message("BF-2924 zulip", 1001);
|
|
|
|
add_topic_message("tech_support/escalation", 1002);
|
|
|
|
|
|
|
|
list_info = get_list_info(true, "2924");
|
|
|
|
assert.equal(list_info.items.length, 1);
|
|
|
|
assert.equal(list_info.items[0].topic_name, "BF-2924 zulip");
|
|
|
|
|
|
|
|
list_info = get_list_info(true, "support/escalation");
|
|
|
|
assert.equal(list_info.items.length, 1);
|
|
|
|
assert.equal(list_info.items[0].topic_name, "tech_support/escalation");
|
|
|
|
|
|
|
|
list_info = get_list_info(true, "support");
|
|
|
|
assert.equal(list_info.items.length, 1);
|
|
|
|
assert.equal(list_info.items[0].topic_name, "tech_support/escalation");
|
|
|
|
|
|
|
|
list_info = get_list_info(true, "zulip");
|
|
|
|
assert.equal(list_info.items.length, 1);
|
|
|
|
assert.equal(list_info.items[0].topic_name, "BF-2924 zulip");
|
|
|
|
|
|
|
|
list_info = get_list_info(true, "SUPPORT");
|
|
|
|
assert.equal(list_info.items.length, 1);
|
|
|
|
assert.equal(list_info.items[0].topic_name, "tech_support/escalation");
|
|
|
|
|
|
|
|
list_info = get_list_info(true, "nonexistent");
|
|
|
|
assert.equal(list_info.items.length, 0);
|
|
|
|
});
|