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");
|
2022-10-21 00:44:55 +02:00
|
|
|
const compose_fade = zrequire("compose_fade");
|
|
|
|
const compose_ui = zrequire("compose_ui");
|
|
|
|
|
|
|
|
const noop = () => {};
|
|
|
|
|
|
|
|
let stream_value = "";
|
|
|
|
compose_ui.compose_stream_widget = {
|
|
|
|
value() {
|
|
|
|
return stream_value;
|
|
|
|
},
|
|
|
|
render(val) {
|
|
|
|
stream_value = val;
|
|
|
|
},
|
|
|
|
};
|
2021-03-05 16:57:23 +01:00
|
|
|
|
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
|
|
|
|
2022-09-26 21:01:43 +02:00
|
|
|
run_test("has_full_recipient", ({override}) => {
|
2022-10-21 00:44:55 +02:00
|
|
|
mock_stream_header_colorblock();
|
|
|
|
$(`#compose_banners .topic_resolved`).remove = noop;
|
|
|
|
compose_fade.update_all = noop;
|
|
|
|
$(".narrow_to_compose_recipients").toggleClass = noop;
|
|
|
|
compose_ui.on_compose_select_stream_update = noop;
|
|
|
|
|
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");
|
2022-10-27 00:22:29 +02:00
|
|
|
compose_state.set_stream_name("");
|
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);
|
|
|
|
|
2022-10-27 00:22:29 +02:00
|
|
|
compose_state.set_stream_name("bar");
|
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
|
|
|
});
|