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_stream_header_colorblock} = require("./lib/compose");
|
|
|
|
const {mock_banners} = require("./lib/compose_banner");
|
2023-02-22 23:04:10 +01:00
|
|
|
const {mock_esm, set_global, zrequire, with_overrides} = require("./lib/namespace");
|
|
|
|
const {run_test} = require("./lib/test");
|
|
|
|
const $ = require("./lib/zjquery");
|
|
|
|
const {user_settings} = require("./lib/zpage_params");
|
2017-02-22 02:34:05 +01:00
|
|
|
|
2022-11-02 01:10:11 +01:00
|
|
|
const blueslip = zrequire("blueslip");
|
2022-08-28 03:48:27 +02:00
|
|
|
const compose_pm_pill = zrequire("compose_pm_pill");
|
|
|
|
const user_pill = zrequire("user_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-02-23 14:37:26 +01:00
|
|
|
const noop = () => {};
|
2018-03-11 22:03:42 +01:00
|
|
|
|
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", {
|
2021-03-06 17:37:51 +01:00
|
|
|
apply_markdown: noop,
|
|
|
|
});
|
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");
|
2023-05-15 07:25:44 +02:00
|
|
|
const messages_overlay_ui = zrequire("messages_overlay_ui");
|
2020-12-01 23:21:38 +01:00
|
|
|
const timerender = zrequire("timerender");
|
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const draft_1 = {
|
2020-06-06 23:57:20 +02:00
|
|
|
stream_id: 30,
|
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",
|
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",
|
2017-02-22 02:34:05 +01:00
|
|
|
};
|
2019-11-02 00:06:25 +01:00
|
|
|
const short_msg = {
|
2023-06-27 01:40:25 +02:00
|
|
|
stream_id: 30,
|
2022-09-28 21:35:43 +02:00
|
|
|
topic: "topic",
|
2018-08-21 23:04:30 +02:00
|
|
|
type: "stream",
|
|
|
|
content: "a",
|
|
|
|
};
|
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) => {
|
2021-06-04 19:27:45 +02:00
|
|
|
$("#draft_overlay").css = () => {};
|
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
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-06-16 14:38:37 +02:00
|
|
|
test("draft_model add", ({override}) => {
|
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);
|
2021-07-04 23:17:03 +02:00
|
|
|
|
2021-02-14 12:55:03 +01:00
|
|
|
override(Date, "now", () => 1);
|
|
|
|
const expected = {...draft_1};
|
|
|
|
expected.updatedAt = 1;
|
|
|
|
const id = draft_model.addDraft({...draft_1});
|
|
|
|
assert.deepEqual(draft_model.getDraft(id), expected);
|
|
|
|
});
|
2017-02-22 02:34:05 +01:00
|
|
|
|
2021-03-14 10:30:49 +01:00
|
|
|
test("draft_model edit", () => {
|
2021-02-14 12:55:03 +01:00
|
|
|
const draft_model = drafts.draft_model;
|
|
|
|
const ls = localstorage();
|
|
|
|
assert.equal(ls.get("draft"), undefined);
|
|
|
|
let id;
|
|
|
|
|
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
|
|
|
|
2022-01-08 09:54:05 +01:00
|
|
|
with_overrides(({override}) => {
|
2021-02-14 12:55:03 +01:00
|
|
|
override(Date, "now", () => 1);
|
|
|
|
const expected = {...draft_1};
|
|
|
|
expected.updatedAt = 1;
|
|
|
|
id = draft_model.addDraft({...draft_1});
|
|
|
|
assert.deepEqual(draft_model.getDraft(id), expected);
|
|
|
|
});
|
|
|
|
|
2022-01-08 09:54:05 +01:00
|
|
|
with_overrides(({override}) => {
|
2021-02-14 12:55:03 +01:00
|
|
|
override(Date, "now", () => 2);
|
|
|
|
const expected = {...draft_2};
|
|
|
|
expected.updatedAt = 2;
|
|
|
|
draft_model.editDraft(id, {...draft_2});
|
|
|
|
assert.deepEqual(draft_model.getDraft(id), expected);
|
|
|
|
});
|
|
|
|
});
|
2017-02-22 02:34:05 +01:00
|
|
|
|
2021-06-16 14:38:37 +02:00
|
|
|
test("draft_model delete", ({override}) => {
|
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);
|
2021-07-04 23:17:03 +02:00
|
|
|
|
2021-02-14 12:55:03 +01:00
|
|
|
override(Date, "now", () => 1);
|
|
|
|
const expected = {...draft_1};
|
|
|
|
expected.updatedAt = 1;
|
|
|
|
const id = draft_model.addDraft({...draft_1});
|
|
|
|
assert.deepEqual(draft_model.getDraft(id), expected);
|
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
|
|
|
|
2022-08-28 03:48:27 +02:00
|
|
|
test("snapshot_message", ({override_rewire}) => {
|
2022-10-21 00:44:55 +02:00
|
|
|
override_rewire(user_pill, "get_user_ids", () => [aaron.user_id]);
|
|
|
|
override_rewire(compose_pm_pill, "set_from_emails", noop);
|
|
|
|
mock_banners();
|
|
|
|
|
|
|
|
$(".narrow_to_compose_recipients").toggleClass = noop;
|
|
|
|
|
|
|
|
mock_stream_header_colorblock();
|
2022-08-28 03:48:27 +02:00
|
|
|
|
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
|
|
|
|
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);
|
|
|
|
|
2021-02-13 14:07:47 +01:00
|
|
|
curr_draft = {};
|
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;
|
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();
|
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
|
|
|
|
2021-03-14 10:30:49 +01:00
|
|
|
test("remove_old_drafts", () => {
|
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(),
|
|
|
|
};
|
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),
|
|
|
|
};
|
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);
|
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}) => {
|
|
|
|
compose_state.set_message_type(null);
|
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);
|
|
|
|
override_rewire(user_pill, "get_user_ids", () => [aaron.user_id]);
|
|
|
|
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);
|
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);
|
|
|
|
|
|
|
|
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
|
|
|
});
|
|
|
|
|
2022-11-02 01:10:11 +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
|
2022-11-02 01:13:42 +01:00
|
|
|
// when we get to delete drafts.fix_drafts_with_undefined_topics.
|
2022-11-02 01:10:11 +01:00
|
|
|
test("catch_buggy_draft_error", () => {
|
|
|
|
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;
|
|
|
|
|
|
|
|
// An error is logged but the draft isn't fixed in this codepath.
|
2023-04-24 15:57:45 +02:00
|
|
|
blueslip.expect("error", "Cannot compare strings; at least one value is undefined");
|
2022-11-02 01:10:11 +01:00
|
|
|
drafts.rename_stream_recipient(
|
|
|
|
stream_B.stream_id,
|
|
|
|
"old_topic",
|
|
|
|
stream_A.stream_id,
|
|
|
|
"new_topic",
|
|
|
|
);
|
|
|
|
const draft = draft_model.getDraft("id1");
|
2023-08-04 07:36:15 +02:00
|
|
|
assert.equal(draft.stream_id, stream_B.stream_id);
|
2022-11-02 01:10:11 +01:00
|
|
|
assert.equal(draft.topic, undefined);
|
|
|
|
});
|
|
|
|
|
2022-11-02 01:13:42 +01:00
|
|
|
test("fix_buggy_draft", ({override_rewire}) => {
|
|
|
|
override_rewire(drafts, "set_count", noop);
|
|
|
|
|
|
|
|
const buggy_draft = {
|
|
|
|
stream_id: 1,
|
|
|
|
// This is the bug: topic never be undefined for a stream
|
|
|
|
// message draft.
|
|
|
|
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;
|
|
|
|
|
|
|
|
drafts.fix_drafts_with_undefined_topics();
|
|
|
|
const draft = draft_model.getDraft("id1");
|
2023-08-04 07:36:15 +02:00
|
|
|
assert.equal(draft.stream_id, buggy_draft.stream_id);
|
2022-11-02 01:13:42 +01:00
|
|
|
assert.equal(draft.topic, "");
|
|
|
|
});
|
|
|
|
|
2021-11-12 11:09:12 +01:00
|
|
|
test("delete_all_drafts", () => {
|
|
|
|
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);
|
2021-11-12 11:09:12 +01:00
|
|
|
|
|
|
|
drafts.delete_all_drafts();
|
|
|
|
assert.deepEqual(draft_model.get(), {});
|
|
|
|
});
|
|
|
|
|
2022-08-28 03:48:27 +02:00
|
|
|
test("format_drafts", ({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(),
|
|
|
|
};
|
|
|
|
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),
|
|
|
|
};
|
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),
|
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),
|
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),
|
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-04-08 01:39:52 +02:00
|
|
|
stream_privacy_icon_color: "#b9b9b9",
|
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-04-08 01:39:52 +02:00
|
|
|
stream_privacy_icon_color: "#b9b9b9",
|
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
|
|
|
|
2022-08-28 03:48:27 +02:00
|
|
|
override_rewire(user_pill, "get_user_ids", () => []);
|
|
|
|
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
|
|
|
|
2023-05-15 07:25:44 +02:00
|
|
|
override_rewire(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: []});
|
2020-06-06 23:57:20 +02:00
|
|
|
$("#draft_overlay").css = () => {};
|
|
|
|
|
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
|
|
|
|
2022-08-28 03:48:27 +02:00
|
|
|
test("filter_drafts", ({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(),
|
|
|
|
};
|
|
|
|
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),
|
|
|
|
};
|
|
|
|
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),
|
|
|
|
};
|
|
|
|
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),
|
|
|
|
};
|
|
|
|
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),
|
|
|
|
};
|
|
|
|
|
|
|
|
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-04-08 01:39:52 +02:00
|
|
|
stream_privacy_icon_color: "#b9b9b9",
|
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-04-08 01:39:52 +02:00
|
|
|
stream_privacy_icon_color: "#b9b9b9",
|
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>";
|
|
|
|
});
|
|
|
|
|
2023-05-15 07:25:44 +02:00
|
|
|
override_rewire(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);
|
|
|
|
|
2022-08-28 03:48:27 +02:00
|
|
|
override_rewire(user_pill, "get_user_ids", () => [aaron.user_id]);
|
|
|
|
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
|
|
|
});
|