mirror of
https://github.com/zulip/zulip.git
synced 2025-10-28 18:43:52 +00:00
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:
@@ -553,42 +553,31 @@ test_ui("test_stream_posting_permission", ({mock_template, override}) => {
|
||||
assert.ok(!banner_rendered);
|
||||
});
|
||||
|
||||
test_ui("test_check_overflow_text", ({mock_template, override}) => {
|
||||
test_ui("test_check_overflow_text", ({override}) => {
|
||||
const fake_compose_box = new FakeComposeBox();
|
||||
|
||||
override(realm, "max_message_length", 10000);
|
||||
|
||||
const $elem = $("#send_message_form");
|
||||
const $textarea = $(".message-textarea");
|
||||
const $indicator = $(".message-limit-indicator");
|
||||
stub_message_row($textarea);
|
||||
$elem.set_find_results(".message-textarea", $textarea);
|
||||
$elem.set_find_results(".message-limit-indicator", $indicator);
|
||||
// RED
|
||||
{
|
||||
fake_compose_box.set_textarea_val("a".repeat(10005));
|
||||
compose_validate.check_overflow_text(fake_compose_box.$send_message_form);
|
||||
fake_compose_box.assert_message_size_is_over_the_limit("-5\n");
|
||||
}
|
||||
|
||||
// Indicator should show red colored text
|
||||
let limit_indicator_html;
|
||||
mock_template("compose_limit_indicator.hbs", true, (_data, html) => {
|
||||
limit_indicator_html = html;
|
||||
});
|
||||
$textarea.val("a".repeat(10000 + 1));
|
||||
compose_validate.check_overflow_text($elem);
|
||||
assert.ok($indicator.hasClass("textarea-over-limit"));
|
||||
assert.equal(limit_indicator_html, "-1\n");
|
||||
assert.ok($textarea.hasClass("textarea-over-limit"));
|
||||
assert.ok($(".message-send-controls").hasClass("disabled-message-send-controls"));
|
||||
// ORANGE
|
||||
{
|
||||
fake_compose_box.set_textarea_val("a".repeat(9100));
|
||||
compose_validate.check_overflow_text(fake_compose_box.$send_message_form);
|
||||
fake_compose_box.assert_message_size_is_under_the_limit("900\n");
|
||||
}
|
||||
|
||||
// Indicator should show orange colored text
|
||||
$textarea.val("a".repeat(9100));
|
||||
compose_validate.check_overflow_text($elem);
|
||||
assert.ok(!$indicator.hasClass("textarea-over-limit"));
|
||||
assert.equal(limit_indicator_html, "900\n");
|
||||
assert.ok(!$textarea.hasClass("textarea-over-limit"));
|
||||
assert.ok(!$(".message-send-controls").hasClass("disabled-message-send-controls"));
|
||||
|
||||
// Indicator must be empty
|
||||
$textarea.val("a".repeat(9100 - 1));
|
||||
compose_validate.check_overflow_text($elem);
|
||||
assert.ok(!$indicator.hasClass("textarea-over-limit"));
|
||||
assert.equal($indicator.text(), "");
|
||||
assert.ok(!$textarea.hasClass("textarea-over-limit"));
|
||||
// ALL CLEAR
|
||||
{
|
||||
fake_compose_box.set_textarea_val("a".repeat(9100 - 1));
|
||||
compose_validate.check_overflow_text(fake_compose_box.$send_message_form);
|
||||
fake_compose_box.assert_message_size_is_under_the_limit();
|
||||
}
|
||||
});
|
||||
|
||||
test_ui("needs_subscribe_warning", () => {
|
||||
|
||||
Reference in New Issue
Block a user