2021-04-15 02:59:34 +02:00
|
|
|
"use strict";
|
|
|
|
|
|
|
|
// Setup
|
|
|
|
const {strict: assert} = require("assert");
|
|
|
|
|
2023-02-22 23:04:10 +01:00
|
|
|
const {mock_esm, set_global, zrequire} = require("./lib/namespace");
|
2023-12-14 23:51:33 +01:00
|
|
|
const {run_test, noop} = require("./lib/test");
|
2023-02-22 23:04:10 +01:00
|
|
|
const $ = require("./lib/zjquery");
|
2021-04-15 02:59:34 +02:00
|
|
|
|
|
|
|
// Mocking and stubbing things
|
|
|
|
set_global("document", "document-stub");
|
2023-02-22 23:04:10 +01:00
|
|
|
const message_lists = mock_esm("../src/message_lists");
|
2022-08-18 00:03:29 +02:00
|
|
|
function MessageListView() {
|
|
|
|
return {
|
|
|
|
maybe_rerender: noop,
|
|
|
|
append: noop,
|
|
|
|
prepend: noop,
|
|
|
|
};
|
|
|
|
}
|
2023-02-22 23:04:10 +01:00
|
|
|
mock_esm("../src/message_list_view", {
|
2022-08-18 00:03:29 +02:00
|
|
|
MessageListView,
|
|
|
|
});
|
2023-07-26 22:07:21 +02:00
|
|
|
const stream_data = zrequire("stream_data");
|
2021-04-15 02:59:34 +02:00
|
|
|
// Code we're actually using/testing
|
|
|
|
const compose_closed_ui = zrequire("compose_closed_ui");
|
2021-05-07 21:59:10 +02:00
|
|
|
const {Filter} = zrequire("filter");
|
2021-04-15 02:59:34 +02:00
|
|
|
const {MessageList} = zrequire("message_list");
|
|
|
|
|
|
|
|
// Helper test function
|
|
|
|
function test_reply_label(expected_label) {
|
2023-06-20 15:08:26 +02:00
|
|
|
const label = $("#left_bar_compose_reply_button_big").text();
|
2021-05-10 14:01:27 +02:00
|
|
|
const prepend_text_length = "translated: Message ".length;
|
|
|
|
assert.equal(
|
|
|
|
label.slice(prepend_text_length),
|
|
|
|
expected_label,
|
|
|
|
"'" + label.slice(prepend_text_length),
|
|
|
|
Number("' did not match '") + expected_label + "'",
|
|
|
|
);
|
2021-04-15 02:59:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
run_test("reply_label", () => {
|
|
|
|
// Mocking up a test message list
|
2021-05-07 21:59:10 +02:00
|
|
|
const filter = new Filter();
|
2021-04-15 02:59:34 +02:00
|
|
|
const list = new MessageList({
|
|
|
|
filter,
|
|
|
|
});
|
|
|
|
message_lists.current = list;
|
2023-07-26 22:07:21 +02:00
|
|
|
const stream_one = {
|
|
|
|
subscribed: true,
|
|
|
|
name: "first_stream",
|
|
|
|
stream_id: 1,
|
|
|
|
};
|
|
|
|
stream_data.add_sub(stream_one);
|
|
|
|
const stream_two = {
|
|
|
|
subscribed: true,
|
|
|
|
name: "second_stream",
|
|
|
|
stream_id: 2,
|
|
|
|
};
|
|
|
|
stream_data.add_sub(stream_two);
|
2021-04-15 02:59:34 +02:00
|
|
|
list.add_messages([
|
|
|
|
{
|
|
|
|
id: 0,
|
2023-07-26 22:07:21 +02:00
|
|
|
stream_id: stream_one.stream_id,
|
2021-04-15 02:59:34 +02:00
|
|
|
topic: "first_topic",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
id: 1,
|
2023-07-26 22:07:21 +02:00
|
|
|
stream_id: stream_one.stream_id,
|
2021-04-15 02:59:34 +02:00
|
|
|
topic: "second_topic",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
id: 2,
|
2023-07-26 22:07:21 +02:00
|
|
|
stream_id: stream_two.stream_id,
|
2021-04-15 02:59:34 +02:00
|
|
|
topic: "third_topic",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
id: 3,
|
2023-07-26 22:07:21 +02:00
|
|
|
stream_id: stream_two.stream_id,
|
2021-04-15 02:59:34 +02:00
|
|
|
topic: "second_topic",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
id: 4,
|
|
|
|
display_reply_to: "some user",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
id: 5,
|
|
|
|
display_reply_to: "some user, other user",
|
|
|
|
},
|
|
|
|
]);
|
|
|
|
|
|
|
|
const expected_labels = [
|
|
|
|
"#first_stream > first_topic",
|
|
|
|
"#first_stream > second_topic",
|
|
|
|
"#second_stream > third_topic",
|
|
|
|
"#second_stream > second_topic",
|
|
|
|
"some user",
|
|
|
|
"some user, other user",
|
|
|
|
];
|
|
|
|
|
|
|
|
// Initialize the code we're testing.
|
|
|
|
compose_closed_ui.initialize();
|
|
|
|
|
|
|
|
// Run the tests!
|
|
|
|
let first = true;
|
|
|
|
for (const expected_label of expected_labels) {
|
|
|
|
if (first) {
|
|
|
|
list.select_id(list.first().id);
|
|
|
|
first = false;
|
|
|
|
} else {
|
|
|
|
list.select_id(list.next());
|
|
|
|
}
|
|
|
|
test_reply_label(expected_label);
|
|
|
|
}
|
|
|
|
});
|
2021-03-18 13:57:28 +01:00
|
|
|
|
|
|
|
run_test("test_custom_message_input", () => {
|
2023-07-26 22:07:21 +02:00
|
|
|
const stream = {
|
|
|
|
subscribed: true,
|
|
|
|
name: "stream test",
|
|
|
|
stream_id: 10,
|
|
|
|
};
|
|
|
|
stream_data.add_sub(stream);
|
2021-03-18 13:57:28 +01:00
|
|
|
compose_closed_ui.update_reply_recipient_label({
|
2023-07-26 22:07:21 +02:00
|
|
|
stream_id: stream.stream_id,
|
2021-03-18 13:57:28 +01:00
|
|
|
topic: "topic test",
|
|
|
|
});
|
|
|
|
test_reply_label("#stream test > topic test");
|
|
|
|
});
|
2021-05-10 17:21:20 +02:00
|
|
|
|
|
|
|
run_test("empty_narrow", () => {
|
2023-05-02 04:04:46 +02:00
|
|
|
message_lists.current.visibly_empty = () => true;
|
2021-05-10 17:21:20 +02:00
|
|
|
compose_closed_ui.update_reply_recipient_label();
|
2023-06-20 15:08:26 +02:00
|
|
|
const label = $("#left_bar_compose_reply_button_big").text();
|
2021-05-10 17:21:20 +02:00
|
|
|
assert.equal(label, "translated: Compose message");
|
|
|
|
});
|