Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

drafts_tests: Add node test coverage to drafts.update_draft().

YashRE426dd0daede053
diff --git a/frontend_tests/node_tests/drafts.js b/frontend_tests/node_tests/drafts.js
index 8faa223aef3..69651c40571 100644
--- a/frontend_tests/node_tests/drafts.js
+++ b/frontend_tests/node_tests/drafts.js
@@ -24,6 +24,11 @@ const localStorage = set_global("localStorage", {
ls_container.clear();
},
});
+const setTimeout_delay = 3000;
+set_global("setTimeout", (f, delay) => {
+ assert.equal(delay, setTimeout_delay);
+ f();
+});
const compose_state = mock_esm("../../static/js/compose_state");
mock_esm("../../static/js/markdown", {
apply_markdown: noop,
@@ -37,6 +42,26 @@ mock_esm("../../static/js/stream_data", {
return {stream_id: 30};
},
});
+const tippy_sel = ".top_left_drafts .unread_count";
+let tippy_args;
+let tippy_show_called;
+let tippy_destroy_called;
+mock_esm("tippy.js", {
+ default: (sel, opts) => {
+ assert.equal(sel, tippy_sel);
+ assert.deepEqual(opts, tippy_args);
+ return [
+ {
+ show: () => {
+ tippy_show_called = true;
+ },
+ destroy: () => {
+ tippy_destroy_called = true;
+ },
+ },
+ ];
+ },
+});
const sub_store = mock_esm("../../static/js/sub_store");
user_settings.twenty_four_hour_time = false;
@@ -221,6 +246,54 @@ test("remove_old_drafts", () => {
assert.deepEqual(draft_model.get(), {id3: draft_3});
});
+test("update_draft", ({override}) => {
+ override(compose_state, "composing", () => false);
+ let draft_id = drafts.update_draft();
+ assert.equal(draft_id, undefined);
+
+ override(compose_state, "composing", () => true);
+ override(compose_state, "message_content", () => "dummy content");
+ override(compose_state, "get_message_type", () => "private");
+ override(compose_state, "private_message_recipient", () => "[email protected]");
+
+ const container = $(".top_left_drafts");
+ const child = $(".unread_count");
+ container.set_find_results(".unread_count", child);
+
+ 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();
+ assert.ok(tippy_show_called);
+ assert.ok(tippy_destroy_called);
+ assert.equal(draft_id, "5-2");
+
+ override(Date, "now", () => 6);
+
+ tippy_show_called = false;
+ tippy_destroy_called = false;
+ draft_id = drafts.update_draft();
+ assert.ok(tippy_show_called);
+ assert.ok(tippy_destroy_called);
+ assert.equal(draft_id, "5-2");
+
+ override(Date, "now", () => 7);
+
+ tippy_show_called = false;
+ tippy_destroy_called = false;
+ draft_id = drafts.update_draft({no_notify: true});
+ assert.ok(!tippy_show_called);
+ assert.ok(!tippy_destroy_called);
+ assert.equal(draft_id, "5-2");
+});
+
test("delete_all_drafts", () => {
const draft_model = drafts.draft_model;
const ls = localstorage();