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:
161
web/tests/list_cursor.test.cjs
Normal file
161
web/tests/list_cursor.test.cjs
Normal file
@@ -0,0 +1,161 @@
|
||||
"use strict";
|
||||
|
||||
const assert = require("node:assert/strict");
|
||||
|
||||
const {zrequire} = require("./lib/namespace.cjs");
|
||||
const {run_test, noop} = require("./lib/test.cjs");
|
||||
const blueslip = require("./lib/zblueslip.cjs");
|
||||
const {$} = require("./lib/zjquery.cjs");
|
||||
|
||||
const {ListCursor} = zrequire("list_cursor");
|
||||
|
||||
function basic_conf({first_key, prev_key, next_key}) {
|
||||
const list = {
|
||||
scroll_container_selector: "whatever",
|
||||
find_li() {},
|
||||
first_key,
|
||||
prev_key,
|
||||
next_key,
|
||||
};
|
||||
|
||||
const conf = {
|
||||
list,
|
||||
highlight_class: "highlight",
|
||||
};
|
||||
|
||||
return conf;
|
||||
}
|
||||
|
||||
run_test("misc errors", ({override}) => {
|
||||
const conf = basic_conf({
|
||||
first_key: () => undefined,
|
||||
prev_key: /* istanbul ignore next */ () => undefined,
|
||||
next_key: /* istanbul ignore next */ () => undefined,
|
||||
});
|
||||
|
||||
const cursor = new ListCursor(conf);
|
||||
|
||||
// Test that we just ignore empty
|
||||
// lists for unknown keys.
|
||||
override(conf.list, "find_li", ({key, force_render}) => {
|
||||
assert.equal(key, "nada");
|
||||
assert.equal(force_render, true);
|
||||
return [];
|
||||
});
|
||||
|
||||
cursor.get_row("nada");
|
||||
|
||||
blueslip.expect("error", "Caller is not checking keys for ListCursor.go_to");
|
||||
cursor.go_to(undefined);
|
||||
|
||||
blueslip.expect("error", "Cannot highlight key for ListCursor");
|
||||
cursor.go_to("nada");
|
||||
|
||||
cursor.prev();
|
||||
cursor.next();
|
||||
});
|
||||
|
||||
run_test("single item list", ({override}) => {
|
||||
const valid_key = "42";
|
||||
|
||||
const conf = basic_conf({
|
||||
first_key: /* istanbul ignore next */ () => valid_key,
|
||||
next_key: () => undefined,
|
||||
prev_key: () => undefined,
|
||||
});
|
||||
const cursor = new ListCursor(conf);
|
||||
|
||||
const $li_stub = {
|
||||
length: 1,
|
||||
addClass() {},
|
||||
};
|
||||
|
||||
override(conf.list, "find_li", () => $li_stub);
|
||||
override(cursor, "adjust_scroll", noop);
|
||||
|
||||
cursor.set_is_highlight_visible(true);
|
||||
cursor.go_to(valid_key);
|
||||
|
||||
// Test prev/next, which should just silently do nothing.
|
||||
cursor.prev();
|
||||
cursor.next();
|
||||
|
||||
// The next line is also a noop designed to just give us test
|
||||
// coverage.
|
||||
cursor.go_to(valid_key);
|
||||
});
|
||||
|
||||
run_test("multiple item list", ({override}) => {
|
||||
const conf = basic_conf({
|
||||
first_key: /* istanbul ignore next */ () => 1,
|
||||
next_key: (key) => (key < 3 ? key + 1 : undefined),
|
||||
prev_key: (key) => (key > 1 ? key - 1 : undefined),
|
||||
});
|
||||
const cursor = new ListCursor(conf);
|
||||
override(cursor, "adjust_scroll", noop);
|
||||
|
||||
function li(key) {
|
||||
return $.create(`item-${key}`);
|
||||
}
|
||||
|
||||
const list_items = {
|
||||
1: li(1),
|
||||
2: li(2),
|
||||
3: li(3),
|
||||
};
|
||||
|
||||
override(conf.list, "find_li", ({key}) => list_items[key]);
|
||||
|
||||
cursor.go_to(2);
|
||||
assert.equal(cursor.get_key(), 2);
|
||||
assert.ok(!list_items[1].hasClass("highlight"));
|
||||
// Selection is not highlighted until we want it to.
|
||||
assert.ok(!list_items[2].hasClass("highlight"));
|
||||
assert.ok(!list_items[3].hasClass("highlight"));
|
||||
|
||||
// Current selection is not highlighted until user wants
|
||||
// to move the cursor.
|
||||
// Also, cursor doesn't move if the selection was not
|
||||
// previously highlighted.
|
||||
cursor.next();
|
||||
assert.equal(cursor.get_key(), 2);
|
||||
assert.ok(!list_items[1].hasClass("highlight"));
|
||||
assert.ok(list_items[2].hasClass("highlight"));
|
||||
assert.ok(!list_items[3].hasClass("highlight"));
|
||||
// Reset state
|
||||
cursor.set_is_highlight_visible(false);
|
||||
cursor.prev();
|
||||
assert.equal(cursor.get_key(), 2);
|
||||
assert.ok(!list_items[1].hasClass("highlight"));
|
||||
assert.ok(list_items[2].hasClass("highlight"));
|
||||
assert.ok(!list_items[3].hasClass("highlight"));
|
||||
|
||||
cursor.next();
|
||||
cursor.next();
|
||||
cursor.next();
|
||||
|
||||
assert.equal(cursor.get_key(), 3);
|
||||
assert.ok(!list_items[1].hasClass("highlight"));
|
||||
assert.ok(!list_items[2].hasClass("highlight"));
|
||||
assert.ok(list_items[3].hasClass("highlight"));
|
||||
|
||||
cursor.prev();
|
||||
cursor.prev();
|
||||
cursor.prev();
|
||||
|
||||
assert.equal(cursor.get_key(), 1);
|
||||
assert.ok(list_items[1].hasClass("highlight"));
|
||||
assert.ok(!list_items[2].hasClass("highlight"));
|
||||
assert.ok(!list_items[3].hasClass("highlight"));
|
||||
|
||||
override(conf.list, "find_li", () => list_items[1]);
|
||||
cursor.redraw();
|
||||
assert.ok(list_items[1].hasClass("highlight"));
|
||||
assert.ok(!list_items[2].hasClass("highlight"));
|
||||
assert.ok(!list_items[3].hasClass("highlight"));
|
||||
|
||||
cursor.clear();
|
||||
assert.equal(cursor.get_key(), undefined);
|
||||
cursor.redraw();
|
||||
assert.ok(!list_items[1].hasClass("highlight"));
|
||||
});
|
||||
Reference in New Issue
Block a user