2020-08-01 03:43:15 +02:00
|
|
|
"use strict";
|
|
|
|
|
2020-11-30 23:46:45 +01:00
|
|
|
const {strict: assert} = require("assert");
|
|
|
|
|
2023-02-22 23:04:10 +01:00
|
|
|
const {mock_esm, set_global, zrequire} = require("./lib/namespace");
|
|
|
|
const {run_test} = require("./lib/test");
|
|
|
|
const $ = require("./lib/zjquery");
|
2020-12-01 00:02:16 +01:00
|
|
|
|
2021-03-07 13:57:14 +01:00
|
|
|
const denmark_stream_id = 101;
|
|
|
|
|
2023-04-25 18:01:02 +02:00
|
|
|
const scroll_util = mock_esm("../src/scroll_util", {
|
2022-01-25 11:36:19 +01:00
|
|
|
get_content_element: ($element) => $element,
|
2021-03-07 13:57:14 +01:00
|
|
|
});
|
2021-02-04 19:08:19 +01:00
|
|
|
|
2023-02-22 23:04:10 +01:00
|
|
|
mock_esm("../src/hash_util", {
|
2022-11-17 23:33:43 +01:00
|
|
|
by_stream_url() {},
|
2020-06-16 18:42:13 +02:00
|
|
|
});
|
2018-07-30 20:05:56 +02:00
|
|
|
|
2024-03-06 17:02:06 +01:00
|
|
|
mock_esm("../src/browser_history", {
|
|
|
|
update() {},
|
|
|
|
});
|
|
|
|
|
2023-10-01 22:03:44 +02:00
|
|
|
mock_esm("../src/hash_parser", {
|
|
|
|
get_current_hash_section: () => denmark_stream_id,
|
|
|
|
});
|
2021-03-15 09:25:22 +01:00
|
|
|
set_global("page_params", {});
|
|
|
|
|
2020-12-01 23:21:38 +01:00
|
|
|
const stream_data = zrequire("stream_data");
|
2021-07-09 15:51:31 +02:00
|
|
|
const stream_settings_ui = zrequire("stream_settings_ui");
|
2022-12-29 17:49:38 +01:00
|
|
|
const user_groups = zrequire("user_groups");
|
2020-12-01 23:21:38 +01:00
|
|
|
|
2021-06-28 00:41:05 +02:00
|
|
|
run_test("redraw_left_panel", ({mock_template}) => {
|
2022-12-29 17:49:38 +01:00
|
|
|
const admins_group = {
|
|
|
|
name: "Admins",
|
|
|
|
id: 1,
|
|
|
|
members: new Set([1]),
|
|
|
|
is_system_group: true,
|
|
|
|
direct_subgroup_ids: new Set([]),
|
|
|
|
};
|
|
|
|
user_groups.initialize({realm_user_groups: [admins_group]});
|
|
|
|
|
2018-05-15 19:36:25 +02:00
|
|
|
// set-up sub rows stubs
|
2021-02-16 15:57:10 +01:00
|
|
|
const denmark = {
|
|
|
|
elem: "denmark",
|
|
|
|
subscribed: false,
|
|
|
|
name: "Denmark",
|
|
|
|
stream_id: denmark_stream_id,
|
|
|
|
description: "Copenhagen",
|
|
|
|
subscribers: [1],
|
|
|
|
stream_weekly_traffic: null,
|
|
|
|
color: "red",
|
2023-07-12 12:57:57 +02:00
|
|
|
can_remove_subscribers_group: admins_group.id,
|
2024-03-23 08:06:21 +01:00
|
|
|
date_created: 1691057093,
|
|
|
|
creator_id: null,
|
2021-02-16 15:57:10 +01:00
|
|
|
};
|
|
|
|
const poland = {
|
|
|
|
elem: "poland",
|
|
|
|
subscribed: true,
|
|
|
|
name: "Poland",
|
|
|
|
stream_id: 102,
|
|
|
|
description: "monday",
|
|
|
|
subscribers: [1, 2, 3],
|
|
|
|
stream_weekly_traffic: 13,
|
|
|
|
color: "red",
|
2023-07-12 12:57:57 +02:00
|
|
|
can_remove_subscribers_group: admins_group.id,
|
2024-03-23 08:06:21 +01:00
|
|
|
date_created: 1691057093,
|
|
|
|
creator_id: null,
|
2021-02-16 15:57:10 +01:00
|
|
|
};
|
|
|
|
const pomona = {
|
|
|
|
elem: "pomona",
|
|
|
|
subscribed: true,
|
|
|
|
name: "Pomona",
|
|
|
|
stream_id: 103,
|
|
|
|
description: "college",
|
|
|
|
subscribers: [],
|
|
|
|
stream_weekly_traffic: 0,
|
|
|
|
color: "red",
|
2023-07-12 12:57:57 +02:00
|
|
|
can_remove_subscribers_group: admins_group.id,
|
2024-03-23 08:06:21 +01:00
|
|
|
date_created: 1691057093,
|
|
|
|
creator_id: null,
|
2021-02-16 15:57:10 +01:00
|
|
|
};
|
|
|
|
const cpp = {
|
|
|
|
elem: "cpp",
|
|
|
|
subscribed: true,
|
|
|
|
name: "C++",
|
|
|
|
stream_id: 104,
|
|
|
|
description: "programming lang",
|
|
|
|
subscribers: [1, 2],
|
|
|
|
stream_weekly_traffic: 6,
|
|
|
|
color: "red",
|
2023-07-12 12:57:57 +02:00
|
|
|
can_remove_subscribers_group: admins_group.id,
|
2024-03-23 08:06:21 +01:00
|
|
|
date_created: 1691057093,
|
|
|
|
creator_id: null,
|
2021-02-16 15:57:10 +01:00
|
|
|
};
|
|
|
|
const zzyzx = {
|
|
|
|
elem: "zzyzx",
|
|
|
|
subscribed: true,
|
|
|
|
name: "Zzyzx",
|
|
|
|
stream_id: 105,
|
|
|
|
description: "california town",
|
|
|
|
subscribers: [1, 2],
|
|
|
|
stream_weekly_traffic: 6,
|
|
|
|
color: "red",
|
2023-07-12 12:57:57 +02:00
|
|
|
can_remove_subscribers_group: admins_group.id,
|
2024-03-23 08:06:21 +01:00
|
|
|
date_created: 1691057093,
|
|
|
|
creator_id: null,
|
2021-02-16 15:57:10 +01:00
|
|
|
};
|
2024-05-08 18:00:20 +02:00
|
|
|
const abcd = {
|
|
|
|
elem: "abcd",
|
|
|
|
subscribed: false,
|
|
|
|
name: "Abcd",
|
|
|
|
stream_id: 106,
|
|
|
|
description: "India town",
|
|
|
|
subscribers: [1, 2, 3],
|
|
|
|
stream_weekly_traffic: 0,
|
|
|
|
color: "red",
|
|
|
|
can_remove_subscribers_group: admins_group.id,
|
|
|
|
date_created: 1691057093,
|
|
|
|
creator_id: null,
|
|
|
|
};
|
|
|
|
const utopia = {
|
|
|
|
elem: "utopia",
|
|
|
|
subscribed: false,
|
|
|
|
name: "Utopia",
|
|
|
|
stream_id: 107,
|
|
|
|
description: "movie",
|
|
|
|
subscribers: [1, 2, 3, 4],
|
|
|
|
stream_weekly_traffic: 8,
|
|
|
|
color: "red",
|
|
|
|
can_remove_subscribers_group: admins_group.id,
|
|
|
|
date_created: 1691057093,
|
|
|
|
creator_id: null,
|
|
|
|
};
|
|
|
|
const jerry = {
|
|
|
|
elem: "jerry",
|
|
|
|
subscribed: false,
|
|
|
|
name: "Jerry",
|
|
|
|
stream_id: 108,
|
|
|
|
description: "cat",
|
|
|
|
subscribers: [1],
|
|
|
|
stream_weekly_traffic: 4,
|
|
|
|
color: "red",
|
|
|
|
can_remove_subscribers_group: admins_group.id,
|
|
|
|
date_created: 1691057093,
|
|
|
|
creator_id: null,
|
|
|
|
};
|
2021-02-16 15:57:10 +01:00
|
|
|
|
2024-05-08 18:00:20 +02:00
|
|
|
const sub_row_data = [denmark, poland, pomona, cpp, zzyzx, abcd, utopia, jerry];
|
2016-12-26 10:13:31 +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
|
|
|
for (const sub of sub_row_data) {
|
2021-01-12 16:05:24 +01:00
|
|
|
stream_data.create_sub_from_server_data(sub);
|
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
|
|
|
}
|
2018-07-29 15:26:45 +02:00
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
let populated_subs;
|
2018-07-30 20:05:56 +02:00
|
|
|
|
2021-07-19 19:13:25 +02:00
|
|
|
mock_template("stream_settings/browse_streams_list.hbs", false, (data) => {
|
2018-07-30 20:05:56 +02:00
|
|
|
populated_subs = data.subscriptions;
|
2019-07-11 05:06:20 +02:00
|
|
|
});
|
2018-07-30 20:05:56 +02:00
|
|
|
|
2021-07-09 15:51:31 +02:00
|
|
|
stream_settings_ui.render_left_panel_superset();
|
2018-07-30 20:05:56 +02:00
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const sub_stubs = [];
|
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
|
|
|
|
|
|
|
for (const data of populated_subs) {
|
2021-02-03 23:23:32 +01:00
|
|
|
const sub_row = `.stream-row-${CSS.escape(data.elem)}`;
|
2018-05-15 19:36:25 +02:00
|
|
|
sub_stubs.push(sub_row);
|
|
|
|
|
|
|
|
$(sub_row).attr("data-stream-id", data.stream_id);
|
2021-02-23 14:37:26 +01:00
|
|
|
$(sub_row).detach = () => sub_row;
|
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
|
|
|
}
|
2018-05-15 19:36:25 +02:00
|
|
|
|
2024-04-30 15:03:47 +02:00
|
|
|
$.create("#channels_overlay_container .stream-row", {children: sub_stubs});
|
2018-05-15 19:36:25 +02:00
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
let ui_called = false;
|
2023-04-25 18:01:02 +02:00
|
|
|
scroll_util.reset_scrollbar = ($elem) => {
|
2018-05-15 19:36:25 +02:00
|
|
|
ui_called = true;
|
2022-01-25 11:36:19 +01:00
|
|
|
assert.equal($elem, $("#subscription_overlay .streams-list"));
|
2018-05-15 19:36:25 +02:00
|
|
|
};
|
2016-12-26 10:13:31 +01:00
|
|
|
|
2021-02-04 19:08:19 +01:00
|
|
|
// Filtering has the side effect of setting the "active" class
|
|
|
|
// on our current stream, even if it doesn't match the filter.
|
2022-01-25 11:36:19 +01:00
|
|
|
const $denmark_row = $(`.stream-row[data-stream-id='${CSS.escape(denmark_stream_id)}']`);
|
2021-02-04 19:08:19 +01:00
|
|
|
// sanity check it's not set to active
|
2022-01-25 11:36:19 +01:00
|
|
|
assert.ok(!$denmark_row.hasClass("active"));
|
2021-02-04 19:08:19 +01:00
|
|
|
|
2021-02-16 17:35:06 +01:00
|
|
|
function test_filter(params, expected_streams) {
|
2024-04-30 15:03:47 +02:00
|
|
|
$("#channels_overlay_container .stream-row:not(.notdisplayed)").length = 0;
|
2021-07-09 15:51:31 +02:00
|
|
|
const stream_ids = stream_settings_ui.redraw_left_panel(params);
|
2021-02-16 17:35:06 +01:00
|
|
|
assert.deepEqual(
|
|
|
|
stream_ids,
|
|
|
|
expected_streams.map((sub) => sub.stream_id),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2016-12-26 10:13:31 +01:00
|
|
|
// Search with single keyword
|
2024-05-08 18:00:20 +02:00
|
|
|
test_filter({input: "Po", show_subscribed: false, show_not_subscribed: false}, [
|
|
|
|
poland,
|
|
|
|
pomona,
|
|
|
|
]);
|
2021-06-10 08:32:54 +02:00
|
|
|
assert.ok(ui_called);
|
2021-02-04 19:08:19 +01:00
|
|
|
|
|
|
|
// The denmark row is active, even though it's not displayed.
|
2022-01-25 11:36:19 +01:00
|
|
|
assert.ok($denmark_row.hasClass("active"));
|
2021-02-04 19:08:19 +01:00
|
|
|
|
2016-12-26 10:13:31 +01:00
|
|
|
// Search with multiple keywords
|
2024-05-08 18:00:20 +02:00
|
|
|
test_filter({input: "Denmark, Pol", show_subscribed: false, show_not_subscribed: false}, [
|
|
|
|
denmark,
|
|
|
|
poland,
|
|
|
|
]);
|
|
|
|
test_filter({input: "Den, Pol", show_subscribed: false, show_not_subscribed: false}, [
|
|
|
|
denmark,
|
|
|
|
poland,
|
|
|
|
]);
|
2016-12-26 10:13:31 +01:00
|
|
|
|
|
|
|
// Search is case-insensitive
|
2024-05-08 18:00:20 +02:00
|
|
|
test_filter({input: "po", show_subscribed: false, show_not_subscribed: false}, [
|
|
|
|
poland,
|
|
|
|
pomona,
|
|
|
|
]);
|
2016-12-26 10:13:31 +01:00
|
|
|
|
2017-02-04 13:02:31 +01:00
|
|
|
// Search handles unusual characters like C++
|
2024-05-08 18:00:20 +02:00
|
|
|
test_filter({input: "c++", show_subscribed: false, show_not_subscribed: false}, [cpp]);
|
2017-02-04 13:02:31 +01:00
|
|
|
|
2016-12-26 10:13:31 +01:00
|
|
|
// Search subscribed streams only
|
2024-05-08 18:00:20 +02:00
|
|
|
test_filter({input: "d", show_subscribed: true, show_not_subscribed: false}, [poland]);
|
2018-05-15 19:36:25 +02:00
|
|
|
|
2024-05-08 18:00:20 +02:00
|
|
|
// Search unsubscribed streams only
|
|
|
|
test_filter({input: "d", show_subscribed: false, show_not_subscribed: true}, [abcd, denmark]);
|
2020-03-31 17:13:01 +02:00
|
|
|
|
2024-05-08 18:00:20 +02:00
|
|
|
// Search terms match stream description
|
|
|
|
test_filter({input: "Co", show_subscribed: false, show_not_subscribed: false}, [
|
2021-02-16 17:35:06 +01:00
|
|
|
denmark,
|
|
|
|
pomona,
|
2020-03-31 17:13:01 +02:00
|
|
|
]);
|
|
|
|
|
2024-05-08 18:00:20 +02:00
|
|
|
// Search names AND descriptions
|
|
|
|
test_filter({input: "Mon", show_subscribed: false, show_not_subscribed: false}, [
|
2021-02-16 17:35:06 +01:00
|
|
|
pomona,
|
2024-05-08 18:00:20 +02:00
|
|
|
poland,
|
2020-03-31 17:13:01 +02:00
|
|
|
]);
|
|
|
|
|
2024-05-08 18:00:20 +02:00
|
|
|
// Explicitly order streams by name
|
|
|
|
test_filter(
|
|
|
|
{
|
|
|
|
input: "",
|
|
|
|
show_subscribed: false,
|
|
|
|
show_not_subscribed: false,
|
|
|
|
sort_order: "by-stream-name",
|
|
|
|
},
|
|
|
|
[abcd, cpp, denmark, jerry, poland, pomona, utopia, zzyzx],
|
|
|
|
);
|
|
|
|
|
|
|
|
// Order streams by subscriber count
|
|
|
|
test_filter(
|
|
|
|
{
|
|
|
|
input: "",
|
|
|
|
show_subscribed: false,
|
|
|
|
show_not_subscribed: false,
|
|
|
|
sort_order: "by-subscriber-count",
|
|
|
|
},
|
|
|
|
[utopia, abcd, poland, cpp, zzyzx, denmark, jerry, pomona],
|
|
|
|
);
|
|
|
|
|
2020-03-31 17:13:01 +02:00
|
|
|
// Order streams by weekly traffic
|
2024-05-08 18:00:20 +02:00
|
|
|
test_filter(
|
|
|
|
{
|
|
|
|
input: "",
|
|
|
|
show_subscribed: false,
|
|
|
|
show_not_subscribed: false,
|
|
|
|
sort_order: "by-weekly-traffic",
|
|
|
|
},
|
|
|
|
[poland, utopia, cpp, zzyzx, jerry, abcd, pomona, denmark],
|
|
|
|
);
|
2020-03-31 17:13:01 +02:00
|
|
|
|
2021-02-16 17:35:06 +01:00
|
|
|
// Sort for subscribed only.
|
2024-05-08 18:00:20 +02:00
|
|
|
test_filter(
|
|
|
|
{
|
|
|
|
input: "",
|
|
|
|
show_subscribed: true,
|
|
|
|
show_not_subscribed: false,
|
|
|
|
sort_order: "by-subscriber-count",
|
|
|
|
},
|
|
|
|
[poland, cpp, zzyzx, pomona],
|
|
|
|
);
|
|
|
|
|
|
|
|
// Sort for unsubscribed only.
|
|
|
|
test_filter(
|
|
|
|
{
|
|
|
|
input: "",
|
|
|
|
show_subscribed: false,
|
|
|
|
show_not_subscribed: true,
|
|
|
|
sort_order: "by-subscriber-count",
|
|
|
|
},
|
|
|
|
[utopia, abcd, denmark, jerry],
|
|
|
|
);
|
2016-12-26 10:13:31 +01:00
|
|
|
|
2018-05-15 19:36:25 +02:00
|
|
|
// active stream-row is not included in results
|
|
|
|
$(".stream-row-denmark").addClass("active");
|
2021-02-23 14:37:26 +01:00
|
|
|
$(".stream-row.active").hasClass = (cls) => {
|
2018-05-15 19:36:25 +02:00
|
|
|
assert.equal(cls, "notdisplayed");
|
|
|
|
return $(".stream-row-denmark").hasClass("active");
|
2017-03-04 17:55:16 +01:00
|
|
|
};
|
2021-02-23 14:37:26 +01:00
|
|
|
$(".stream-row.active").removeClass = (cls) => {
|
2018-05-15 19:36:25 +02:00
|
|
|
assert.equal(cls, "active");
|
|
|
|
$(".stream-row-denmark").removeClass("active");
|
2017-03-04 17:55:16 +01:00
|
|
|
};
|
|
|
|
|
2024-05-08 15:00:30 +02:00
|
|
|
test_filter({input: "d", show_subscribed: true}, [poland]);
|
2024-03-06 17:02:06 +01:00
|
|
|
assert.ok($(".stream-row-denmark").hasClass("active"));
|
|
|
|
|
|
|
|
stream_settings_ui.switch_stream_tab("subscribed");
|
2021-06-10 08:32:54 +02:00
|
|
|
assert.ok(!$(".stream-row-denmark").hasClass("active"));
|
|
|
|
assert.ok(!$(".right .settings").visible());
|
|
|
|
assert.ok($(".nothing-selected").visible());
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|
2024-05-16 02:22:03 +02:00
|
|
|
|
|
|
|
run_test("close color container when scrolling", ({mock_template}) => {
|
|
|
|
// Test to see if logic of the colorpicker closing is correct
|
|
|
|
const admins_group = {
|
|
|
|
name: "Admins",
|
|
|
|
id: 1,
|
|
|
|
members: new Set([1]),
|
|
|
|
is_system_group: true,
|
|
|
|
direct_subgroup_ids: new Set([]),
|
|
|
|
};
|
|
|
|
user_groups.initialize({realm_user_groups: [admins_group]});
|
|
|
|
|
|
|
|
const denmark = {
|
|
|
|
elem: "denmark",
|
|
|
|
subscribed: false,
|
|
|
|
name: "Denmark",
|
|
|
|
stream_id: denmark_stream_id,
|
|
|
|
description: "Copenhagen",
|
|
|
|
subscribers: [1],
|
|
|
|
stream_weekly_traffic: null,
|
|
|
|
color: "red",
|
|
|
|
can_remove_subscribers_group: admins_group.id,
|
|
|
|
};
|
|
|
|
|
|
|
|
const populated_subs = [denmark];
|
|
|
|
|
|
|
|
mock_template("stream_settings/browse_streams_list.hbs", false, (data) => {
|
|
|
|
data.subscriptions = populated_subs;
|
|
|
|
});
|
|
|
|
|
|
|
|
stream_settings_ui.render_left_panel_superset();
|
|
|
|
|
|
|
|
const sub_stubs = [];
|
|
|
|
|
|
|
|
for (const data of populated_subs) {
|
|
|
|
const sub_row = `.stream-row-${CSS.escape(data.elem)}`;
|
|
|
|
sub_stubs.push(sub_row);
|
|
|
|
|
|
|
|
$(sub_row).attr("data-stream-id", data.stream_id);
|
|
|
|
}
|
|
|
|
|
|
|
|
$.create("#streams_overlay_container .stream-row", {children: sub_stubs});
|
|
|
|
|
|
|
|
let colorpicker_closed = false;
|
|
|
|
|
|
|
|
$("#stream_settings").on("scroll", () => {
|
|
|
|
// Set colorpicker_closed to true when scrolling to test out the logic
|
|
|
|
colorpicker_closed = true;
|
|
|
|
});
|
|
|
|
|
|
|
|
$("#stream_settings").trigger("scroll");
|
|
|
|
|
|
|
|
// Check that the variable was indeed changed following the logic
|
|
|
|
assert.ok(colorpicker_closed);
|
|
|
|
});
|