2020-08-01 03:43:15 +02:00
|
|
|
"use strict";
|
|
|
|
|
2020-11-30 23:46:45 +01:00
|
|
|
const {strict: assert} = require("assert");
|
|
|
|
|
2021-03-10 06:10:32 +01:00
|
|
|
const {mock_esm, zrequire} = require("../zjsunit/namespace");
|
2020-12-01 00:39:47 +01:00
|
|
|
const {run_test} = require("../zjsunit/test");
|
2020-12-01 00:02:16 +01:00
|
|
|
|
2021-03-10 06:10:32 +01:00
|
|
|
mock_esm("../../static/js/message_scroll", {
|
2020-06-15 12:47:11 +02:00
|
|
|
hide_loading_older: () => {},
|
2021-03-06 17:37:51 +01:00
|
|
|
|
2020-06-15 12:47:11 +02:00
|
|
|
show_loading_older: () => {},
|
2020-06-15 11:53:00 +02:00
|
|
|
hide_loading_newer: () => {},
|
|
|
|
show_loading_newer: () => {},
|
|
|
|
});
|
2018-03-09 22:04:07 +01:00
|
|
|
|
2020-12-01 23:21:38 +01:00
|
|
|
const {FetchStatus} = zrequire("fetch_status");
|
|
|
|
|
2020-07-23 01:30:13 +02:00
|
|
|
let fetch_status = new FetchStatus();
|
2018-03-09 22:04:07 +01:00
|
|
|
|
|
|
|
function reset() {
|
2020-07-23 01:30:13 +02:00
|
|
|
fetch_status = new FetchStatus();
|
2018-03-09 22:04:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function can_load_newer() {
|
|
|
|
assert.equal(fetch_status.can_load_newer_messages(), true);
|
|
|
|
}
|
|
|
|
|
|
|
|
function blocked_newer() {
|
|
|
|
assert.equal(fetch_status.can_load_newer_messages(), false);
|
|
|
|
}
|
|
|
|
|
|
|
|
function can_load_older() {
|
|
|
|
assert.equal(fetch_status.can_load_older_messages(), true);
|
|
|
|
}
|
|
|
|
|
|
|
|
function blocked_older() {
|
|
|
|
assert.equal(fetch_status.can_load_older_messages(), false);
|
|
|
|
}
|
|
|
|
|
2020-06-13 12:26:36 +02:00
|
|
|
function has_found_oldest() {
|
|
|
|
assert.equal(fetch_status.has_found_oldest(), true);
|
|
|
|
}
|
|
|
|
|
|
|
|
function has_not_found_oldest() {
|
|
|
|
assert.equal(fetch_status.has_found_oldest(), false);
|
|
|
|
}
|
|
|
|
|
2018-05-03 19:44:11 +02:00
|
|
|
function has_found_newest() {
|
|
|
|
assert.equal(fetch_status.has_found_newest(), true);
|
|
|
|
}
|
|
|
|
|
|
|
|
function has_not_found_newest() {
|
|
|
|
assert.equal(fetch_status.has_found_newest(), false);
|
|
|
|
}
|
|
|
|
|
2018-12-13 00:53:35 +01:00
|
|
|
function can_load_history() {
|
|
|
|
assert.equal(fetch_status.history_limited(), false);
|
|
|
|
}
|
|
|
|
|
|
|
|
function blocked_history() {
|
|
|
|
assert.equal(fetch_status.history_limited(), true);
|
|
|
|
}
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
run_test("basics", () => {
|
2018-03-09 22:04:07 +01:00
|
|
|
reset();
|
|
|
|
|
2020-07-16 22:40:18 +02:00
|
|
|
fetch_status.start_newer_batch({update_loading_indicator: false});
|
|
|
|
fetch_status.start_older_batch({update_loading_indicator: false});
|
2018-03-16 14:15:30 +01:00
|
|
|
|
|
|
|
blocked_newer();
|
|
|
|
blocked_older();
|
2018-12-13 00:53:35 +01:00
|
|
|
can_load_history();
|
2020-06-13 12:26:36 +02:00
|
|
|
has_not_found_oldest();
|
2018-05-03 19:44:11 +02:00
|
|
|
has_not_found_newest();
|
2018-03-16 14:15:30 +01:00
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
let data = {
|
2020-06-15 11:53:00 +02:00
|
|
|
update_loading_indicator: false,
|
2018-03-16 14:15:30 +01:00
|
|
|
found_oldest: true,
|
|
|
|
found_newest: true,
|
2018-12-13 00:53:35 +01:00
|
|
|
history_limited: true,
|
2018-12-13 00:57:40 +01:00
|
|
|
};
|
2020-05-30 17:34:07 +02:00
|
|
|
fetch_status.finish_newer_batch([], data);
|
2018-12-13 00:57:40 +01:00
|
|
|
fetch_status.finish_older_batch(data);
|
2018-03-16 14:15:30 +01:00
|
|
|
|
2020-06-13 12:26:36 +02:00
|
|
|
has_found_oldest();
|
2018-05-03 19:44:11 +02:00
|
|
|
has_found_newest();
|
2018-03-16 14:15:30 +01:00
|
|
|
blocked_newer();
|
|
|
|
blocked_older();
|
2018-12-13 00:53:35 +01:00
|
|
|
blocked_history();
|
2018-03-16 14:15:30 +01:00
|
|
|
|
|
|
|
reset();
|
|
|
|
|
2020-07-16 22:40:18 +02:00
|
|
|
fetch_status.start_newer_batch({update_loading_indicator: true});
|
|
|
|
fetch_status.start_older_batch({update_loading_indicator: true});
|
2018-03-16 14:15:30 +01:00
|
|
|
|
|
|
|
blocked_newer();
|
|
|
|
blocked_older();
|
2018-12-13 00:53:35 +01:00
|
|
|
can_load_history();
|
2018-03-16 14:15:30 +01:00
|
|
|
|
2018-12-13 00:57:40 +01:00
|
|
|
data = {
|
2020-06-15 11:53:00 +02:00
|
|
|
update_loading_indicator: false,
|
2018-03-16 14:15:30 +01:00
|
|
|
found_oldest: false,
|
|
|
|
found_newest: false,
|
2018-12-13 00:53:35 +01:00
|
|
|
history_limited: false,
|
2018-12-13 00:57:40 +01:00
|
|
|
};
|
2020-05-30 17:34:07 +02:00
|
|
|
fetch_status.finish_newer_batch([], data);
|
2018-12-13 00:57:40 +01:00
|
|
|
fetch_status.finish_older_batch(data);
|
2018-03-16 14:15:30 +01:00
|
|
|
|
|
|
|
can_load_older();
|
|
|
|
can_load_newer();
|
2018-12-13 00:53:35 +01:00
|
|
|
can_load_history();
|
2018-03-16 14:15:30 +01:00
|
|
|
|
|
|
|
reset();
|
|
|
|
|
2018-03-09 22:04:07 +01:00
|
|
|
can_load_older();
|
|
|
|
|
2020-07-16 22:40:18 +02:00
|
|
|
fetch_status.start_older_batch({update_loading_indicator: false});
|
2018-03-09 22:04:07 +01:00
|
|
|
|
|
|
|
blocked_older();
|
|
|
|
can_load_newer();
|
2018-12-13 00:53:35 +01:00
|
|
|
can_load_history();
|
2018-03-09 22:04:07 +01:00
|
|
|
|
|
|
|
fetch_status.finish_older_batch({
|
2020-06-15 12:47:11 +02:00
|
|
|
update_loading_indicator: true,
|
2018-03-09 22:04:07 +01:00
|
|
|
found_oldest: false,
|
2018-12-13 00:53:35 +01:00
|
|
|
history_limited: false,
|
2018-03-09 22:04:07 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
can_load_older();
|
|
|
|
can_load_newer();
|
2018-12-13 00:53:35 +01:00
|
|
|
can_load_history();
|
2018-03-09 22:04:07 +01:00
|
|
|
|
2020-07-16 22:40:18 +02:00
|
|
|
fetch_status.start_older_batch({update_loading_indicator: true});
|
2018-03-09 22:04:07 +01:00
|
|
|
|
|
|
|
blocked_older();
|
|
|
|
can_load_newer();
|
2018-12-13 00:53:35 +01:00
|
|
|
can_load_history();
|
2018-03-09 22:04:07 +01:00
|
|
|
|
|
|
|
fetch_status.finish_older_batch({
|
2020-06-15 12:47:11 +02:00
|
|
|
update_loading_indicator: true,
|
2018-03-09 22:04:07 +01:00
|
|
|
found_oldest: true,
|
2018-12-13 00:53:35 +01:00
|
|
|
history_limited: true,
|
2018-03-09 22:04:07 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
blocked_older();
|
|
|
|
can_load_newer();
|
2018-12-13 00:53:35 +01:00
|
|
|
blocked_history();
|
2018-03-09 22:04:07 +01:00
|
|
|
|
|
|
|
reset();
|
|
|
|
|
|
|
|
can_load_older();
|
|
|
|
can_load_newer();
|
|
|
|
|
2020-07-16 22:40:18 +02:00
|
|
|
fetch_status.start_newer_batch({update_loading_indicator: false});
|
2018-03-09 22:04:07 +01:00
|
|
|
|
|
|
|
can_load_older();
|
|
|
|
blocked_newer();
|
|
|
|
|
2020-05-30 17:34:07 +02:00
|
|
|
fetch_status.finish_newer_batch([], {
|
2020-06-15 11:53:00 +02:00
|
|
|
update_loading_indicator: true,
|
2018-03-09 22:04:07 +01:00
|
|
|
found_newest: false,
|
|
|
|
});
|
|
|
|
|
|
|
|
can_load_older();
|
|
|
|
can_load_newer();
|
|
|
|
|
2020-07-16 22:40:18 +02:00
|
|
|
fetch_status.start_newer_batch({update_loading_indicator: true});
|
2018-03-09 22:04:07 +01:00
|
|
|
|
|
|
|
can_load_older();
|
|
|
|
blocked_newer();
|
|
|
|
|
2020-05-30 17:34:07 +02:00
|
|
|
fetch_status.finish_newer_batch([], {
|
2020-06-15 11:53:00 +02:00
|
|
|
update_loading_indicator: true,
|
2018-03-09 22:04:07 +01:00
|
|
|
found_newest: true,
|
|
|
|
});
|
|
|
|
|
|
|
|
can_load_older();
|
|
|
|
blocked_newer();
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|