From 1d0e5b1b4ee9ac16a16ba7301f579fc5e8295c68 Mon Sep 17 00:00:00 2001 From: evykassirer Date: Sat, 30 Sep 2023 13:37:10 -0700 Subject: [PATCH] compose fade: Add test for want_normal_display. --- web/tests/compose_fade.test.js | 49 ++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/web/tests/compose_fade.test.js b/web/tests/compose_fade.test.js index 51363cb369..92e75114c7 100644 --- a/web/tests/compose_fade.test.js +++ b/web/tests/compose_fade.test.js @@ -91,3 +91,52 @@ run_test("set_focused_recipient", ({override_rewire}) => { assert.ok(!compose_fade_helper.should_fade_message(good_msg)); assert.ok(compose_fade_helper.should_fade_message(bad_msg)); }); + +run_test("want_normal_display", () => { + const stream_id = 110; + const sub = { + stream_id, + name: "display testing", + subscribed: true, + }; + + stream_data.clear_subscriptions(); + + // No focused recipient. + compose_fade_helper.set_focused_recipient(undefined); + assert.ok(compose_fade_helper.want_normal_display()); + + // Focused recipient is a sub that doesn't exist. + compose_fade_helper.set_focused_recipient({ + type: "stream", + stream_id, + topic: "", + }); + assert.ok(compose_fade_helper.want_normal_display()); + + // Focused recipient is a valid stream with no topic set + stream_data.add_sub(sub); + assert.ok(compose_fade_helper.want_normal_display()); + + // If we're focused to a topic, then we do want to fade. + compose_fade_helper.set_focused_recipient({ + type: "stream", + stream_id, + topic: "lunch", + }); + assert.ok(!compose_fade_helper.want_normal_display()); + + // Private message with no recipient. + compose_fade_helper.set_focused_recipient({ + type: "private", + reply_to: "", + }); + assert.ok(compose_fade_helper.want_normal_display()); + + // Private message with a recipient. + compose_fade_helper.set_focused_recipient({ + type: "private", + reply_to: "hello@zulip.com", + }); + assert.ok(!compose_fade_helper.want_normal_display()); +});