node tests: Broaden what FakeComposeBox.reset does.

I moved some existing code into reset, as well as
making sure a common banner has zero length.
This commit is contained in:
Steve Howell
2025-01-08 11:12:03 +00:00
committed by Tim Abbott
parent 0a6a37fcff
commit a6f2197091
2 changed files with 13 additions and 6 deletions

View File

@@ -3,6 +3,7 @@
const assert = require("node:assert/strict"); const assert = require("node:assert/strict");
const {mock_banners} = require("./lib/compose_banner.cjs"); const {mock_banners} = require("./lib/compose_banner.cjs");
const {FakeComposeBox} = require("./lib/compose_helpers.cjs");
const {$t} = require("./lib/i18n.cjs"); const {$t} = require("./lib/i18n.cjs");
const {mock_esm, zrequire} = require("./lib/namespace.cjs"); const {mock_esm, zrequire} = require("./lib/namespace.cjs");
const {run_test, noop} = require("./lib/test.cjs"); const {run_test, noop} = require("./lib/test.cjs");
@@ -116,7 +117,11 @@ function stub_message_row($textarea) {
} }
test_ui("validate_stream_message_address_info", ({mock_template}) => { test_ui("validate_stream_message_address_info", ({mock_template}) => {
mock_banners(); // For this test we basically only use FakeComposeBox
// to set up the DOM environment. We don't assert about
// any side effects on the DOM, since the scope of this
// test is mostly to make sure the template gets rendered.
new FakeComposeBox();
const party_sub = { const party_sub = {
stream_id: 101, stream_id: 101,
@@ -128,7 +133,6 @@ test_ui("validate_stream_message_address_info", ({mock_template}) => {
party_sub.subscribed = false; party_sub.subscribed = false;
stream_data.add_sub(party_sub); stream_data.add_sub(party_sub);
$("#compose_banners .user_not_subscribed").length = 0;
let user_not_subscribed_rendered = false; let user_not_subscribed_rendered = false;
mock_template("compose_banner/compose_banner.hbs", true, (data, html) => { mock_template("compose_banner/compose_banner.hbs", true, (data, html) => {
assert.equal(data.classname, compose_banner.CLASSNAMES.user_not_subscribed); assert.equal(data.classname, compose_banner.CLASSNAMES.user_not_subscribed);
@@ -142,7 +146,9 @@ test_ui("validate_stream_message_address_info", ({mock_template}) => {
party_sub.stream_id = 102; party_sub.stream_id = 102;
stream_data.add_sub(party_sub); stream_data.add_sub(party_sub);
user_not_subscribed_rendered = false; user_not_subscribed_rendered = false;
assert.ok(!compose_validate.validate_stream_message_address_info(party_sub)); assert.ok(!compose_validate.validate_stream_message_address_info(party_sub));
assert.ok(user_not_subscribed_rendered); assert.ok(user_not_subscribed_rendered);
}); });

View File

@@ -17,7 +17,6 @@ class FakeComposeBox {
".message-limit-indicator", ".message-limit-indicator",
$.create("limit-indicator-stub"), $.create("limit-indicator-stub"),
); );
$("textarea#compose-textarea").toggleClass = noop;
const $message_row_stub = $.create("message_row_stub"); const $message_row_stub = $.create("message_row_stub");
$("textarea#compose-textarea").closest = (selector) => { $("textarea#compose-textarea").closest = (selector) => {
@@ -26,13 +25,15 @@ class FakeComposeBox {
return $message_row_stub; return $message_row_stub;
}; };
$("textarea#compose-textarea").set_height(50);
$("#compose .preview_message_area").css = noop;
this.reset(); this.reset();
} }
reset() { reset() {
$("#compose_banners .user_not_subscribed").length = 0;
$("textarea#compose-textarea").toggleClass = noop;
$("textarea#compose-textarea").set_height(50);
$("#compose .preview_message_area").css = noop;
$("textarea#compose-textarea").val("default message"); $("textarea#compose-textarea").val("default message");
$("textarea#compose-textarea").trigger("blur"); $("textarea#compose-textarea").trigger("blur");
$(".compose-submit-button .loader").show(); $(".compose-submit-button .loader").show();