compose_validate test: Use FakeComposeBox for size limits.

This commit simplifies a compose_validate test by
using FakeComposeBox.

It also exposes $send_message_form to the callers.
(The general idea here is that for any individual
test, we don't want the developer to have to
switch between thinking about low-level zjquery
idioms and higher-level abstractions.)

This commit also removes the use of mock_template,
since the template in question generates trivially
easy html to deal with (and we verify the actual
effects to the DOM).
This commit is contained in:
Steve Howell
2025-01-08 11:46:13 +00:00
committed by Tim Abbott
parent a3c76646b2
commit a1217fbc5a
2 changed files with 52 additions and 35 deletions

View File

@@ -7,15 +7,16 @@ const $ = require("./zjquery.cjs");
class FakeComposeBox {
constructor() {
this.$send_message_form = $("#send_message_form");
this.$content_textarea = $("textarea#compose-textarea");
this.$preview_message_area = $("#compose .preview_message_area");
// Simulate DOM relationships
$("#send_message_form").set_find_results(".message-textarea", this.$content_textarea);
this.$send_message_form.set_find_results(".message-textarea", this.$content_textarea);
$("#send_message_form").set_find_results(
this.$send_message_form.set_find_results(
".message-limit-indicator",
$.create("limit-indicator-stub"),
$(".message-limit-indicator"),
);
const $message_row_stub = $.create("message_row_stub");
@@ -29,6 +30,9 @@ class FakeComposeBox {
}
reset() {
$(".message-limit-indicator").html("");
$(".message-limit-indicator").text("");
$("#compose_banners .user_not_subscribed").length = 0;
this.$content_textarea.toggleClass = noop;
@@ -135,6 +139,30 @@ class FakeComposeBox {
assert.ok($("#compose .undo_markdown_preview").visible());
assert.ok($("#compose").hasClass("preview_mode"));
}
assert_message_size_is_over_the_limit(desired_html) {
// Indicator should show red colored text
assert.equal($(".message-limit-indicator").html(), desired_html);
assert.ok(this.$content_textarea.hasClass("textarea-over-limit"));
assert.ok($(".message-limit-indicator").hasClass("textarea-over-limit"));
assert.ok($(".message-send-controls").hasClass("disabled-message-send-controls"));
}
assert_message_size_is_under_the_limit(desired_html) {
// Work around the quirk that our validation code
// arbitrarily switches between html() and text(),
// and zjquery doesn't unify text and html.
if (desired_html) {
assert.equal($(".message-limit-indicator").html(), desired_html);
} else {
assert.equal($(".message-limit-indicator").text(), "");
}
assert.ok(!this.$content_textarea.hasClass("textarea-over-limit"));
assert.ok(!$(".message-limit-indicator").hasClass("textarea-over-limit"));
assert.ok(!$(".message-send-controls").hasClass("disabled-message-send-controls"));
}
}
module.exports = {FakeComposeBox};