2021-03-05 16:57:23 +01:00
|
|
|
"use strict";
|
|
|
|
|
|
|
|
const {strict: assert} = require("assert");
|
|
|
|
|
2022-10-21 00:44:55 +02:00
|
|
|
const {mock_stream_header_colorblock} = require("./lib/compose");
|
2023-02-22 23:04:10 +01:00
|
|
|
const {mock_esm, zrequire} = require("./lib/namespace");
|
|
|
|
const {run_test} = require("./lib/test");
|
2022-10-21 00:44:55 +02:00
|
|
|
const $ = require("./lib/zjquery");
|
2021-03-05 16:57:23 +01:00
|
|
|
|
2023-02-22 23:04:10 +01:00
|
|
|
const compose_pm_pill = mock_esm("../src/compose_pm_pill");
|
2021-03-05 16:57:23 +01:00
|
|
|
|
|
|
|
const compose_state = zrequire("compose_state");
|
2023-03-31 06:27:36 +02:00
|
|
|
const compose_recipient = zrequire("compose_recipient");
|
2023-05-07 14:45:04 +02:00
|
|
|
const stream_data = zrequire("stream_data");
|
2022-10-21 00:44:55 +02:00
|
|
|
|
|
|
|
const noop = () => {};
|
|
|
|
|
2021-06-16 14:38:37 +02:00
|
|
|
run_test("private_message_recipient", ({override}) => {
|
2021-03-05 16:57:23 +01:00
|
|
|
let emails;
|
|
|
|
override(compose_pm_pill, "set_from_emails", (value) => {
|
|
|
|
emails = value;
|
|
|
|
});
|
|
|
|
|
|
|
|
override(compose_pm_pill, "get_emails", () => emails);
|
|
|
|
|
|
|
|
compose_state.private_message_recipient("fred@fred.org");
|
|
|
|
assert.equal(compose_state.private_message_recipient(), "fred@fred.org");
|
|
|
|
});
|
2022-03-09 18:29:01 +01:00
|
|
|
|
2023-02-09 21:45:47 +01:00
|
|
|
run_test("has_full_recipient", ({override, override_rewire}) => {
|
2022-10-21 00:44:55 +02:00
|
|
|
mock_stream_header_colorblock();
|
|
|
|
$(`#compose_banners .topic_resolved`).remove = noop;
|
|
|
|
$(".narrow_to_compose_recipients").toggleClass = noop;
|
2023-05-01 23:17:55 +02:00
|
|
|
override_rewire(compose_recipient, "on_compose_select_recipient_update", () => {});
|
2022-10-21 00:44:55 +02:00
|
|
|
|
2022-09-26 21:01:43 +02:00
|
|
|
let emails;
|
|
|
|
override(compose_pm_pill, "set_from_emails", (value) => {
|
|
|
|
emails = value;
|
|
|
|
});
|
|
|
|
|
|
|
|
override(compose_pm_pill, "get_emails", () => emails);
|
|
|
|
|
|
|
|
compose_state.set_message_type("stream");
|
2023-06-27 01:40:25 +02:00
|
|
|
compose_state.set_stream_id("");
|
2022-03-09 18:29:01 +01:00
|
|
|
compose_state.topic("");
|
2022-09-26 21:01:43 +02:00
|
|
|
assert.equal(compose_state.has_full_recipient(), false);
|
2022-03-09 18:29:01 +01:00
|
|
|
|
|
|
|
compose_state.topic("foo");
|
2022-09-26 21:01:43 +02:00
|
|
|
assert.equal(compose_state.has_full_recipient(), false);
|
|
|
|
|
2023-05-07 14:45:04 +02:00
|
|
|
stream_data.add_sub({name: "bar", stream_id: 99});
|
2023-06-27 01:40:25 +02:00
|
|
|
compose_state.set_stream_id(99);
|
2022-09-26 21:01:43 +02:00
|
|
|
assert.equal(compose_state.has_full_recipient(), true);
|
|
|
|
|
|
|
|
compose_state.set_message_type("private");
|
|
|
|
compose_state.private_message_recipient("");
|
|
|
|
assert.equal(compose_state.has_full_recipient(), false);
|
|
|
|
|
|
|
|
compose_state.private_message_recipient("foo@zulip.com");
|
|
|
|
assert.equal(compose_state.has_full_recipient(), true);
|
2022-03-09 18:29:01 +01:00
|
|
|
});
|