2020-08-01 03:43:15 +02:00
|
|
|
"use strict";
|
|
|
|
|
2020-11-30 23:46:45 +01:00
|
|
|
const {strict: assert} = require("assert");
|
|
|
|
|
2022-10-21 00:44:55 +02:00
|
|
|
const {mock_banners} = require("./lib/compose_banner");
|
2024-02-02 00:23:35 +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");
|
|
|
|
const {user_settings} = require("./lib/zpage_params");
|
2017-02-22 02:34:05 +01:00
|
|
|
|
2024-03-15 21:51:16 +01:00
|
|
|
const user_pill = mock_esm("../src/user_pill");
|
|
|
|
const messages_overlay_ui = mock_esm("../src/messages_overlay_ui");
|
|
|
|
|
2022-08-28 03:48:27 +02:00
|
|
|
const compose_pm_pill = zrequire("compose_pm_pill");
|
2022-05-17 03:13:57 +02:00
|
|
|
const people = zrequire("people");
|
2022-08-28 03:48:27 +02:00
|
|
|
const compose_state = zrequire("compose_state");
|
2023-03-31 06:27:36 +02:00
|
|
|
const compose_recipient = zrequire("compose_recipient");
|
2022-10-14 02:18:56 +02:00
|
|
|
const sub_store = zrequire("sub_store");
|
|
|
|
const stream_data = zrequire("stream_data");
|
2022-11-02 01:10:11 +01:00
|
|
|
|
2022-05-17 03:13:57 +02:00
|
|
|
const aaron = {
|
|
|
|
email: "aaron@zulip.com",
|
|
|
|
user_id: 6,
|
|
|
|
full_name: "Aaron",
|
|
|
|
};
|
|
|
|
people.add_active_user(aaron);
|
|
|
|
|
2021-11-30 19:36:27 +01:00
|
|
|
const setTimeout_delay = 3000;
|
|
|
|
set_global("setTimeout", (f, delay) => {
|
|
|
|
assert.equal(delay, setTimeout_delay);
|
|
|
|
f();
|
|
|
|
});
|
2023-02-22 23:04:10 +01:00
|
|
|
mock_esm("../src/markdown", {
|
2024-01-22 07:55:55 +01:00
|
|
|
render: noop,
|
2021-03-06 17:37:51 +01:00
|
|
|
});
|
2023-02-22 23:04:10 +01:00
|
|
|
mock_esm("../src/overlays", {
|
2022-07-10 01:06:33 +02:00
|
|
|
open_overlay: noop,
|
|
|
|
});
|
2022-10-14 02:18:56 +02:00
|
|
|
|
2021-11-30 19:36:27 +01:00
|
|
|
const tippy_sel = ".top_left_drafts .unread_count";
|
|
|
|
let tippy_args;
|
|
|
|
let tippy_show_called;
|
|
|
|
let tippy_destroy_called;
|
|
|
|
mock_esm("tippy.js", {
|
2022-11-17 23:33:43 +01:00
|
|
|
default(sel, opts) {
|
2021-11-30 19:36:27 +01:00
|
|
|
assert.equal(sel, tippy_sel);
|
|
|
|
assert.deepEqual(opts, tippy_args);
|
|
|
|
return [
|
|
|
|
{
|
2022-11-17 23:33:43 +01:00
|
|
|
show() {
|
2021-11-30 19:36:27 +01:00
|
|
|
tippy_show_called = true;
|
|
|
|
},
|
2022-11-17 23:33:43 +01:00
|
|
|
destroy() {
|
2021-11-30 19:36:27 +01:00
|
|
|
tippy_destroy_called = true;
|
|
|
|
},
|
|
|
|
},
|
|
|
|
];
|
|
|
|
},
|
|
|
|
});
|
2021-07-28 16:00:58 +02:00
|
|
|
user_settings.twenty_four_hour_time = false;
|
2017-02-22 02:34:05 +01:00
|
|
|
|
2020-12-01 23:21:38 +01:00
|
|
|
const {localstorage} = zrequire("localstorage");
|
|
|
|
const drafts = zrequire("drafts");
|
2023-10-06 01:19:21 +02:00
|
|
|
const drafts_overlay_ui = zrequire("drafts_overlay_ui");
|
2020-12-01 23:21:38 +01:00
|
|
|
const timerender = zrequire("timerender");
|
|
|
|
|
2024-02-02 00:23:35 +01:00
|
|
|
const mock_current_timestamp = 1234;
|
2021-05-26 20:51:28 +02:00
|
|
|
const stream_id = 30;
|
2024-02-02 00:23:35 +01:00
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const draft_1 = {
|
2021-05-26 20:51:28 +02:00
|
|
|
stream_id,
|
2018-12-16 17:36:41 +01:00
|
|
|
topic: "topic",
|
2017-02-22 02:34:05 +01:00
|
|
|
type: "stream",
|
2021-05-10 07:02:14 +02:00
|
|
|
content: "Test stream message",
|
2024-02-02 00:23:35 +01:00
|
|
|
updatedAt: mock_current_timestamp,
|
2024-03-16 00:57:19 +01:00
|
|
|
is_sending_saving: false,
|
2024-03-30 04:59:19 +01:00
|
|
|
drafts_version: 1,
|
2017-02-22 02:34:05 +01:00
|
|
|
};
|
2019-11-02 00:06:25 +01:00
|
|
|
const draft_2 = {
|
2017-02-22 02:34:05 +01:00
|
|
|
private_message_recipient: "aaron@zulip.com",
|
2017-03-29 08:54:26 +02:00
|
|
|
reply_to: "aaron@zulip.com",
|
2017-02-22 02:34:05 +01:00
|
|
|
type: "private",
|
2023-06-16 17:37:19 +02:00
|
|
|
content: "Test direct message",
|
2024-02-02 00:23:35 +01:00
|
|
|
updatedAt: mock_current_timestamp,
|
2024-03-16 00:57:19 +01:00
|
|
|
is_sending_saving: false,
|
2024-03-30 04:59:19 +01:00
|
|
|
drafts_version: 1,
|
2017-02-22 02:34:05 +01:00
|
|
|
};
|
2019-11-02 00:06:25 +01:00
|
|
|
const short_msg = {
|
2021-05-26 20:51:28 +02:00
|
|
|
stream_id,
|
2022-09-28 21:35:43 +02:00
|
|
|
topic: "topic",
|
2018-08-21 23:04:30 +02:00
|
|
|
type: "stream",
|
|
|
|
content: "a",
|
2024-02-02 00:23:35 +01:00
|
|
|
updatedAt: mock_current_timestamp,
|
2024-03-16 00:57:19 +01:00
|
|
|
is_sending_saving: false,
|
2024-03-30 04:59:19 +01:00
|
|
|
drafts_version: 1,
|
2018-08-21 23:04:30 +02:00
|
|
|
};
|
2017-02-22 02:34:05 +01:00
|
|
|
|
2021-03-14 10:30:49 +01:00
|
|
|
function test(label, f) {
|
2022-07-10 01:06:33 +02:00
|
|
|
run_test(label, (helpers) => {
|
2023-12-14 23:51:33 +01:00
|
|
|
$("#draft_overlay").css = noop;
|
2022-04-10 02:16:59 +02:00
|
|
|
window.localStorage.clear();
|
2022-07-10 01:06:33 +02:00
|
|
|
f(helpers);
|
2021-03-14 10:30:49 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2024-02-02 20:56:49 +01:00
|
|
|
// There were some buggy drafts that had their topics
|
|
|
|
// renamed to `undefined` in #23238.
|
|
|
|
// TODO/compatibility: The next two tests can be deleted
|
|
|
|
// when we get to delete drafts.fix_drafts_with_undefined_topics.
|
|
|
|
//
|
|
|
|
// This test must run before others, so that
|
|
|
|
// fixed_buggy_drafts is false.
|
|
|
|
test("fix buggy drafts", ({override_rewire}) => {
|
|
|
|
override_rewire(drafts, "set_count", noop);
|
|
|
|
|
|
|
|
const stream_A = {
|
|
|
|
subscribed: false,
|
|
|
|
name: "A",
|
|
|
|
stream_id: 1,
|
|
|
|
};
|
|
|
|
stream_data.add_sub(stream_A);
|
|
|
|
const stream_B = {
|
|
|
|
subscribed: false,
|
|
|
|
name: "B",
|
|
|
|
stream_id: 2,
|
|
|
|
};
|
|
|
|
stream_data.add_sub(stream_B);
|
|
|
|
|
|
|
|
const buggy_draft = {
|
|
|
|
stream_id: stream_B.stream_id,
|
|
|
|
topic: undefined,
|
|
|
|
type: "stream",
|
|
|
|
content: "Test stream message",
|
|
|
|
updatedAt: Date.now(),
|
|
|
|
};
|
|
|
|
const data = {id1: buggy_draft};
|
|
|
|
const ls = localstorage();
|
|
|
|
ls.set("drafts", data);
|
|
|
|
const draft_model = drafts.draft_model;
|
|
|
|
|
|
|
|
// The draft is fixed in this codepath.
|
|
|
|
drafts.rename_stream_recipient(
|
|
|
|
stream_B.stream_id,
|
|
|
|
"old_topic",
|
|
|
|
stream_A.stream_id,
|
|
|
|
"new_topic",
|
|
|
|
);
|
|
|
|
|
|
|
|
const draft = draft_model.getDraft("id1");
|
|
|
|
assert.equal(draft.stream_id, stream_B.stream_id);
|
|
|
|
assert.equal(draft.topic, "");
|
|
|
|
});
|
|
|
|
|
2024-02-07 08:14:58 +01:00
|
|
|
test("draft_model add", ({override_rewire}) => {
|
2019-11-02 00:06:25 +01:00
|
|
|
const draft_model = drafts.draft_model;
|
|
|
|
const ls = localstorage();
|
2021-02-14 12:55:03 +01:00
|
|
|
assert.equal(ls.get("draft"), undefined);
|
2017-02-22 02:34:05 +01:00
|
|
|
|
2022-03-17 00:31:13 +01:00
|
|
|
const $unread_count = $("<unread-count-stub>");
|
2022-01-25 11:36:19 +01:00
|
|
|
$(".top_left_drafts").set_find_results(".unread_count", $unread_count);
|
2024-02-07 08:14:58 +01:00
|
|
|
override_rewire(drafts, "update_compose_draft_count", noop);
|
2021-07-04 23:17:03 +02:00
|
|
|
|
2024-02-02 00:23:35 +01:00
|
|
|
const id = draft_model.addDraft(draft_1);
|
|
|
|
assert.deepEqual(draft_model.getDraft(id), draft_1);
|
2021-02-14 12:55:03 +01:00
|
|
|
});
|
2017-02-22 02:34:05 +01:00
|
|
|
|
2024-02-07 08:14:58 +01:00
|
|
|
test("draft_model edit", ({override_rewire}) => {
|
2021-02-14 12:55:03 +01:00
|
|
|
const draft_model = drafts.draft_model;
|
|
|
|
const ls = localstorage();
|
|
|
|
assert.equal(ls.get("draft"), undefined);
|
|
|
|
|
2022-03-17 00:31:13 +01:00
|
|
|
const $unread_count = $("<unread-count-stub>");
|
2022-01-25 11:36:19 +01:00
|
|
|
$(".top_left_drafts").set_find_results(".unread_count", $unread_count);
|
2024-02-07 08:14:58 +01:00
|
|
|
override_rewire(drafts, "update_compose_draft_count", noop);
|
2021-07-04 23:17:03 +02:00
|
|
|
|
2024-02-02 00:23:35 +01:00
|
|
|
const id = draft_model.addDraft(draft_1);
|
|
|
|
assert.deepEqual(draft_model.getDraft(id), draft_1);
|
2021-02-14 12:55:03 +01:00
|
|
|
|
2024-02-02 00:23:35 +01:00
|
|
|
draft_model.editDraft(id, draft_2);
|
|
|
|
assert.deepEqual(draft_model.getDraft(id), draft_2);
|
2021-02-14 12:55:03 +01:00
|
|
|
});
|
2017-02-22 02:34:05 +01:00
|
|
|
|
2024-02-07 08:14:58 +01:00
|
|
|
test("draft_model delete", ({override_rewire}) => {
|
2021-02-14 12:55:03 +01:00
|
|
|
const draft_model = drafts.draft_model;
|
|
|
|
const ls = localstorage();
|
|
|
|
assert.equal(ls.get("draft"), undefined);
|
2017-02-22 02:34:05 +01:00
|
|
|
|
2022-03-17 00:31:13 +01:00
|
|
|
const $unread_count = $("<unread-count-stub>");
|
2022-01-25 11:36:19 +01:00
|
|
|
$(".top_left_drafts").set_find_results(".unread_count", $unread_count);
|
2024-02-07 08:14:58 +01:00
|
|
|
override_rewire(drafts, "update_compose_draft_count", noop);
|
2021-07-04 23:17:03 +02:00
|
|
|
|
2024-02-02 00:23:35 +01:00
|
|
|
const id = draft_model.addDraft(draft_1);
|
|
|
|
assert.deepEqual(draft_model.getDraft(id), draft_1);
|
2017-02-22 02:34:05 +01:00
|
|
|
|
2021-02-14 12:55:03 +01:00
|
|
|
draft_model.deleteDraft(id);
|
|
|
|
assert.deepEqual(draft_model.getDraft(id), false);
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|
2017-03-29 08:54:26 +02:00
|
|
|
|
2024-02-02 00:23:35 +01:00
|
|
|
test("snapshot_message", ({override, override_rewire}) => {
|
2024-03-15 21:51:16 +01:00
|
|
|
override(user_pill, "get_user_ids", () => [aaron.user_id]);
|
2022-10-21 00:44:55 +02:00
|
|
|
override_rewire(compose_pm_pill, "set_from_emails", noop);
|
|
|
|
mock_banners();
|
|
|
|
|
|
|
|
$(".narrow_to_compose_recipients").toggleClass = noop;
|
|
|
|
|
2021-02-13 14:07:47 +01:00
|
|
|
let curr_draft;
|
|
|
|
|
2022-08-28 03:48:27 +02:00
|
|
|
function set_compose_state() {
|
|
|
|
compose_state.set_message_type(curr_draft.type);
|
|
|
|
compose_state.message_content(curr_draft.content);
|
2023-05-07 14:45:04 +02:00
|
|
|
if (curr_draft.type === "private") {
|
2023-08-04 23:40:48 +02:00
|
|
|
compose_state.set_compose_recipient_id(compose_recipient.DIRECT_MESSAGE_ID);
|
2023-05-07 14:45:04 +02:00
|
|
|
} else {
|
2023-06-27 01:40:25 +02:00
|
|
|
compose_state.set_stream_id(curr_draft.stream_id);
|
2023-05-07 14:45:04 +02:00
|
|
|
}
|
2022-08-28 03:48:27 +02:00
|
|
|
compose_state.topic(curr_draft.topic);
|
|
|
|
compose_state.private_message_recipient(curr_draft.private_message_recipient);
|
2017-03-29 08:54:26 +02:00
|
|
|
}
|
|
|
|
|
2023-05-07 14:45:04 +02:00
|
|
|
const stream = {
|
|
|
|
stream_id: draft_1.stream_id,
|
2023-08-04 07:36:15 +02:00
|
|
|
name: "stream name",
|
2023-05-07 14:45:04 +02:00
|
|
|
};
|
|
|
|
stream_data.add_sub(stream);
|
2023-06-27 01:40:25 +02:00
|
|
|
compose_state.set_stream_id(stream.stream_id);
|
2023-05-07 14:45:04 +02:00
|
|
|
|
2024-02-02 00:23:35 +01:00
|
|
|
override(Date, "now", () => mock_current_timestamp);
|
|
|
|
|
2021-02-13 14:07:47 +01:00
|
|
|
curr_draft = draft_1;
|
2022-08-28 03:48:27 +02:00
|
|
|
set_compose_state();
|
2017-03-29 08:54:26 +02:00
|
|
|
assert.deepEqual(drafts.snapshot_message(), draft_1);
|
|
|
|
|
2021-02-13 14:07:47 +01:00
|
|
|
curr_draft = draft_2;
|
2022-08-28 03:48:27 +02:00
|
|
|
set_compose_state();
|
2017-03-29 08:54:26 +02:00
|
|
|
assert.deepEqual(drafts.snapshot_message(), draft_2);
|
|
|
|
|
2021-02-13 14:07:47 +01:00
|
|
|
curr_draft = short_msg;
|
2022-08-28 03:48:27 +02:00
|
|
|
set_compose_state();
|
2018-08-21 23:04:30 +02:00
|
|
|
assert.deepEqual(drafts.snapshot_message(), undefined);
|
|
|
|
|
2023-11-02 19:27:34 +01:00
|
|
|
curr_draft = {type: false};
|
2022-08-28 03:48:27 +02:00
|
|
|
set_compose_state();
|
2017-03-29 08:54:26 +02:00
|
|
|
assert.equal(drafts.snapshot_message(), undefined);
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|
2017-06-02 23:12:15 +02:00
|
|
|
|
2022-01-08 10:27:06 +01:00
|
|
|
test("initialize", ({override_rewire}) => {
|
2021-02-23 14:37:26 +01:00
|
|
|
window.addEventListener = (event_name, f) => {
|
2017-06-02 23:12:15 +02:00
|
|
|
assert.equal(event_name, "beforeunload");
|
2019-11-02 00:06:25 +01:00
|
|
|
let called = false;
|
2022-01-08 10:27:06 +01:00
|
|
|
override_rewire(drafts, "update_draft", () => {
|
2020-07-15 00:34:28 +02:00
|
|
|
called = true;
|
2024-03-16 00:57:19 +01:00
|
|
|
return 100;
|
2021-02-28 00:37:57 +01:00
|
|
|
});
|
2017-06-02 23:12:15 +02:00
|
|
|
f();
|
2021-06-10 08:32:54 +02:00
|
|
|
assert.ok(called);
|
2017-06-02 23:12:15 +02:00
|
|
|
};
|
|
|
|
|
2022-03-17 00:31:13 +01:00
|
|
|
const $unread_count = $("<unread-count-stub>");
|
2022-01-25 11:36:19 +01:00
|
|
|
$(".top_left_drafts").set_find_results(".unread_count", $unread_count);
|
2021-07-04 23:17:03 +02:00
|
|
|
|
2017-06-02 23:12:15 +02:00
|
|
|
drafts.initialize();
|
2024-04-17 02:17:26 +02:00
|
|
|
drafts.initialize_ui();
|
2023-10-06 01:19:21 +02:00
|
|
|
drafts_overlay_ui.initialize();
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|
2018-02-15 17:38:31 +01:00
|
|
|
|
2024-02-07 08:14:58 +01:00
|
|
|
test("remove_old_drafts", ({override_rewire}) => {
|
2019-11-02 00:06:25 +01:00
|
|
|
const draft_3 = {
|
2022-09-28 21:35:43 +02:00
|
|
|
topic: "topic",
|
2018-02-15 17:38:31 +01:00
|
|
|
type: "stream",
|
2021-05-10 07:02:14 +02:00
|
|
|
content: "Test stream message",
|
2018-02-15 17:38:31 +01:00
|
|
|
updatedAt: Date.now(),
|
2024-03-16 00:57:19 +01:00
|
|
|
is_sending_saving: false,
|
2024-03-30 04:59:19 +01:00
|
|
|
drafts_version: 1,
|
2018-02-15 17:38:31 +01:00
|
|
|
};
|
2019-11-02 00:06:25 +01:00
|
|
|
const draft_4 = {
|
2018-02-15 17:38:31 +01:00
|
|
|
private_message_recipient: "aaron@zulip.com",
|
|
|
|
reply_to: "aaron@zulip.com",
|
|
|
|
type: "private",
|
2023-06-16 17:37:19 +02:00
|
|
|
content: "Test direct message",
|
2018-02-15 17:38:31 +01:00
|
|
|
updatedAt: new Date().setDate(-30),
|
2024-03-16 00:57:19 +01:00
|
|
|
is_sending_saving: false,
|
2024-03-30 04:59:19 +01:00
|
|
|
drafts_version: 1,
|
2018-02-15 17:38:31 +01:00
|
|
|
};
|
2019-11-02 00:06:25 +01:00
|
|
|
const draft_model = drafts.draft_model;
|
|
|
|
const ls = localstorage();
|
|
|
|
const data = {id3: draft_3, id4: draft_4};
|
2018-02-15 17:38:31 +01:00
|
|
|
ls.set("drafts", data);
|
|
|
|
assert.deepEqual(draft_model.get(), data);
|
|
|
|
|
2022-03-17 00:31:13 +01:00
|
|
|
const $unread_count = $("<unread-count-stub>");
|
2022-01-25 11:36:19 +01:00
|
|
|
$(".top_left_drafts").set_find_results(".unread_count", $unread_count);
|
2024-02-07 08:14:58 +01:00
|
|
|
override_rewire(drafts, "update_compose_draft_count", noop);
|
2021-07-04 23:17:03 +02:00
|
|
|
|
2018-02-15 17:38:31 +01:00
|
|
|
drafts.remove_old_drafts();
|
|
|
|
assert.deepEqual(draft_model.get(), {id3: draft_3});
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|
2018-03-11 22:03:42 +01:00
|
|
|
|
2022-08-28 03:48:27 +02:00
|
|
|
test("update_draft", ({override, override_rewire}) => {
|
2024-01-07 23:28:42 +01:00
|
|
|
compose_state.set_message_type(undefined);
|
2021-11-30 19:36:27 +01:00
|
|
|
let draft_id = drafts.update_draft();
|
|
|
|
assert.equal(draft_id, undefined);
|
|
|
|
|
2022-08-28 03:48:27 +02:00
|
|
|
override_rewire(compose_pm_pill, "set_from_emails", noop);
|
2024-03-15 21:51:16 +01:00
|
|
|
override(user_pill, "get_user_ids", () => [aaron.user_id]);
|
2022-08-28 03:48:27 +02:00
|
|
|
compose_state.set_message_type("private");
|
|
|
|
compose_state.message_content("dummy content");
|
|
|
|
compose_state.private_message_recipient(aaron.email);
|
2021-11-30 19:36:27 +01:00
|
|
|
|
2022-01-25 11:36:19 +01:00
|
|
|
const $container = $(".top_left_drafts");
|
|
|
|
const $child = $(".unread_count");
|
|
|
|
$container.set_find_results(".unread_count", $child);
|
2024-02-07 08:14:58 +01:00
|
|
|
override_rewire(drafts, "update_compose_draft_count", noop);
|
2021-11-30 19:36:27 +01:00
|
|
|
|
|
|
|
tippy_args = {
|
|
|
|
content: "translated: Saved as draft",
|
|
|
|
arrow: true,
|
|
|
|
placement: "right",
|
|
|
|
};
|
|
|
|
tippy_show_called = false;
|
|
|
|
tippy_destroy_called = false;
|
|
|
|
|
|
|
|
override(Date, "now", () => 5);
|
|
|
|
override(Math, "random", () => 2);
|
|
|
|
draft_id = drafts.update_draft();
|
2021-11-30 17:52:16 +01:00
|
|
|
assert.equal(draft_id, "5-2");
|
2021-11-30 19:36:27 +01:00
|
|
|
assert.ok(tippy_show_called);
|
|
|
|
assert.ok(tippy_destroy_called);
|
|
|
|
|
|
|
|
override(Date, "now", () => 6);
|
|
|
|
|
2022-08-28 03:48:27 +02:00
|
|
|
compose_state.message_content("dummy content edited once");
|
2021-11-30 19:36:27 +01:00
|
|
|
tippy_show_called = false;
|
|
|
|
tippy_destroy_called = false;
|
|
|
|
draft_id = drafts.update_draft();
|
2021-11-30 17:52:16 +01:00
|
|
|
assert.equal(draft_id, "5-2");
|
2021-11-30 19:36:27 +01:00
|
|
|
assert.ok(tippy_show_called);
|
|
|
|
assert.ok(tippy_destroy_called);
|
|
|
|
|
|
|
|
override(Date, "now", () => 7);
|
|
|
|
|
2021-11-30 17:52:16 +01:00
|
|
|
// message contents not edited
|
2021-11-30 19:36:27 +01:00
|
|
|
tippy_show_called = false;
|
|
|
|
tippy_destroy_called = false;
|
2021-11-30 17:52:16 +01:00
|
|
|
draft_id = drafts.update_draft();
|
|
|
|
assert.equal(draft_id, "5-2");
|
2021-11-30 19:36:27 +01:00
|
|
|
assert.ok(!tippy_show_called);
|
|
|
|
assert.ok(!tippy_destroy_called);
|
2021-11-30 17:52:16 +01:00
|
|
|
|
|
|
|
override(Date, "now", () => 8);
|
|
|
|
|
2022-08-28 03:48:27 +02:00
|
|
|
compose_state.message_content("dummy content edited a second time");
|
2021-11-30 17:52:16 +01:00
|
|
|
tippy_show_called = false;
|
|
|
|
tippy_destroy_called = false;
|
|
|
|
draft_id = drafts.update_draft({no_notify: true});
|
2021-11-30 19:36:27 +01:00
|
|
|
assert.equal(draft_id, "5-2");
|
2021-11-30 17:52:16 +01:00
|
|
|
assert.ok(!tippy_show_called);
|
|
|
|
assert.ok(!tippy_destroy_called);
|
2021-11-30 19:36:27 +01:00
|
|
|
});
|
|
|
|
|
2022-10-14 02:18:56 +02:00
|
|
|
test("rename_stream_recipient", ({override_rewire}) => {
|
|
|
|
override_rewire(drafts, "set_count", noop);
|
2024-02-07 08:14:58 +01:00
|
|
|
override_rewire(drafts, "update_compose_draft_count", noop);
|
2022-10-14 02:18:56 +02:00
|
|
|
|
|
|
|
const stream_A = {
|
|
|
|
subscribed: false,
|
|
|
|
name: "A",
|
|
|
|
stream_id: 1,
|
|
|
|
};
|
|
|
|
stream_data.add_sub(stream_A);
|
|
|
|
const stream_B = {
|
|
|
|
subscribed: false,
|
|
|
|
name: "B",
|
|
|
|
stream_id: 2,
|
|
|
|
};
|
|
|
|
stream_data.add_sub(stream_B);
|
|
|
|
|
|
|
|
const draft_1 = {
|
|
|
|
stream_id: stream_A.stream_id,
|
|
|
|
topic: "a",
|
|
|
|
type: "stream",
|
|
|
|
content: "Test stream message",
|
|
|
|
updatedAt: Date.now(),
|
|
|
|
};
|
|
|
|
const draft_2 = {
|
|
|
|
stream_id: stream_A.stream_id,
|
|
|
|
topic: "b",
|
|
|
|
type: "stream",
|
|
|
|
content: "Test stream message",
|
|
|
|
updatedAt: Date.now(),
|
|
|
|
};
|
|
|
|
const draft_3 = {
|
|
|
|
stream_id: stream_B.stream_id,
|
|
|
|
topic: "a",
|
|
|
|
type: "stream",
|
|
|
|
content: "Test stream message",
|
|
|
|
updatedAt: Date.now(),
|
|
|
|
};
|
|
|
|
const draft_4 = {
|
|
|
|
stream_id: stream_B.stream_id,
|
|
|
|
topic: "c",
|
|
|
|
type: "stream",
|
|
|
|
content: "Test stream message",
|
|
|
|
updatedAt: Date.now(),
|
|
|
|
};
|
|
|
|
const data = {id1: draft_1, id2: draft_2, id3: draft_3, id4: draft_4};
|
|
|
|
const ls = localstorage();
|
|
|
|
ls.set("drafts", data);
|
|
|
|
|
|
|
|
const draft_model = drafts.draft_model;
|
2023-08-04 07:36:15 +02:00
|
|
|
function assert_draft(draft_id, stream_id, topic_name) {
|
2022-10-14 02:18:56 +02:00
|
|
|
const draft = draft_model.getDraft(draft_id);
|
|
|
|
assert.equal(draft.topic, topic_name);
|
2023-08-04 07:36:15 +02:00
|
|
|
assert.equal(draft.stream_id, stream_id);
|
2022-10-14 02:18:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// There are no drafts in B>b, so moving messages from there doesn't change drafts
|
|
|
|
drafts.rename_stream_recipient(stream_B.stream_id, "b", undefined, "c");
|
2023-08-04 07:36:15 +02:00
|
|
|
assert_draft("id1", stream_A.stream_id, "a");
|
|
|
|
assert_draft("id2", stream_A.stream_id, "b");
|
|
|
|
assert_draft("id3", stream_B.stream_id, "a");
|
|
|
|
assert_draft("id4", stream_B.stream_id, "c");
|
2022-10-14 02:18:56 +02:00
|
|
|
|
|
|
|
// Update with both stream and topic changes Bc -> Aa
|
|
|
|
drafts.rename_stream_recipient(stream_B.stream_id, "c", stream_A.stream_id, "a");
|
2023-08-04 07:36:15 +02:00
|
|
|
assert_draft("id1", stream_A.stream_id, "a");
|
|
|
|
assert_draft("id2", stream_A.stream_id, "b");
|
|
|
|
assert_draft("id3", stream_B.stream_id, "a");
|
|
|
|
assert_draft("id4", stream_A.stream_id, "a");
|
2022-10-14 02:18:56 +02:00
|
|
|
|
|
|
|
// Update with only stream change Aa -> Ba
|
|
|
|
drafts.rename_stream_recipient(stream_A.stream_id, "a", stream_B.stream_id, undefined);
|
2023-08-04 07:36:15 +02:00
|
|
|
assert_draft("id1", stream_B.stream_id, "a");
|
|
|
|
assert_draft("id2", stream_A.stream_id, "b");
|
|
|
|
assert_draft("id3", stream_B.stream_id, "a");
|
|
|
|
assert_draft("id4", stream_B.stream_id, "a");
|
2022-10-14 02:18:56 +02:00
|
|
|
|
|
|
|
// Update with only topic change, affecting three messages
|
|
|
|
drafts.rename_stream_recipient(stream_B.stream_id, "a", undefined, "e");
|
2023-08-04 07:36:15 +02:00
|
|
|
assert_draft("id1", stream_B.stream_id, "e");
|
|
|
|
assert_draft("id2", stream_A.stream_id, "b");
|
|
|
|
assert_draft("id3", stream_B.stream_id, "e");
|
|
|
|
assert_draft("id4", stream_B.stream_id, "e");
|
2022-10-14 02:18:56 +02:00
|
|
|
});
|
|
|
|
|
2024-02-07 08:14:58 +01:00
|
|
|
test("delete_all_drafts", ({override_rewire}) => {
|
2021-11-12 11:09:12 +01:00
|
|
|
const draft_model = drafts.draft_model;
|
|
|
|
const ls = localstorage();
|
|
|
|
const data = {draft_1, draft_2, short_msg};
|
|
|
|
ls.set("drafts", data);
|
|
|
|
assert.deepEqual(draft_model.get(), data);
|
|
|
|
|
2022-03-17 00:31:13 +01:00
|
|
|
const $unread_count = $("<unread-count-stub>");
|
2022-01-25 11:36:19 +01:00
|
|
|
$(".top_left_drafts").set_find_results(".unread_count", $unread_count);
|
2024-02-07 08:14:58 +01:00
|
|
|
override_rewire(drafts, "update_compose_draft_count", noop);
|
2021-11-12 11:09:12 +01:00
|
|
|
|
|
|
|
drafts.delete_all_drafts();
|
|
|
|
assert.deepEqual(draft_model.get(), {});
|
|
|
|
});
|
|
|
|
|
2024-03-15 21:51:16 +01:00
|
|
|
test("format_drafts", ({override, override_rewire, mock_template}) => {
|
2023-08-04 23:40:48 +02:00
|
|
|
override_rewire(stream_data, "get_color", () => "#FFFFFF");
|
2021-03-14 10:30:49 +01:00
|
|
|
function feb12() {
|
|
|
|
return new Date(1549958107000); // 2/12/2019 07:55:07 AM (UTC+0)
|
|
|
|
}
|
|
|
|
|
|
|
|
function date(offset) {
|
|
|
|
return feb12().setDate(offset);
|
|
|
|
}
|
|
|
|
|
|
|
|
const draft_1 = {
|
|
|
|
topic: "topic",
|
|
|
|
type: "stream",
|
2021-05-10 07:02:14 +02:00
|
|
|
content: "Test stream message",
|
2020-06-06 23:57:20 +02:00
|
|
|
stream_id: 30,
|
2021-03-14 10:30:49 +01:00
|
|
|
updatedAt: feb12().getTime(),
|
2024-03-16 00:57:19 +01:00
|
|
|
is_sending_saving: false,
|
2024-03-30 04:59:19 +01:00
|
|
|
drafts_version: 1,
|
2021-03-14 10:30:49 +01:00
|
|
|
};
|
|
|
|
const draft_2 = {
|
|
|
|
private_message_recipient: "aaron@zulip.com",
|
|
|
|
reply_to: "aaron@zulip.com",
|
|
|
|
type: "private",
|
2023-06-16 17:37:19 +02:00
|
|
|
content: "Test direct message",
|
2021-03-14 10:30:49 +01:00
|
|
|
updatedAt: date(-1),
|
2024-03-16 00:57:19 +01:00
|
|
|
is_sending_saving: false,
|
2024-03-30 04:59:19 +01:00
|
|
|
drafts_version: 1,
|
2021-03-14 10:30:49 +01:00
|
|
|
};
|
2019-11-02 00:06:25 +01:00
|
|
|
const draft_3 = {
|
2022-09-28 21:35:43 +02:00
|
|
|
topic: "topic",
|
2018-03-11 22:03:42 +01:00
|
|
|
type: "stream",
|
2023-08-04 07:36:15 +02:00
|
|
|
stream_id: 40,
|
2021-05-10 07:02:14 +02:00
|
|
|
content: "Test stream message 2",
|
2021-03-14 10:30:49 +01:00
|
|
|
updatedAt: date(-10),
|
2024-03-16 00:57:19 +01:00
|
|
|
is_sending_saving: false,
|
2024-03-30 04:59:19 +01:00
|
|
|
drafts_version: 1,
|
2018-03-11 22:03:42 +01:00
|
|
|
};
|
2019-11-02 00:06:25 +01:00
|
|
|
const draft_4 = {
|
2018-03-11 22:03:42 +01:00
|
|
|
private_message_recipient: "aaron@zulip.com",
|
|
|
|
reply_to: "iago@zulip.com",
|
|
|
|
type: "private",
|
2023-06-16 17:37:19 +02:00
|
|
|
content: "Test direct message 2",
|
2021-03-14 10:30:49 +01:00
|
|
|
updatedAt: date(-5),
|
2024-03-16 00:57:19 +01:00
|
|
|
is_sending_saving: false,
|
2024-03-30 04:59:19 +01:00
|
|
|
drafts_version: 1,
|
2018-03-11 22:03:42 +01:00
|
|
|
};
|
2019-11-02 00:06:25 +01:00
|
|
|
const draft_5 = {
|
2018-03-11 22:03:42 +01:00
|
|
|
private_message_recipient: "aaron@zulip.com",
|
|
|
|
reply_to: "zoe@zulip.com",
|
|
|
|
type: "private",
|
2023-06-16 17:37:19 +02:00
|
|
|
content: "Test direct message 3",
|
2021-03-14 10:30:49 +01:00
|
|
|
updatedAt: date(-2),
|
2024-03-16 00:57:19 +01:00
|
|
|
is_sending_saving: false,
|
2024-03-30 04:59:19 +01:00
|
|
|
drafts_version: 1,
|
2018-03-11 22:03:42 +01:00
|
|
|
};
|
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const expected = [
|
2018-12-16 21:15:32 +01:00
|
|
|
{
|
2020-07-15 01:29:15 +02:00
|
|
|
draft_id: "id1",
|
2018-03-11 22:03:42 +01:00
|
|
|
is_stream: true,
|
2020-10-24 21:24:21 +02:00
|
|
|
stream_name: "stream",
|
2023-04-08 01:39:52 +02:00
|
|
|
stream_id: 30,
|
2023-05-13 08:15:50 +02:00
|
|
|
recipient_bar_color: "#ebebeb",
|
2023-11-02 16:46:04 +01:00
|
|
|
stream_privacy_icon_color: "#9a9a9a",
|
2020-07-15 01:29:15 +02:00
|
|
|
topic: "topic",
|
2021-05-10 07:02:14 +02:00
|
|
|
raw_content: "Test stream message",
|
2023-03-16 19:40:55 +01:00
|
|
|
time_stamp: "7:55 AM",
|
2023-04-08 01:39:52 +02:00
|
|
|
invite_only: undefined,
|
|
|
|
is_web_public: undefined,
|
2018-03-11 22:03:42 +01:00
|
|
|
},
|
2018-12-16 21:15:32 +01:00
|
|
|
{
|
2020-07-15 01:29:15 +02:00
|
|
|
draft_id: "id2",
|
2018-03-11 22:03:42 +01:00
|
|
|
is_stream: false,
|
2022-05-17 03:13:57 +02:00
|
|
|
recipients: "Aaron",
|
2023-06-16 17:37:19 +02:00
|
|
|
raw_content: "Test direct message",
|
2023-01-08 18:08:49 +01:00
|
|
|
time_stamp: "Jan 30",
|
2018-03-11 22:03:42 +01:00
|
|
|
},
|
2018-12-16 21:15:32 +01:00
|
|
|
{
|
2020-07-15 01:29:15 +02:00
|
|
|
draft_id: "id5",
|
2018-03-11 22:03:42 +01:00
|
|
|
is_stream: false,
|
2022-05-17 03:13:57 +02:00
|
|
|
recipients: "Aaron",
|
2023-06-16 17:37:19 +02:00
|
|
|
raw_content: "Test direct message 3",
|
2023-01-08 18:08:49 +01:00
|
|
|
time_stamp: "Jan 29",
|
2018-03-11 22:03:42 +01:00
|
|
|
},
|
2018-12-16 21:15:32 +01:00
|
|
|
{
|
2020-07-15 01:29:15 +02:00
|
|
|
draft_id: "id4",
|
2018-03-11 22:03:42 +01:00
|
|
|
is_stream: false,
|
2022-05-17 03:13:57 +02:00
|
|
|
recipients: "Aaron",
|
2023-06-16 17:37:19 +02:00
|
|
|
raw_content: "Test direct message 2",
|
2023-01-08 18:08:49 +01:00
|
|
|
time_stamp: "Jan 26",
|
2018-03-11 22:03:42 +01:00
|
|
|
},
|
2018-12-16 21:15:32 +01:00
|
|
|
{
|
2020-07-15 01:29:15 +02:00
|
|
|
draft_id: "id3",
|
2018-03-11 22:03:42 +01:00
|
|
|
is_stream: true,
|
2020-10-24 21:24:21 +02:00
|
|
|
stream_name: "stream 2",
|
2023-08-04 07:36:15 +02:00
|
|
|
stream_id: 40,
|
2023-05-13 08:15:50 +02:00
|
|
|
recipient_bar_color: "#ebebeb",
|
2023-11-02 16:46:04 +01:00
|
|
|
stream_privacy_icon_color: "#9a9a9a",
|
2020-07-15 01:29:15 +02:00
|
|
|
topic: "topic",
|
2021-05-10 07:02:14 +02:00
|
|
|
raw_content: "Test stream message 2",
|
2023-01-08 18:08:49 +01:00
|
|
|
time_stamp: "Jan 21",
|
2023-04-08 01:39:52 +02:00
|
|
|
invite_only: false,
|
|
|
|
is_web_public: false,
|
2018-03-11 22:03:42 +01:00
|
|
|
},
|
2018-12-16 21:15:32 +01:00
|
|
|
];
|
2018-03-11 22:03:42 +01:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
$("#drafts_table").append = noop;
|
2018-03-11 22:03:42 +01:00
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const draft_model = drafts.draft_model;
|
|
|
|
const ls = localstorage();
|
2020-07-16 22:40:18 +02:00
|
|
|
const data = {id1: draft_1, id2: draft_2, id3: draft_3, id4: draft_4, id5: draft_5};
|
2018-03-11 22:03:42 +01:00
|
|
|
ls.set("drafts", data);
|
|
|
|
assert.deepEqual(draft_model.get(), data);
|
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const stub_render_now = timerender.render_now;
|
2022-01-08 10:27:06 +01:00
|
|
|
override_rewire(timerender, "render_now", (time) =>
|
|
|
|
stub_render_now(time, new Date(1549958107000)),
|
|
|
|
);
|
2018-03-11 22:03:42 +01:00
|
|
|
|
2023-08-04 23:40:48 +02:00
|
|
|
override_rewire(sub_store, "get", (stream_id) => {
|
2023-08-04 07:36:15 +02:00
|
|
|
assert.ok([30, 40].includes(stream_id));
|
|
|
|
if (stream_id === 30) {
|
|
|
|
return {name: "stream", stream_id};
|
|
|
|
}
|
|
|
|
return {name: "stream 2", stream_id, invite_only: false, is_web_public: false};
|
2023-08-04 23:40:48 +02:00
|
|
|
});
|
2020-06-06 23:57:20 +02:00
|
|
|
|
2024-03-15 21:51:16 +01:00
|
|
|
override(user_pill, "get_user_ids", () => []);
|
2022-08-28 03:48:27 +02:00
|
|
|
compose_state.set_message_type("private");
|
|
|
|
compose_state.private_message_recipient(null);
|
2022-05-17 03:13:57 +02:00
|
|
|
|
2021-06-28 00:41:05 +02:00
|
|
|
mock_template("draft_table_body.hbs", false, (data) => {
|
2022-05-17 03:13:57 +02:00
|
|
|
// Tests formatting and time-sorting of drafts
|
|
|
|
assert.deepEqual(data.narrow_drafts, []);
|
|
|
|
assert.deepEqual(data.other_drafts, expected);
|
2020-07-15 01:29:15 +02:00
|
|
|
return "<draft table stub>";
|
2019-07-11 05:06:20 +02:00
|
|
|
});
|
2018-03-11 22:03:42 +01:00
|
|
|
|
2024-03-15 21:51:16 +01:00
|
|
|
override(messages_overlay_ui, "set_initial_element", noop);
|
2019-04-18 21:11:30 +02:00
|
|
|
|
2023-06-05 21:03:54 +02:00
|
|
|
const $unread_count = $("<unread-count-stub>");
|
|
|
|
$(".top_left_drafts").set_find_results(".unread_count", $unread_count);
|
|
|
|
|
2023-06-09 21:53:24 +02:00
|
|
|
$.create("#drafts_table .overlay-message-row", {children: []});
|
2023-01-24 12:49:04 +01:00
|
|
|
$(".draft-selection-checkbox").filter = () => [];
|
2023-10-06 01:19:21 +02:00
|
|
|
drafts_overlay_ui.launch();
|
2020-06-06 23:57:20 +02:00
|
|
|
|
|
|
|
$.clear_all_elements();
|
2023-06-09 21:53:24 +02:00
|
|
|
$.create("#drafts_table .overlay-message-row", {children: []});
|
2023-12-14 23:51:33 +01:00
|
|
|
$("#draft_overlay").css = noop;
|
2020-06-06 23:57:20 +02:00
|
|
|
|
2023-08-04 23:40:48 +02:00
|
|
|
override_rewire(sub_store, "get", (stream_id) => {
|
2023-08-04 07:36:15 +02:00
|
|
|
assert.ok([30, 40].includes(stream_id));
|
|
|
|
if (stream_id === 30) {
|
|
|
|
return {name: "stream-rename", stream_id};
|
|
|
|
}
|
|
|
|
return {name: "stream 2", stream_id, invite_only: false, is_web_public: false};
|
2023-08-04 23:40:48 +02:00
|
|
|
});
|
2020-06-06 23:57:20 +02:00
|
|
|
|
2020-10-24 21:24:21 +02:00
|
|
|
expected[0].stream_name = "stream-rename";
|
2020-06-06 23:57:20 +02:00
|
|
|
|
2022-01-25 11:36:19 +01:00
|
|
|
$(".top_left_drafts").set_find_results(".unread_count", $unread_count);
|
2021-07-04 23:17:03 +02:00
|
|
|
|
2023-01-24 12:49:04 +01:00
|
|
|
$(".draft-selection-checkbox").filter = () => [];
|
2023-10-06 01:19:21 +02:00
|
|
|
drafts_overlay_ui.launch();
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|
2022-05-17 03:13:57 +02:00
|
|
|
|
2024-03-15 21:51:16 +01:00
|
|
|
test("filter_drafts", ({override, override_rewire, mock_template}) => {
|
2023-08-04 23:40:48 +02:00
|
|
|
override_rewire(stream_data, "get_color", () => "#FFFFFF");
|
2022-05-17 03:13:57 +02:00
|
|
|
function feb12() {
|
|
|
|
return new Date(1549958107000); // 2/12/2019 07:55:07 AM (UTC+0)
|
|
|
|
}
|
|
|
|
|
|
|
|
function date(offset) {
|
|
|
|
return feb12().setDate(offset);
|
|
|
|
}
|
|
|
|
|
|
|
|
const stream_draft_1 = {
|
|
|
|
topic: "topic",
|
|
|
|
type: "stream",
|
|
|
|
content: "Test stream message",
|
|
|
|
stream_id: 30,
|
|
|
|
updatedAt: feb12().getTime(),
|
2024-03-16 00:57:19 +01:00
|
|
|
is_sending_saving: false,
|
2024-03-30 04:59:19 +01:00
|
|
|
drafts_version: 1,
|
2022-05-17 03:13:57 +02:00
|
|
|
};
|
|
|
|
const pm_draft_1 = {
|
|
|
|
private_message_recipient: "aaron@zulip.com",
|
|
|
|
reply_to: "aaron@zulip.com",
|
|
|
|
type: "private",
|
2023-06-16 17:37:19 +02:00
|
|
|
content: "Test direct message",
|
2022-05-17 03:13:57 +02:00
|
|
|
updatedAt: date(-1),
|
2024-03-16 00:57:19 +01:00
|
|
|
is_sending_saving: false,
|
2024-03-30 04:59:19 +01:00
|
|
|
drafts_version: 1,
|
2022-05-17 03:13:57 +02:00
|
|
|
};
|
|
|
|
const stream_draft_2 = {
|
2022-09-28 21:35:43 +02:00
|
|
|
topic: "topic",
|
2022-05-17 03:13:57 +02:00
|
|
|
type: "stream",
|
2023-08-04 07:36:15 +02:00
|
|
|
stream_id: 40,
|
2022-05-17 03:13:57 +02:00
|
|
|
content: "Test stream message 2",
|
|
|
|
updatedAt: date(-10),
|
2024-03-16 00:57:19 +01:00
|
|
|
is_sending_saving: false,
|
2024-03-30 04:59:19 +01:00
|
|
|
drafts_version: 1,
|
2022-05-17 03:13:57 +02:00
|
|
|
};
|
|
|
|
const pm_draft_2 = {
|
|
|
|
private_message_recipient: "aaron@zulip.com",
|
|
|
|
reply_to: "iago@zulip.com",
|
|
|
|
type: "private",
|
2023-06-16 17:37:19 +02:00
|
|
|
content: "Test direct message 2",
|
2022-05-17 03:13:57 +02:00
|
|
|
updatedAt: date(-5),
|
2024-03-16 00:57:19 +01:00
|
|
|
is_sending_saving: false,
|
2024-03-30 04:59:19 +01:00
|
|
|
drafts_version: 1,
|
2022-05-17 03:13:57 +02:00
|
|
|
};
|
|
|
|
const pm_draft_3 = {
|
|
|
|
private_message_recipient: "aaron@zulip.com",
|
|
|
|
reply_to: "zoe@zulip.com",
|
|
|
|
type: "private",
|
2023-06-16 17:37:19 +02:00
|
|
|
content: "Test direct message 3",
|
2022-05-17 03:13:57 +02:00
|
|
|
updatedAt: date(-2),
|
2024-03-16 00:57:19 +01:00
|
|
|
is_sending_saving: false,
|
2024-03-30 04:59:19 +01:00
|
|
|
drafts_version: 1,
|
2022-05-17 03:13:57 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
const expected_pm_drafts = [
|
|
|
|
{
|
|
|
|
draft_id: "id2",
|
|
|
|
is_stream: false,
|
|
|
|
recipients: "Aaron",
|
2023-06-16 17:37:19 +02:00
|
|
|
raw_content: "Test direct message",
|
2023-01-08 18:08:49 +01:00
|
|
|
time_stamp: "Jan 30",
|
2022-05-17 03:13:57 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
draft_id: "id5",
|
|
|
|
is_stream: false,
|
|
|
|
recipients: "Aaron",
|
2023-06-16 17:37:19 +02:00
|
|
|
raw_content: "Test direct message 3",
|
2023-01-08 18:08:49 +01:00
|
|
|
time_stamp: "Jan 29",
|
2022-05-17 03:13:57 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
draft_id: "id4",
|
|
|
|
is_stream: false,
|
|
|
|
recipients: "Aaron",
|
2023-06-16 17:37:19 +02:00
|
|
|
raw_content: "Test direct message 2",
|
2023-01-08 18:08:49 +01:00
|
|
|
time_stamp: "Jan 26",
|
2022-05-17 03:13:57 +02:00
|
|
|
},
|
|
|
|
];
|
|
|
|
|
|
|
|
const expected_other_drafts = [
|
|
|
|
{
|
|
|
|
draft_id: "id1",
|
|
|
|
is_stream: true,
|
|
|
|
stream_name: "stream",
|
2023-04-08 01:39:52 +02:00
|
|
|
stream_id: 30,
|
2023-05-13 08:15:50 +02:00
|
|
|
recipient_bar_color: "#ebebeb",
|
2023-11-02 16:46:04 +01:00
|
|
|
stream_privacy_icon_color: "#9a9a9a",
|
2022-05-17 03:13:57 +02:00
|
|
|
topic: "topic",
|
|
|
|
raw_content: "Test stream message",
|
2023-03-16 19:40:55 +01:00
|
|
|
time_stamp: "7:55 AM",
|
2023-04-08 01:39:52 +02:00
|
|
|
invite_only: false,
|
|
|
|
is_web_public: false,
|
2022-05-17 03:13:57 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
draft_id: "id3",
|
|
|
|
is_stream: true,
|
|
|
|
stream_name: "stream 2",
|
2023-08-04 07:36:15 +02:00
|
|
|
stream_id: 40,
|
2023-05-13 08:15:50 +02:00
|
|
|
recipient_bar_color: "#ebebeb",
|
2023-11-02 16:46:04 +01:00
|
|
|
stream_privacy_icon_color: "#9a9a9a",
|
2022-05-17 03:13:57 +02:00
|
|
|
topic: "topic",
|
|
|
|
raw_content: "Test stream message 2",
|
2023-01-08 18:08:49 +01:00
|
|
|
time_stamp: "Jan 21",
|
2023-04-08 01:39:52 +02:00
|
|
|
invite_only: false,
|
|
|
|
is_web_public: false,
|
2022-05-17 03:13:57 +02:00
|
|
|
},
|
|
|
|
];
|
|
|
|
|
|
|
|
$("#drafts_table").append = noop;
|
|
|
|
|
|
|
|
const draft_model = drafts.draft_model;
|
|
|
|
const ls = localstorage();
|
|
|
|
const data = {
|
|
|
|
id1: stream_draft_1,
|
|
|
|
id2: pm_draft_1,
|
|
|
|
id3: stream_draft_2,
|
|
|
|
id4: pm_draft_2,
|
|
|
|
id5: pm_draft_3,
|
|
|
|
};
|
|
|
|
ls.set("drafts", data);
|
|
|
|
assert.deepEqual(draft_model.get(), data);
|
|
|
|
|
|
|
|
const stub_render_now = timerender.render_now;
|
|
|
|
override_rewire(timerender, "render_now", (time) =>
|
|
|
|
stub_render_now(time, new Date(1549958107000)),
|
|
|
|
);
|
|
|
|
|
2023-08-04 23:40:48 +02:00
|
|
|
override_rewire(sub_store, "get", (stream_id) => {
|
2023-08-04 07:36:15 +02:00
|
|
|
assert.ok([30, 40].includes(stream_id));
|
|
|
|
if (stream_id === 30) {
|
|
|
|
return {name: "stream", stream_id, invite_only: false, is_web_public: false};
|
|
|
|
}
|
|
|
|
return {name: "stream 2", stream_id, invite_only: false, is_web_public: false};
|
2023-08-04 23:40:48 +02:00
|
|
|
});
|
2022-05-17 03:13:57 +02:00
|
|
|
|
|
|
|
mock_template("draft_table_body.hbs", false, (data) => {
|
|
|
|
// Tests splitting up drafts by current narrow.
|
|
|
|
assert.deepEqual(data.narrow_drafts, expected_pm_drafts);
|
|
|
|
assert.deepEqual(data.other_drafts, expected_other_drafts);
|
|
|
|
return "<draft table stub>";
|
|
|
|
});
|
|
|
|
|
2024-03-15 21:51:16 +01:00
|
|
|
override(messages_overlay_ui, "set_initial_element", noop);
|
2022-05-17 03:13:57 +02:00
|
|
|
|
2023-06-05 21:03:54 +02:00
|
|
|
const $unread_count = $("<unread-count-stub>");
|
|
|
|
$(".top_left_drafts").set_find_results(".unread_count", $unread_count);
|
|
|
|
|
2024-03-15 21:51:16 +01:00
|
|
|
override(user_pill, "get_user_ids", () => [aaron.user_id]);
|
2022-08-28 03:48:27 +02:00
|
|
|
override_rewire(compose_pm_pill, "set_from_emails", noop);
|
|
|
|
compose_state.set_message_type("private");
|
|
|
|
compose_state.private_message_recipient(aaron.email);
|
2022-05-17 03:13:57 +02:00
|
|
|
|
2023-06-09 21:53:24 +02:00
|
|
|
$.create("#drafts_table .overlay-message-row", {children: []});
|
2023-01-24 12:49:04 +01:00
|
|
|
$(".draft-selection-checkbox").filter = () => [];
|
2023-10-06 01:19:21 +02:00
|
|
|
drafts_overlay_ui.launch();
|
2022-05-17 03:13:57 +02:00
|
|
|
});
|