2021-03-05 16:57:23 +01:00
|
|
|
"use strict";
|
|
|
|
|
2024-10-09 00:25:41 +02:00
|
|
|
const assert = require("node:assert/strict");
|
2021-03-05 16:57:23 +01:00
|
|
|
|
2024-11-13 07:05:32 +01:00
|
|
|
const {mock_esm, zrequire} = require("./lib/namespace.cjs");
|
|
|
|
const {run_test, noop} = require("./lib/test.cjs");
|
|
|
|
const $ = require("./lib/zjquery.cjs");
|
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-05-07 14:45:04 +02:00
|
|
|
const stream_data = zrequire("stream_data");
|
2022-10-21 00:44:55 +02: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
|
|
|
|
2023-10-05 08:04:23 +02:00
|
|
|
run_test("has_full_recipient", ({override}) => {
|
2022-10-21 00:44:55 +02:00
|
|
|
$(`#compose_banners .topic_resolved`).remove = noop;
|
|
|
|
$(".narrow_to_compose_recipients").toggleClass = 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");
|
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
|
|
|
});
|