2020-08-01 03:43:15 +02:00
|
|
|
"use strict";
|
|
|
|
|
2016-12-26 10:13:31 +01:00
|
|
|
global.stub_out_jquery();
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
set_global("ui", {
|
2020-07-02 01:39:34 +02:00
|
|
|
get_content_element: (element) => element,
|
|
|
|
get_scroll_element: (element) => element,
|
2019-03-01 01:40:05 +01:00
|
|
|
});
|
2020-07-15 01:29:15 +02:00
|
|
|
zrequire("stream_data");
|
|
|
|
zrequire("search_util");
|
|
|
|
set_global("page_params", {});
|
2018-07-29 16:11:48 +02:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
set_global("location", {
|
2019-07-25 09:13:22 +02:00
|
|
|
hash: "#streams/1/announce",
|
2017-08-02 16:51:37 +02:00
|
|
|
});
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
zrequire("subs");
|
2016-12-26 10:13:31 +01:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
set_global("$", global.make_zjquery());
|
|
|
|
set_global("hash_util", {
|
2020-06-16 18:42:13 +02:00
|
|
|
by_stream_uri: () => {},
|
|
|
|
});
|
2018-07-30 20:05:56 +02:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
run_test("filter_table", () => {
|
2019-11-02 00:06:25 +01:00
|
|
|
const stream_list = $(".streams-list");
|
2018-05-15 19:36:25 +02:00
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
let scrolltop_called = false;
|
2018-05-15 19:36:25 +02:00
|
|
|
stream_list.scrollTop = function (set) {
|
|
|
|
scrolltop_called = true;
|
|
|
|
if (!set) {
|
|
|
|
return 10;
|
|
|
|
}
|
|
|
|
assert.equal(set, 10);
|
|
|
|
};
|
|
|
|
|
|
|
|
// set-up sub rows stubs
|
2020-02-06 02:25:08 +01:00
|
|
|
const sub_row_data = [
|
|
|
|
{
|
2020-07-15 01:29:15 +02:00
|
|
|
elem: "denmark",
|
2020-02-06 02:25:08 +01:00
|
|
|
subscribed: false,
|
2020-07-15 01:29:15 +02:00
|
|
|
name: "Denmark",
|
2020-02-06 02:25:08 +01:00
|
|
|
stream_id: 1,
|
2020-07-15 01:29:15 +02:00
|
|
|
description: "Copenhagen",
|
2020-03-31 17:13:01 +02:00
|
|
|
subscribers: {size: 1},
|
2020-06-16 18:42:13 +02:00
|
|
|
stream_weekly_traffic: null,
|
2020-02-06 02:25:08 +01:00
|
|
|
},
|
|
|
|
{
|
2020-07-15 01:29:15 +02:00
|
|
|
elem: "poland",
|
2020-02-06 02:25:08 +01:00
|
|
|
subscribed: true,
|
2020-07-15 01:29:15 +02:00
|
|
|
name: "Poland",
|
2020-02-06 02:25:08 +01:00
|
|
|
stream_id: 2,
|
2020-07-15 01:29:15 +02:00
|
|
|
description: "monday",
|
2020-03-31 17:13:01 +02:00
|
|
|
subscribers: {size: 3},
|
|
|
|
stream_weekly_traffic: 13,
|
2020-02-06 02:25:08 +01:00
|
|
|
},
|
|
|
|
{
|
2020-07-15 01:29:15 +02:00
|
|
|
elem: "pomona",
|
2020-02-06 02:25:08 +01:00
|
|
|
subscribed: true,
|
2020-07-15 01:29:15 +02:00
|
|
|
name: "Pomona",
|
2020-02-06 02:25:08 +01:00
|
|
|
stream_id: 3,
|
2020-07-15 01:29:15 +02:00
|
|
|
description: "college",
|
2020-03-31 17:13:01 +02:00
|
|
|
subscribers: {size: 0},
|
|
|
|
stream_weekly_traffic: 0,
|
2020-02-06 02:25:08 +01:00
|
|
|
},
|
|
|
|
{
|
2020-07-15 01:29:15 +02:00
|
|
|
elem: "cpp",
|
2020-02-06 02:25:08 +01:00
|
|
|
subscribed: true,
|
2020-07-15 01:29:15 +02:00
|
|
|
name: "C++",
|
2020-02-06 02:25:08 +01:00
|
|
|
stream_id: 4,
|
2020-07-15 01:29:15 +02:00
|
|
|
description: "programming lang",
|
2020-03-31 17:13:01 +02:00
|
|
|
subscribers: {size: 2},
|
|
|
|
stream_weekly_traffic: 6,
|
|
|
|
},
|
|
|
|
{
|
2020-07-15 01:29:15 +02:00
|
|
|
elem: "zzyzx",
|
2020-03-31 17:13:01 +02:00
|
|
|
subscribed: true,
|
2020-07-15 01:29:15 +02:00
|
|
|
name: "Zzyzx",
|
2020-03-31 17:13:01 +02:00
|
|
|
stream_id: 5,
|
2020-07-15 01:29:15 +02:00
|
|
|
description: "california town",
|
2020-03-31 17:13:01 +02:00
|
|
|
subscribers: {size: 2},
|
|
|
|
stream_weekly_traffic: 6,
|
2020-02-06 02:25:08 +01:00
|
|
|
},
|
|
|
|
];
|
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) {
|
2020-02-09 22:02:55 +01:00
|
|
|
stream_data.add_sub(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
|
|
|
|
2019-07-11 05:06:20 +02:00
|
|
|
global.stub_templates((fn, data) => {
|
2020-07-15 01:29:15 +02:00
|
|
|
assert.equal(fn, "subscriptions");
|
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
|
|
|
|
|
|
|
subs.populate_stream_settings_left_panel();
|
|
|
|
|
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) {
|
2019-11-02 00:06:25 +01:00
|
|
|
const sub_row = ".stream-row-" + data.elem;
|
2018-05-15 19:36:25 +02:00
|
|
|
sub_stubs.push(sub_row);
|
|
|
|
|
|
|
|
$(sub_row).attr("data-stream-id", data.stream_id);
|
2020-07-15 00:34:28 +02:00
|
|
|
$(sub_row).set_find_results(
|
|
|
|
'.sub-info-box [class$="-bar"] [class$="-count"]',
|
|
|
|
$(".tooltip"),
|
|
|
|
);
|
2018-05-15 19:36:25 +02:00
|
|
|
$(sub_row).detach = function () {
|
|
|
|
return 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
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
let tooltip_called = false;
|
2018-05-15 19:36:25 +02:00
|
|
|
$(".tooltip").tooltip = function (obj) {
|
|
|
|
tooltip_called = true;
|
|
|
|
assert.deepEqual(obj, {
|
2020-07-15 01:29:15 +02:00
|
|
|
placement: "left",
|
2018-05-15 19:36:25 +02:00
|
|
|
animation: false,
|
|
|
|
});
|
|
|
|
};
|
2016-12-26 10:13:31 +01:00
|
|
|
|
2018-05-15 19:36:25 +02:00
|
|
|
$.stub_selector("#subscriptions_table .stream-row", sub_stubs);
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
const sub_table = $("#subscriptions_table .streams-list");
|
2019-11-02 00:06:25 +01:00
|
|
|
let sub_table_append = [];
|
2018-05-15 19:36:25 +02:00
|
|
|
sub_table.append = function (rows) {
|
2018-07-29 14:55:29 +02:00
|
|
|
sub_table_append.push(rows);
|
2018-05-15 19:36:25 +02:00
|
|
|
};
|
2016-12-26 10:13:31 +01:00
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
let ui_called = false;
|
2019-01-09 14:30:35 +01:00
|
|
|
ui.reset_scrollbar = function (elem) {
|
2018-05-15 19:36:25 +02:00
|
|
|
ui_called = true;
|
|
|
|
assert.equal(elem, $("#subscription_overlay .streams-list"));
|
|
|
|
};
|
2016-12-26 10:13:31 +01:00
|
|
|
|
|
|
|
// Search with single keyword
|
|
|
|
subs.filter_table({input: "Po", subscribed_only: false});
|
2018-05-15 19:36:25 +02:00
|
|
|
assert($(".stream-row-denmark").hasClass("notdisplayed"));
|
|
|
|
assert(!$(".stream-row-poland").hasClass("notdisplayed"));
|
|
|
|
assert(!$(".stream-row-pomona").hasClass("notdisplayed"));
|
|
|
|
assert($(".stream-row-cpp").hasClass("notdisplayed"));
|
2020-03-31 17:13:01 +02:00
|
|
|
assert($(".stream-row-zzyzx").hasClass("notdisplayed"));
|
2018-05-15 19:36:25 +02:00
|
|
|
|
|
|
|
// assert these once and call it done
|
|
|
|
assert(ui_called);
|
|
|
|
assert(scrolltop_called);
|
|
|
|
assert(tooltip_called);
|
|
|
|
assert.deepEqual(sub_table_append, [
|
2020-07-15 01:29:15 +02:00
|
|
|
".stream-row-poland",
|
|
|
|
".stream-row-pomona",
|
|
|
|
".stream-row-cpp",
|
|
|
|
".stream-row-zzyzx",
|
|
|
|
".stream-row-denmark",
|
2018-05-15 19:36:25 +02:00
|
|
|
]);
|
2016-12-26 10:13:31 +01:00
|
|
|
|
|
|
|
// Search with multiple keywords
|
|
|
|
subs.filter_table({input: "Denmark, Pol", subscribed_only: false});
|
2018-05-15 19:36:25 +02:00
|
|
|
assert(!$(".stream-row-denmark").hasClass("notdisplayed"));
|
|
|
|
assert(!$(".stream-row-poland").hasClass("notdisplayed"));
|
|
|
|
assert($(".stream-row-pomona").hasClass("notdisplayed"));
|
|
|
|
assert($(".stream-row-cpp").hasClass("notdisplayed"));
|
2020-03-31 17:13:01 +02:00
|
|
|
assert($(".stream-row-zzyzx").hasClass("notdisplayed"));
|
2016-12-26 10:13:31 +01:00
|
|
|
|
|
|
|
subs.filter_table({input: "Den, Pol", subscribed_only: false});
|
2018-05-15 19:36:25 +02:00
|
|
|
assert(!$(".stream-row-denmark").hasClass("notdisplayed"));
|
|
|
|
assert(!$(".stream-row-poland").hasClass("notdisplayed"));
|
|
|
|
assert($(".stream-row-pomona").hasClass("notdisplayed"));
|
|
|
|
assert($(".stream-row-cpp").hasClass("notdisplayed"));
|
2020-03-31 17:13:01 +02:00
|
|
|
assert($(".stream-row-zzyzx").hasClass("notdisplayed"));
|
2016-12-26 10:13:31 +01:00
|
|
|
|
|
|
|
// Search is case-insensitive
|
|
|
|
subs.filter_table({input: "po", subscribed_only: false});
|
2018-05-15 19:36:25 +02:00
|
|
|
assert($(".stream-row-denmark").hasClass("notdisplayed"));
|
|
|
|
assert(!$(".stream-row-poland").hasClass("notdisplayed"));
|
|
|
|
assert(!$(".stream-row-pomona").hasClass("notdisplayed"));
|
|
|
|
assert($(".stream-row-cpp").hasClass("notdisplayed"));
|
2020-03-31 17:13:01 +02:00
|
|
|
assert($(".stream-row-zzyzx").hasClass("notdisplayed"));
|
2016-12-26 10:13:31 +01:00
|
|
|
|
2017-02-04 13:02:31 +01:00
|
|
|
// Search handles unusual characters like C++
|
|
|
|
subs.filter_table({input: "c++", subscribed_only: false});
|
2018-05-15 19:36:25 +02:00
|
|
|
assert($(".stream-row-denmark").hasClass("notdisplayed"));
|
|
|
|
assert($(".stream-row-poland").hasClass("notdisplayed"));
|
|
|
|
assert($(".stream-row-pomona").hasClass("notdisplayed"));
|
|
|
|
assert(!$(".stream-row-cpp").hasClass("notdisplayed"));
|
2020-03-31 17:13:01 +02:00
|
|
|
assert($(".stream-row-zzyzx").hasClass("notdisplayed"));
|
2017-02-04 13:02:31 +01:00
|
|
|
|
2016-12-26 10:13:31 +01:00
|
|
|
// Search subscribed streams only
|
|
|
|
subs.filter_table({input: "d", subscribed_only: true});
|
2018-05-15 19:36:25 +02:00
|
|
|
assert($(".stream-row-denmark").hasClass("notdisplayed"));
|
|
|
|
assert(!$(".stream-row-poland").hasClass("notdisplayed"));
|
|
|
|
assert($(".stream-row-pomona").hasClass("notdisplayed"));
|
|
|
|
assert($(".stream-row-cpp").hasClass("notdisplayed"));
|
2020-03-31 17:13:01 +02:00
|
|
|
assert($(".stream-row-zzyzx").hasClass("notdisplayed"));
|
2017-01-03 13:26:48 +01:00
|
|
|
|
|
|
|
// Search terms match stream description
|
|
|
|
subs.filter_table({input: "Co", subscribed_only: false});
|
2018-05-15 19:36:25 +02:00
|
|
|
assert(!$(".stream-row-denmark").hasClass("notdisplayed"));
|
|
|
|
assert($(".stream-row-poland").hasClass("notdisplayed"));
|
|
|
|
assert(!$(".stream-row-pomona").hasClass("notdisplayed"));
|
|
|
|
assert($(".stream-row-cpp").hasClass("notdisplayed"));
|
2020-03-31 17:13:01 +02:00
|
|
|
assert($(".stream-row-zzyzx").hasClass("notdisplayed"));
|
2018-05-15 19:36:25 +02:00
|
|
|
|
|
|
|
// Search names AND descriptions
|
|
|
|
sub_table_append = [];
|
2017-01-03 13:26:48 +01:00
|
|
|
|
|
|
|
subs.filter_table({input: "Mon", subscribed_only: false});
|
2018-05-15 19:36:25 +02:00
|
|
|
assert($(".stream-row-denmark").hasClass("notdisplayed"));
|
|
|
|
assert(!$(".stream-row-poland").hasClass("notdisplayed"));
|
|
|
|
assert(!$(".stream-row-pomona").hasClass("notdisplayed"));
|
|
|
|
assert($(".stream-row-cpp").hasClass("notdisplayed"));
|
2020-03-31 17:13:01 +02:00
|
|
|
assert($(".stream-row-zzyzx").hasClass("notdisplayed"));
|
|
|
|
assert.deepEqual(sub_table_append, [
|
2020-07-15 01:29:15 +02:00
|
|
|
".stream-row-pomona",
|
|
|
|
".stream-row-poland",
|
|
|
|
".stream-row-cpp",
|
|
|
|
".stream-row-zzyzx",
|
|
|
|
".stream-row-denmark",
|
2020-03-31 17:13:01 +02:00
|
|
|
]);
|
|
|
|
|
|
|
|
// Explicitly order streams by name
|
|
|
|
sub_table_append = [];
|
|
|
|
subs.filter_table({input: "", subscribed_only: false, sort_order: "by-stream-name"});
|
2018-05-15 19:36:25 +02:00
|
|
|
assert.deepEqual(sub_table_append, [
|
2020-07-15 01:29:15 +02:00
|
|
|
".stream-row-cpp",
|
|
|
|
".stream-row-denmark",
|
|
|
|
".stream-row-poland",
|
|
|
|
".stream-row-pomona",
|
|
|
|
".stream-row-zzyzx",
|
2020-03-31 17:13:01 +02:00
|
|
|
]);
|
|
|
|
|
|
|
|
// Order streams by subscriber count
|
|
|
|
sub_table_append = [];
|
|
|
|
subs.filter_table({input: "", subscribed_only: false, sort_order: "by-subscriber-count"});
|
|
|
|
assert.deepEqual(sub_table_append, [
|
2020-07-15 01:29:15 +02:00
|
|
|
".stream-row-poland",
|
|
|
|
".stream-row-cpp",
|
|
|
|
".stream-row-zzyzx",
|
|
|
|
".stream-row-denmark",
|
|
|
|
".stream-row-pomona",
|
2020-03-31 17:13:01 +02:00
|
|
|
]);
|
|
|
|
|
|
|
|
// Order streams by weekly traffic
|
|
|
|
sub_table_append = [];
|
|
|
|
subs.filter_table({input: "", subscribed_only: false, sort_order: "by-weekly-traffic"});
|
|
|
|
assert.deepEqual(sub_table_append, [
|
2020-07-15 01:29:15 +02:00
|
|
|
".stream-row-poland",
|
|
|
|
".stream-row-cpp",
|
|
|
|
".stream-row-zzyzx",
|
|
|
|
".stream-row-pomona",
|
|
|
|
".stream-row-denmark",
|
2020-03-31 17:13:01 +02:00
|
|
|
]);
|
|
|
|
|
|
|
|
// Showing subscribed streams only puts un-subscribed DOM elements last
|
|
|
|
sub_table_append = [];
|
|
|
|
subs.filter_table({input: "", subscribed_only: true, sort_order: "by-subscriber-count"});
|
|
|
|
assert.deepEqual(sub_table_append, [
|
2020-07-15 01:29:15 +02:00
|
|
|
".stream-row-poland",
|
|
|
|
".stream-row-cpp",
|
|
|
|
".stream-row-zzyzx",
|
|
|
|
".stream-row-pomona",
|
|
|
|
".stream-row-denmark",
|
2018-05-15 19:36:25 +02:00
|
|
|
]);
|
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");
|
|
|
|
$(".stream-row.active").hasClass = function (cls) {
|
|
|
|
assert.equal(cls, "notdisplayed");
|
|
|
|
return $(".stream-row-denmark").hasClass("active");
|
2017-03-04 17:55:16 +01:00
|
|
|
};
|
2018-05-15 19:36:25 +02:00
|
|
|
$(".stream-row.active").removeClass = function (cls) {
|
|
|
|
assert.equal(cls, "active");
|
|
|
|
$(".stream-row-denmark").removeClass("active");
|
2017-03-04 17:55:16 +01:00
|
|
|
};
|
|
|
|
|
2018-05-15 19:36:25 +02:00
|
|
|
subs.filter_table({input: "d", subscribed_only: true});
|
|
|
|
assert(!$(".stream-row-denmark").hasClass("active"));
|
|
|
|
assert(!$(".right .settings").visible());
|
|
|
|
assert($(".nothing-selected").visible());
|
2017-03-04 17:55:16 +01:00
|
|
|
|
2018-05-15 19:36:25 +02:00
|
|
|
subs.filter_table({input: "d", subscribed_only: true});
|
2018-07-30 20:51:08 +02:00
|
|
|
assert($(".stream-row-denmark").hasClass("notdisplayed"));
|
2018-05-15 19:36:25 +02:00
|
|
|
assert(!$(".stream-row-poland").hasClass("notdisplayed"));
|
|
|
|
assert($(".stream-row-pomona").hasClass("notdisplayed"));
|
|
|
|
assert($(".stream-row-cpp").hasClass("notdisplayed"));
|
2020-03-31 17:13:01 +02:00
|
|
|
assert($(".stream-row-zzyzx").hasClass("notdisplayed"));
|
2017-03-04 17:55:16 +01:00
|
|
|
|
2018-05-15 19:36:25 +02:00
|
|
|
subs.filter_table({input: "d", subscribed_only: true});
|
|
|
|
assert($(".stream-row-denmark").hasClass("notdisplayed"));
|
|
|
|
assert(!$(".stream-row-poland").hasClass("notdisplayed"));
|
|
|
|
assert($(".stream-row-pomona").hasClass("notdisplayed"));
|
|
|
|
assert($(".stream-row-cpp").hasClass("notdisplayed"));
|
2020-03-31 17:13:01 +02:00
|
|
|
assert($(".stream-row-zzyzx").hasClass("notdisplayed"));
|
2018-05-15 19:36:25 +02:00
|
|
|
|
|
|
|
// test selected row set to active
|
|
|
|
$(".stream-row[data-stream-id='1']").removeClass("active");
|
|
|
|
subs.filter_table({input: "", subscribed_only: false});
|
|
|
|
assert($(".stream-row[data-stream-id='1']").hasClass("active"));
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|