2020-08-01 03:43:15 +02:00
|
|
|
"use strict";
|
|
|
|
|
2020-11-30 23:46:45 +01:00
|
|
|
const {strict: assert} = require("assert");
|
|
|
|
|
2023-02-22 23:04:10 +01:00
|
|
|
const {mock_esm, set_global, zrequire} = require("./lib/namespace");
|
2023-12-14 23:51:33 +01:00
|
|
|
const {run_test, noop} = require("./lib/test");
|
2023-02-22 23:04:10 +01:00
|
|
|
const $ = require("./lib/zjquery");
|
2024-02-13 02:08:24 +01:00
|
|
|
const {realm} = require("./lib/zpage_params");
|
2020-12-01 00:02:16 +01:00
|
|
|
|
2024-05-15 04:24:25 +02:00
|
|
|
class ClipboardEvent {
|
|
|
|
constructor({clipboardData}) {
|
|
|
|
this.clipboardData = clipboardData;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
set_global("ClipboardEvent", ClipboardEvent);
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
set_global("navigator", {
|
|
|
|
userAgent: "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)",
|
2018-02-13 23:29:17 +01:00
|
|
|
});
|
2017-11-25 22:22:36 +01:00
|
|
|
|
2021-03-10 06:31:13 +01:00
|
|
|
let uppy_stub;
|
2022-10-07 00:56:00 +02:00
|
|
|
mock_esm("@uppy/core", {
|
|
|
|
Uppy: function Uppy(options) {
|
|
|
|
return uppy_stub.call(this, options);
|
|
|
|
},
|
|
|
|
});
|
2023-06-16 12:49:02 +02:00
|
|
|
|
2022-10-07 00:56:00 +02:00
|
|
|
mock_esm("@uppy/xhr-upload", {default: class XHRUpload {}});
|
2019-11-21 05:24:55 +01:00
|
|
|
|
2023-02-22 23:04:10 +01:00
|
|
|
const compose_actions = mock_esm("../src/compose_actions");
|
2023-10-06 01:43:50 +02:00
|
|
|
const compose_reply = mock_esm("../src/compose_reply");
|
2023-09-21 06:25:07 +02:00
|
|
|
const compose_state = mock_esm("../src/compose_state");
|
2023-02-22 23:04:10 +01:00
|
|
|
mock_esm("../src/csrf", {csrf_token: "csrf_token"});
|
2023-09-21 06:25:07 +02:00
|
|
|
const rows = mock_esm("../src/rows");
|
2021-03-25 23:20:18 +01:00
|
|
|
|
2023-01-09 07:02:05 +01:00
|
|
|
const compose_ui = zrequire("compose_ui");
|
zjsunit: Remove rewiremock dependency.
We now just use a module._load hook to inject
stubs into our code.
For conversion purposes I temporarily maintain
the API of rewiremock, apart from the enable/disable
pieces, but I will make a better wrapper in an
upcoming commit.
We can detect when rewiremock is called after
zrequire now, and I fix all the violations in
this commit, mostly by using override.
We can also detect when a mock is needlessly
created, and I fix all the violations in this
commit.
The one minor nuisance that this commit introduces
is that you can only stub out modules in the Zulip
source tree, which is now static/js. This should
not really be a problem--there are usually better
techniques to deal with third party depenencies.
In the prior commit I show a typical workaround,
which is to create a one-line wrapper in your
test code. It's often the case that you can simply
use override(), as well.
In passing I kill off `reset_modules`, and I
eliminated the second argument to zrequire,
which dates back to pre-es6 days.
2021-03-06 12:47:54 +01:00
|
|
|
const upload = zrequire("upload");
|
2024-02-20 01:25:16 +01:00
|
|
|
const message_lists = mock_esm("../src/message_lists");
|
2024-01-09 08:20:20 +01:00
|
|
|
message_lists.current = {
|
2024-01-17 07:53:40 +01:00
|
|
|
id: "1",
|
2024-01-09 08:20:20 +01:00
|
|
|
};
|
2021-04-03 19:07:13 +02:00
|
|
|
function test(label, f) {
|
2022-07-10 01:06:33 +02:00
|
|
|
run_test(label, (helpers) => {
|
2024-02-13 02:08:24 +01:00
|
|
|
realm.max_file_upload_size_mib = 25;
|
2023-01-09 07:43:39 +01:00
|
|
|
return f(helpers);
|
2021-04-03 19:07:13 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-06-16 14:38:37 +02:00
|
|
|
test("feature_check", ({override}) => {
|
2024-05-14 09:48:08 +02:00
|
|
|
assert.ok(!upload.feature_check());
|
2021-03-05 17:27:53 +01:00
|
|
|
|
2021-03-05 17:48:22 +01:00
|
|
|
override(window, "XMLHttpRequest", () => ({upload: true}));
|
2024-05-14 09:48:08 +02:00
|
|
|
assert.ok(upload.feature_check());
|
2021-03-05 17:27:53 +01:00
|
|
|
});
|
|
|
|
|
2024-05-15 03:44:44 +02:00
|
|
|
test("config", () => {
|
|
|
|
assert.equal(upload.compose_config.textarea(), $("textarea#compose-textarea"));
|
2020-07-15 00:34:28 +02:00
|
|
|
assert.equal(
|
2024-05-15 03:44:44 +02:00
|
|
|
upload.compose_config.upload_banner_message("id_1"),
|
2023-03-28 07:54:27 +02:00
|
|
|
$("#compose_banners .upload_banner.file_id_1 .upload_msg"),
|
2023-01-09 07:43:39 +01:00
|
|
|
);
|
2023-06-06 14:37:19 +02:00
|
|
|
assert.equal(
|
2024-05-15 03:44:44 +02:00
|
|
|
upload.compose_config.upload_banner_cancel_button("id_2"),
|
2023-06-06 14:37:19 +02:00
|
|
|
$("#compose_banners .upload_banner.file_id_2 .upload_banner_cancel_button"),
|
|
|
|
);
|
2023-01-09 07:43:39 +01:00
|
|
|
assert.equal(
|
2024-05-15 03:44:44 +02:00
|
|
|
upload.compose_config.upload_banner_hide_button("id_2"),
|
2023-05-15 19:57:31 +02:00
|
|
|
$("#compose_banners .upload_banner.file_id_2 .main-view-banner-close-button"),
|
2020-07-15 00:34:28 +02:00
|
|
|
);
|
2024-05-15 04:24:25 +02:00
|
|
|
assert.equal(upload.compose_config.file_input_identifier(), "#compose input.file_input");
|
2024-05-15 03:44:44 +02:00
|
|
|
assert.equal(upload.compose_config.source(), "compose-file-input");
|
|
|
|
assert.equal(upload.compose_config.drag_drop_container(), $("#compose"));
|
2021-04-20 16:14:55 +02:00
|
|
|
assert.equal(
|
2024-05-15 03:44:44 +02:00
|
|
|
upload.compose_config.markdown_preview_hide_button(),
|
2021-04-20 19:50:01 +02:00
|
|
|
$("#compose .undo_markdown_preview"),
|
2020-09-04 21:10:48 +02:00
|
|
|
);
|
2019-11-21 05:24:55 +01:00
|
|
|
|
2021-02-03 23:23:32 +01:00
|
|
|
assert.equal(
|
2024-05-15 03:44:44 +02:00
|
|
|
upload.edit_config(1).textarea(),
|
2024-05-15 04:24:25 +02:00
|
|
|
$(`#edit_form_${CSS.escape(1)} textarea.message_edit_content`),
|
2021-02-03 23:23:32 +01:00
|
|
|
);
|
2019-11-21 05:24:55 +01:00
|
|
|
|
2023-06-15 12:03:46 +02:00
|
|
|
$(`#edit_form_${CSS.escape(2)}`).set_find_results(
|
|
|
|
".message_edit_save",
|
|
|
|
$(".message_edit_save"),
|
|
|
|
);
|
2024-05-15 03:44:44 +02:00
|
|
|
assert.equal(upload.edit_config(2).send_button(), $(".message_edit_save"));
|
2019-11-21 05:24:55 +01:00
|
|
|
|
2020-07-15 00:34:28 +02:00
|
|
|
assert.equal(
|
2024-05-15 03:44:44 +02:00
|
|
|
upload.edit_config(11).upload_banner_identifier("id_3"),
|
2023-03-28 07:54:27 +02:00
|
|
|
`#edit_form_${CSS.escape(11)} .upload_banner.file_id_3`,
|
2020-07-15 00:34:28 +02:00
|
|
|
);
|
|
|
|
assert.equal(
|
2024-05-15 03:44:44 +02:00
|
|
|
upload.edit_config(75).upload_banner("id_60"),
|
2023-03-28 07:54:27 +02:00
|
|
|
$(`#edit_form_${CSS.escape(75)} .upload_banner.file_id_60`),
|
2020-07-15 00:34:28 +02:00
|
|
|
);
|
2019-11-21 05:24:55 +01:00
|
|
|
|
2023-06-06 14:37:19 +02:00
|
|
|
$(`#edit_form_${CSS.escape(2)} .upload_banner`).set_find_results(
|
|
|
|
".upload_banner_cancel_button",
|
|
|
|
$(".upload_banner_cancel_button"),
|
|
|
|
);
|
|
|
|
assert.equal(
|
2024-05-15 03:44:44 +02:00
|
|
|
upload.edit_config(2).upload_banner_cancel_button("id_34"),
|
2023-06-06 14:37:19 +02:00
|
|
|
$(`#edit_form_${CSS.escape(2)} .upload_banner.file_id_34 .upload_banner_cancel_button`),
|
|
|
|
);
|
|
|
|
|
2023-01-09 07:43:39 +01:00
|
|
|
$(`#edit_form_${CSS.escape(2)} .upload_banner`).set_find_results(
|
2023-05-15 19:57:31 +02:00
|
|
|
".main-view-banner-close-button",
|
|
|
|
$(".main-view-banner-close-button"),
|
2020-07-15 00:34:28 +02:00
|
|
|
);
|
|
|
|
assert.equal(
|
2024-05-15 03:44:44 +02:00
|
|
|
upload.edit_config(2).upload_banner_hide_button("id_34"),
|
2023-05-15 19:57:31 +02:00
|
|
|
$(`#edit_form_${CSS.escape(2)} .upload_banner.file_id_34 .main-view-banner-close-button`),
|
2020-07-15 00:34:28 +02:00
|
|
|
);
|
2019-11-21 05:24:55 +01:00
|
|
|
|
2023-03-28 07:54:27 +02:00
|
|
|
$(`#edit_form_${CSS.escape(22)} .upload_banner.file_id_234`).set_find_results(
|
2023-01-09 07:43:39 +01:00
|
|
|
".upload_msg",
|
|
|
|
$(".upload_msg"),
|
|
|
|
);
|
|
|
|
assert.equal(
|
2024-05-15 03:44:44 +02:00
|
|
|
upload.edit_config(22).upload_banner_message("id_234"),
|
2023-03-28 07:54:27 +02:00
|
|
|
$(`#edit_form_${CSS.escape(22)} .upload_banner.file_id_234 .upload_msg`),
|
2021-02-03 23:23:32 +01:00
|
|
|
);
|
2019-11-21 05:24:55 +01:00
|
|
|
|
2020-07-15 00:34:28 +02:00
|
|
|
assert.equal(
|
2024-05-15 03:44:44 +02:00
|
|
|
upload.edit_config(123).file_input_identifier(),
|
2024-05-15 04:24:25 +02:00
|
|
|
`#edit_form_${CSS.escape(123)} input.file_input`,
|
2020-07-15 00:34:28 +02:00
|
|
|
);
|
2024-05-15 03:44:44 +02:00
|
|
|
assert.equal(upload.edit_config(123).source(), "message-edit-file-input");
|
2020-07-15 00:34:28 +02:00
|
|
|
assert.equal(
|
2024-05-15 03:44:44 +02:00
|
|
|
upload.edit_config(1).drag_drop_container(),
|
2024-01-17 07:53:40 +01:00
|
|
|
$(`#message-row-1-${CSS.escape(1)} .message_edit_form`),
|
2020-07-15 00:34:28 +02:00
|
|
|
);
|
2020-09-04 21:10:48 +02:00
|
|
|
assert.equal(
|
2024-05-15 03:44:44 +02:00
|
|
|
upload.edit_config(65).markdown_preview_hide_button(),
|
2021-04-20 19:50:01 +02:00
|
|
|
$(`#edit_form_${CSS.escape(65)} .undo_markdown_preview`),
|
2020-09-04 21:10:48 +02:00
|
|
|
);
|
2019-11-21 05:24:55 +01:00
|
|
|
});
|
|
|
|
|
2023-01-09 07:43:39 +01:00
|
|
|
test("show_error_message", ({mock_template}) => {
|
2023-12-14 23:51:33 +01:00
|
|
|
$("#compose_banners .upload_banner .moving_bar").css = noop;
|
2023-01-09 07:43:39 +01:00
|
|
|
$("#compose_banners .upload_banner").length = 0;
|
|
|
|
|
|
|
|
let banner_shown = false;
|
|
|
|
mock_template("compose_banner/upload_banner.hbs", false, (data) => {
|
|
|
|
assert.equal(data.banner_type, "error");
|
|
|
|
assert.equal(data.banner_text, "Error message");
|
|
|
|
banner_shown = true;
|
2023-12-28 07:50:10 +01:00
|
|
|
return "<banner-stub>";
|
2023-01-09 07:43:39 +01:00
|
|
|
});
|
|
|
|
|
2020-07-22 02:59:06 +02:00
|
|
|
$("#compose-send-button").prop("disabled", true);
|
2019-11-21 05:24:55 +01:00
|
|
|
|
2024-05-15 03:39:14 +02:00
|
|
|
upload.show_error_message(upload.compose_config, "Error message");
|
2023-11-10 21:00:25 +01:00
|
|
|
assert.ok(!$(".message-send-controls").hasClass("disabled-message-send-controls"));
|
2023-01-09 07:43:39 +01:00
|
|
|
assert.ok(banner_shown);
|
2019-11-21 05:24:55 +01:00
|
|
|
|
2023-01-09 07:43:39 +01:00
|
|
|
mock_template("compose_banner/upload_banner.hbs", false, (data) => {
|
|
|
|
assert.equal(data.banner_type, "error");
|
|
|
|
assert.equal(data.banner_text, "translated: An unknown error occurred.");
|
|
|
|
banner_shown = true;
|
2023-12-28 07:50:10 +01:00
|
|
|
return "<banner-stub>";
|
2023-01-09 07:43:39 +01:00
|
|
|
});
|
2024-05-15 03:39:14 +02:00
|
|
|
upload.show_error_message(upload.compose_config);
|
2019-11-21 05:24:55 +01:00
|
|
|
});
|
|
|
|
|
2023-01-09 07:43:39 +01:00
|
|
|
test("upload_files", async ({mock_template, override_rewire}) => {
|
2023-12-14 23:51:33 +01:00
|
|
|
$("#compose_banners .upload_banner").remove = noop;
|
|
|
|
$("#compose_banners .upload_banner .moving_bar").css = noop;
|
2023-01-09 07:43:39 +01:00
|
|
|
$("#compose_banners .upload_banner").length = 0;
|
|
|
|
|
2020-04-16 17:11:06 +02:00
|
|
|
let files = [
|
2019-11-21 05:24:55 +01:00
|
|
|
{
|
|
|
|
name: "budapest.png",
|
|
|
|
type: "image/png",
|
|
|
|
},
|
|
|
|
];
|
|
|
|
let uppy_add_file_called = false;
|
2023-03-28 07:54:27 +02:00
|
|
|
let remove_file_called = false;
|
2019-11-21 05:24:55 +01:00
|
|
|
const uppy = {
|
2022-11-17 23:33:43 +01:00
|
|
|
addFile(params) {
|
2019-11-21 05:24:55 +01:00
|
|
|
uppy_add_file_called = true;
|
|
|
|
assert.equal(params.source, "compose-file-input");
|
|
|
|
assert.equal(params.name, "budapest.png");
|
|
|
|
assert.equal(params.type, "image/png");
|
|
|
|
assert.equal(params.data, files[0]);
|
2023-03-28 07:54:27 +02:00
|
|
|
return "id_123";
|
|
|
|
},
|
|
|
|
removeFile() {
|
|
|
|
remove_file_called = true;
|
2019-11-21 05:24:55 +01:00
|
|
|
},
|
2018-08-15 03:57:35 +02:00
|
|
|
};
|
2023-04-05 05:37:14 +02:00
|
|
|
let hide_upload_banner_called = false;
|
2023-06-29 21:59:08 +02:00
|
|
|
override_rewire(upload, "hide_upload_banner", (_uppy, config) => {
|
2023-04-05 05:37:14 +02:00
|
|
|
hide_upload_banner_called = true;
|
2021-06-03 16:42:03 +02:00
|
|
|
assert.equal(config.mode, "compose");
|
2021-02-28 00:52:20 +01:00
|
|
|
});
|
2024-05-15 03:39:14 +02:00
|
|
|
const config = upload.compose_config;
|
2023-11-10 21:00:25 +01:00
|
|
|
$(".message-send-controls").removeClass("disabled-message-send-controls");
|
2023-01-09 07:43:39 +01:00
|
|
|
await upload.upload_files(uppy, config, []);
|
2023-11-10 21:00:25 +01:00
|
|
|
assert.ok(!$(".message-send-controls").hasClass("disabled-message-send-controls"));
|
2017-11-25 22:22:36 +01:00
|
|
|
|
2023-01-09 07:43:39 +01:00
|
|
|
let banner_shown = false;
|
|
|
|
mock_template("compose_banner/upload_banner.hbs", false, (data) => {
|
|
|
|
assert.equal(data.banner_type, "error");
|
|
|
|
assert.equal(
|
|
|
|
data.banner_text,
|
|
|
|
"translated: File and image uploads have been disabled for this organization.",
|
|
|
|
);
|
|
|
|
banner_shown = true;
|
2023-12-28 07:50:10 +01:00
|
|
|
return "<banner-stub>";
|
2023-01-09 07:43:39 +01:00
|
|
|
});
|
2024-02-13 02:08:24 +01:00
|
|
|
realm.max_file_upload_size_mib = 0;
|
2023-01-09 07:43:39 +01:00
|
|
|
$("#compose_banners .upload_banner .upload_msg").text("");
|
|
|
|
await upload.upload_files(uppy, config, files);
|
|
|
|
assert.ok(banner_shown);
|
2017-11-25 22:22:36 +01:00
|
|
|
|
2024-02-13 02:08:24 +01:00
|
|
|
realm.max_file_upload_size_mib = 25;
|
2019-11-21 05:24:55 +01:00
|
|
|
let on_click_close_button_callback;
|
2023-06-06 14:37:19 +02:00
|
|
|
|
|
|
|
$("#compose_banners .upload_banner.file_id_123 .upload_banner_cancel_button").one = (
|
2023-03-28 07:54:27 +02:00
|
|
|
event,
|
|
|
|
callback,
|
|
|
|
) => {
|
2019-11-21 05:24:55 +01:00
|
|
|
assert.equal(event, "click");
|
|
|
|
on_click_close_button_callback = callback;
|
|
|
|
};
|
|
|
|
let compose_ui_insert_syntax_and_focus_called = false;
|
2023-03-28 07:54:27 +02:00
|
|
|
override_rewire(compose_ui, "insert_syntax_and_focus", () => {
|
2019-11-21 05:24:55 +01:00
|
|
|
compose_ui_insert_syntax_and_focus_called = true;
|
2021-02-28 01:26:48 +01:00
|
|
|
});
|
2019-11-21 05:24:55 +01:00
|
|
|
let compose_ui_autosize_textarea_called = false;
|
2023-01-09 07:02:05 +01:00
|
|
|
override_rewire(compose_ui, "autosize_textarea", () => {
|
2019-11-21 05:24:55 +01:00
|
|
|
compose_ui_autosize_textarea_called = true;
|
2021-02-28 01:26:48 +01:00
|
|
|
});
|
2020-09-04 21:10:48 +02:00
|
|
|
let markdown_preview_hide_button_clicked = false;
|
2021-04-20 19:50:01 +02:00
|
|
|
$("#compose .undo_markdown_preview").on("click", () => {
|
2020-09-04 21:10:48 +02:00
|
|
|
markdown_preview_hide_button_clicked = true;
|
|
|
|
});
|
2023-11-10 21:00:25 +01:00
|
|
|
$(".message-send-controls").removeClass("disabled-message-send-controls");
|
2023-01-09 07:43:39 +01:00
|
|
|
$("#compose_banners .upload_banner").remove();
|
2021-04-20 19:50:01 +02:00
|
|
|
$("#compose .undo_markdown_preview").show();
|
2023-01-09 07:43:39 +01:00
|
|
|
|
|
|
|
banner_shown = false;
|
2023-03-28 07:54:27 +02:00
|
|
|
mock_template("compose_banner/upload_banner.hbs", false, () => {
|
2023-01-09 07:43:39 +01:00
|
|
|
banner_shown = true;
|
2023-12-28 07:50:10 +01:00
|
|
|
return "<banner-stub>";
|
2023-01-09 07:43:39 +01:00
|
|
|
});
|
|
|
|
await upload.upload_files(uppy, config, files);
|
2023-11-10 21:00:25 +01:00
|
|
|
assert.ok($(".message-send-controls").hasClass("disabled-message-send-controls"));
|
2023-01-09 07:43:39 +01:00
|
|
|
assert.ok(banner_shown);
|
2021-06-10 08:32:54 +02:00
|
|
|
assert.ok(compose_ui_insert_syntax_and_focus_called);
|
|
|
|
assert.ok(compose_ui_autosize_textarea_called);
|
|
|
|
assert.ok(markdown_preview_hide_button_clicked);
|
|
|
|
assert.ok(uppy_add_file_called);
|
2017-11-25 22:22:36 +01:00
|
|
|
|
2023-01-09 07:43:39 +01:00
|
|
|
banner_shown = false;
|
2020-04-16 17:11:06 +02:00
|
|
|
files = [
|
|
|
|
{
|
|
|
|
name: "budapest.png",
|
|
|
|
type: "image/png",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "prague.png",
|
|
|
|
type: "image/png",
|
|
|
|
},
|
|
|
|
];
|
|
|
|
let add_file_counter = 0;
|
|
|
|
uppy.addFile = (file) => {
|
|
|
|
add_file_counter += 1;
|
2023-03-28 07:54:27 +02:00
|
|
|
if (file.name === "budapest.png") {
|
|
|
|
throw new Error("some error");
|
|
|
|
}
|
|
|
|
return `id_${add_file_counter}`;
|
2020-04-16 17:11:06 +02:00
|
|
|
};
|
2023-01-09 07:43:39 +01:00
|
|
|
await upload.upload_files(uppy, config, files);
|
|
|
|
assert.ok(banner_shown);
|
2023-03-28 07:54:27 +02:00
|
|
|
assert.equal(add_file_counter, 2);
|
2020-04-16 17:11:06 +02:00
|
|
|
|
2023-04-05 05:37:14 +02:00
|
|
|
hide_upload_banner_called = false;
|
2020-03-08 11:13:57 +01:00
|
|
|
let compose_ui_replace_syntax_called = false;
|
2023-03-28 07:54:27 +02:00
|
|
|
|
2023-11-02 20:47:30 +01:00
|
|
|
override_rewire(compose_ui, "replace_syntax", (old_syntax, new_syntax, $textarea) => {
|
2020-03-08 11:13:57 +01:00
|
|
|
compose_ui_replace_syntax_called = true;
|
2020-04-17 17:37:06 +02:00
|
|
|
assert.equal(old_syntax, "[translated: Uploading budapest.png…]()");
|
2020-03-08 11:13:57 +01:00
|
|
|
assert.equal(new_syntax, "");
|
2023-11-02 20:47:30 +01:00
|
|
|
assert.equal($textarea, $("textarea#compose-textarea"));
|
2021-02-28 01:26:48 +01:00
|
|
|
});
|
2019-11-21 05:24:55 +01:00
|
|
|
on_click_close_button_callback();
|
2023-03-28 07:54:27 +02:00
|
|
|
assert.ok(remove_file_called);
|
2023-04-05 05:37:14 +02:00
|
|
|
assert.ok(hide_upload_banner_called);
|
2021-06-10 08:32:54 +02:00
|
|
|
assert.ok(compose_ui_autosize_textarea_called);
|
|
|
|
assert.ok(compose_ui_replace_syntax_called);
|
2023-04-05 05:37:14 +02:00
|
|
|
hide_upload_banner_called = false;
|
2020-03-08 11:13:57 +01:00
|
|
|
compose_ui_replace_syntax_called = false;
|
2023-03-28 07:54:27 +02:00
|
|
|
remove_file_called = false;
|
2023-11-02 19:29:54 +01:00
|
|
|
$("textarea#compose-textarea").val("user modified text");
|
2023-03-28 07:54:27 +02:00
|
|
|
|
2020-03-08 11:13:57 +01:00
|
|
|
on_click_close_button_callback();
|
2023-03-28 07:54:27 +02:00
|
|
|
assert.ok(remove_file_called);
|
2023-04-05 05:37:14 +02:00
|
|
|
assert.ok(hide_upload_banner_called);
|
2021-06-10 08:32:54 +02:00
|
|
|
assert.ok(compose_ui_autosize_textarea_called);
|
|
|
|
assert.ok(compose_ui_replace_syntax_called);
|
2023-11-02 19:29:54 +01:00
|
|
|
assert.equal($("textarea#compose-textarea").val(), "user modified text");
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|
2017-11-25 22:22:36 +01:00
|
|
|
|
2021-04-03 19:07:13 +02:00
|
|
|
test("uppy_config", () => {
|
2019-11-21 05:24:55 +01:00
|
|
|
let uppy_stub_called = false;
|
|
|
|
let uppy_set_meta_called = false;
|
|
|
|
let uppy_used_xhrupload = false;
|
2018-04-05 04:29:21 +02:00
|
|
|
|
2021-03-10 06:31:13 +01:00
|
|
|
uppy_stub = function (config) {
|
2019-11-21 05:24:55 +01:00
|
|
|
uppy_stub_called = true;
|
|
|
|
assert.equal(config.debug, false);
|
|
|
|
assert.equal(config.autoProceed, true);
|
|
|
|
assert.equal(config.restrictions.maxFileSize, 25 * 1024 * 1024);
|
|
|
|
assert.equal(Object.keys(config.locale.strings).length, 2);
|
2021-06-10 08:32:54 +02:00
|
|
|
assert.ok("exceedsSize" in config.locale.strings);
|
2019-11-21 05:24:55 +01:00
|
|
|
|
|
|
|
return {
|
2022-11-17 23:33:43 +01:00
|
|
|
setMeta(params) {
|
2019-11-21 05:24:55 +01:00
|
|
|
uppy_set_meta_called = true;
|
2020-07-15 01:29:15 +02:00
|
|
|
assert.equal(params.csrfmiddlewaretoken, "csrf_token");
|
2019-11-21 05:24:55 +01:00
|
|
|
},
|
2022-11-17 23:33:43 +01:00
|
|
|
use(func, params) {
|
2019-11-21 05:24:55 +01:00
|
|
|
const func_name = func.name;
|
|
|
|
if (func_name === "XHRUpload") {
|
|
|
|
uppy_used_xhrupload = true;
|
2020-07-15 01:29:15 +02:00
|
|
|
assert.equal(params.endpoint, "/json/user_uploads");
|
2019-11-21 05:24:55 +01:00
|
|
|
assert.equal(params.formData, true);
|
2020-07-15 01:29:15 +02:00
|
|
|
assert.equal(params.fieldName, "file");
|
2019-11-21 05:24:55 +01:00
|
|
|
assert.equal(params.limit, 5);
|
|
|
|
assert.equal(Object.keys(params.locale.strings).length, 1);
|
2024-05-15 04:25:06 +02:00
|
|
|
assert.ok("uploadStalled" in params.locale.strings);
|
2019-11-21 05:24:55 +01:00
|
|
|
} else {
|
|
|
|
/* istanbul ignore next */
|
|
|
|
assert.fail(`Missing tests for ${func_name}`);
|
|
|
|
}
|
|
|
|
},
|
2022-11-17 23:33:43 +01:00
|
|
|
on() {},
|
2018-04-05 04:29:21 +02:00
|
|
|
};
|
2021-03-10 06:31:13 +01:00
|
|
|
};
|
2024-05-15 03:39:14 +02:00
|
|
|
upload.setup_upload(upload.compose_config);
|
2017-11-25 22:22:36 +01:00
|
|
|
|
2019-11-21 05:24:55 +01:00
|
|
|
assert.equal(uppy_stub_called, true);
|
|
|
|
assert.equal(uppy_set_meta_called, true);
|
|
|
|
assert.equal(uppy_used_xhrupload, true);
|
|
|
|
});
|
2017-11-25 22:22:36 +01:00
|
|
|
|
2022-01-08 10:27:06 +01:00
|
|
|
test("file_input", ({override_rewire}) => {
|
2024-05-15 03:39:14 +02:00
|
|
|
upload.setup_upload(upload.compose_config);
|
2019-11-21 05:24:55 +01:00
|
|
|
|
2024-05-15 04:24:25 +02:00
|
|
|
const change_handler = $("#compose input.file_input").get_on_handler("change");
|
2019-11-21 05:24:55 +01:00
|
|
|
const files = ["file1", "file2"];
|
|
|
|
const event = {
|
|
|
|
target: {
|
2020-07-20 22:18:43 +02:00
|
|
|
files,
|
2020-07-16 23:03:45 +02:00
|
|
|
value: "C:\\fakepath\\portland.png",
|
2019-11-21 05:24:55 +01:00
|
|
|
},
|
|
|
|
};
|
|
|
|
let upload_files_called = false;
|
2023-06-29 21:59:08 +02:00
|
|
|
override_rewire(upload, "upload_files", (_uppy, config, files) => {
|
2019-11-21 05:24:55 +01:00
|
|
|
assert.equal(config.mode, "compose");
|
|
|
|
assert.equal(files, files);
|
|
|
|
upload_files_called = true;
|
2021-02-28 00:52:20 +01:00
|
|
|
});
|
2019-11-21 05:24:55 +01:00
|
|
|
change_handler(event);
|
2021-06-10 08:32:54 +02:00
|
|
|
assert.ok(upload_files_called);
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|
2017-11-25 22:22:36 +01:00
|
|
|
|
2023-04-12 13:10:40 +02:00
|
|
|
test("file_drop", ({override, override_rewire}) => {
|
2023-09-21 06:25:07 +02:00
|
|
|
override(compose_state, "composing", () => false);
|
2024-05-15 03:39:14 +02:00
|
|
|
upload.setup_upload(upload.compose_config);
|
2017-11-25 22:22:36 +01:00
|
|
|
|
2019-11-21 05:24:55 +01:00
|
|
|
let prevent_default_counter = 0;
|
|
|
|
const drag_event = {
|
2022-11-17 23:33:43 +01:00
|
|
|
preventDefault() {
|
2019-11-21 05:24:55 +01:00
|
|
|
prevent_default_counter += 1;
|
|
|
|
},
|
|
|
|
};
|
|
|
|
const dragover_handler = $("#compose").get_on_handler("dragover");
|
|
|
|
dragover_handler(drag_event);
|
|
|
|
assert.equal(prevent_default_counter, 1);
|
|
|
|
|
|
|
|
const dragenter_handler = $("#compose").get_on_handler("dragenter");
|
|
|
|
dragenter_handler(drag_event);
|
|
|
|
assert.equal(prevent_default_counter, 2);
|
|
|
|
|
2023-09-07 00:29:46 +02:00
|
|
|
let stop_propagation_counter = 0;
|
2019-11-21 05:24:55 +01:00
|
|
|
const files = ["file1", "file2"];
|
|
|
|
const drop_event = {
|
2022-11-17 23:33:43 +01:00
|
|
|
preventDefault() {
|
2019-11-21 05:24:55 +01:00
|
|
|
prevent_default_counter += 1;
|
|
|
|
},
|
2023-06-16 12:49:02 +02:00
|
|
|
stopPropagation() {
|
2023-09-07 00:29:46 +02:00
|
|
|
stop_propagation_counter += 1;
|
2023-06-16 12:49:02 +02:00
|
|
|
},
|
2019-11-21 05:24:55 +01:00
|
|
|
originalEvent: {
|
|
|
|
dataTransfer: {
|
2020-07-20 22:18:43 +02:00
|
|
|
files,
|
2019-11-21 05:24:55 +01:00
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
const drop_handler = $("#compose").get_on_handler("drop");
|
|
|
|
let upload_files_called = false;
|
2022-01-08 10:27:06 +01:00
|
|
|
override_rewire(upload, "upload_files", () => {
|
2020-07-15 00:34:28 +02:00
|
|
|
upload_files_called = true;
|
2021-02-28 00:52:20 +01:00
|
|
|
});
|
2023-04-12 13:10:40 +02:00
|
|
|
let compose_actions_start_called = false;
|
2023-10-06 01:43:50 +02:00
|
|
|
override(compose_reply, "respond_to_message", () => {
|
2023-04-12 13:10:40 +02:00
|
|
|
compose_actions_start_called = true;
|
|
|
|
});
|
2019-11-21 05:24:55 +01:00
|
|
|
drop_handler(drop_event);
|
2023-04-12 13:10:40 +02:00
|
|
|
assert.ok(compose_actions_start_called);
|
2019-11-21 05:24:55 +01:00
|
|
|
assert.equal(prevent_default_counter, 3);
|
2023-09-07 00:29:46 +02:00
|
|
|
assert.equal(stop_propagation_counter, 1);
|
2019-11-21 05:24:55 +01:00
|
|
|
assert.equal(upload_files_called, true);
|
|
|
|
});
|
|
|
|
|
2023-04-12 13:10:40 +02:00
|
|
|
test("copy_paste", ({override, override_rewire}) => {
|
2023-09-21 06:25:07 +02:00
|
|
|
override(compose_state, "composing", () => false);
|
2024-05-15 03:39:14 +02:00
|
|
|
upload.setup_upload(upload.compose_config);
|
2019-11-21 05:24:55 +01:00
|
|
|
|
|
|
|
const paste_handler = $("#compose").get_on_handler("paste");
|
|
|
|
let get_as_file_called = false;
|
|
|
|
let event = {
|
2024-05-15 04:24:25 +02:00
|
|
|
originalEvent: new ClipboardEvent({
|
2019-11-21 05:24:55 +01:00
|
|
|
clipboardData: {
|
|
|
|
items: [
|
|
|
|
{
|
|
|
|
kind: "file",
|
2022-11-17 23:33:43 +01:00
|
|
|
getAsFile() {
|
2019-11-21 05:24:55 +01:00
|
|
|
get_as_file_called = true;
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
kind: "notfile",
|
2024-05-15 04:24:25 +02:00
|
|
|
getAsFile: () => null,
|
2019-11-21 05:24:55 +01:00
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
2024-05-15 04:24:25 +02:00
|
|
|
}),
|
2023-09-07 18:18:51 +02:00
|
|
|
preventDefault() {},
|
2019-11-21 05:24:55 +01:00
|
|
|
};
|
|
|
|
let upload_files_called = false;
|
2022-01-08 10:27:06 +01:00
|
|
|
override_rewire(upload, "upload_files", () => {
|
2019-11-21 05:24:55 +01:00
|
|
|
upload_files_called = true;
|
2021-02-28 00:52:20 +01:00
|
|
|
});
|
2023-04-12 13:10:40 +02:00
|
|
|
let compose_actions_start_called = false;
|
2023-10-06 01:43:50 +02:00
|
|
|
override(compose_reply, "respond_to_message", () => {
|
2023-04-12 13:10:40 +02:00
|
|
|
compose_actions_start_called = true;
|
|
|
|
});
|
2019-11-21 05:24:55 +01:00
|
|
|
|
|
|
|
paste_handler(event);
|
2021-06-10 08:32:54 +02:00
|
|
|
assert.ok(get_as_file_called);
|
|
|
|
assert.ok(upload_files_called);
|
2023-04-12 13:10:40 +02:00
|
|
|
assert.ok(compose_actions_start_called);
|
2019-11-21 05:24:55 +01:00
|
|
|
upload_files_called = false;
|
|
|
|
event = {
|
2024-05-15 04:24:25 +02:00
|
|
|
originalEvent: new ClipboardEvent({}),
|
2019-11-21 05:24:55 +01:00
|
|
|
};
|
|
|
|
paste_handler(event);
|
|
|
|
assert.equal(upload_files_called, false);
|
|
|
|
});
|
|
|
|
|
2023-04-12 13:10:40 +02:00
|
|
|
test("uppy_events", ({override_rewire, mock_template}) => {
|
2023-12-14 23:51:33 +01:00
|
|
|
$("#compose_banners .upload_banner .moving_bar").css = noop;
|
2023-01-09 07:43:39 +01:00
|
|
|
$("#compose_banners .upload_banner").length = 0;
|
2023-12-14 23:51:33 +01:00
|
|
|
override_rewire(compose_ui, "smart_insert_inline", noop);
|
2023-01-09 07:43:39 +01:00
|
|
|
|
2019-11-21 05:24:55 +01:00
|
|
|
const callbacks = {};
|
|
|
|
let state = {};
|
2018-04-05 04:29:21 +02:00
|
|
|
|
2021-03-10 06:31:13 +01:00
|
|
|
uppy_stub = function () {
|
2019-11-21 05:24:55 +01:00
|
|
|
return {
|
2022-11-17 23:33:43 +01:00
|
|
|
setMeta() {},
|
|
|
|
use() {},
|
|
|
|
on(event_name, callback) {
|
2019-11-21 05:24:55 +01:00
|
|
|
callbacks[event_name] = callback;
|
|
|
|
},
|
2023-03-28 07:54:27 +02:00
|
|
|
removeFile() {},
|
2020-07-02 01:41:40 +02:00
|
|
|
getState: () => ({
|
2022-06-12 21:43:55 +02:00
|
|
|
info: [
|
|
|
|
{
|
|
|
|
type: state.type,
|
|
|
|
details: state.details,
|
|
|
|
message: state.message,
|
|
|
|
},
|
|
|
|
],
|
2020-07-02 01:41:40 +02:00
|
|
|
}),
|
2019-11-21 05:24:55 +01:00
|
|
|
};
|
2021-03-10 06:31:13 +01:00
|
|
|
};
|
2024-05-15 03:39:14 +02:00
|
|
|
upload.setup_upload(upload.compose_config);
|
2023-03-28 07:54:27 +02:00
|
|
|
assert.equal(Object.keys(callbacks).length, 5);
|
2017-11-25 22:22:36 +01:00
|
|
|
|
2019-11-21 05:24:55 +01:00
|
|
|
const on_upload_success_callback = callbacks["upload-success"];
|
|
|
|
const file = {
|
|
|
|
name: "copenhagen.png",
|
2023-03-28 07:54:27 +02:00
|
|
|
id: "123",
|
2019-11-21 05:24:55 +01:00
|
|
|
};
|
|
|
|
let response = {
|
|
|
|
body: {
|
|
|
|
uri: "/user_uploads/4/cb/rue1c-MlMUjDAUdkRrEM4BTJ/copenhagen.png",
|
|
|
|
},
|
|
|
|
};
|
2023-04-12 13:10:40 +02:00
|
|
|
|
2019-11-21 05:24:55 +01:00
|
|
|
let compose_ui_replace_syntax_called = false;
|
2023-11-02 20:47:30 +01:00
|
|
|
override_rewire(compose_ui, "replace_syntax", (old_syntax, new_syntax, $textarea) => {
|
2019-11-21 05:24:55 +01:00
|
|
|
compose_ui_replace_syntax_called = true;
|
2020-04-17 17:37:06 +02:00
|
|
|
assert.equal(old_syntax, "[translated: Uploading copenhagen.png…]()");
|
2020-07-15 00:34:28 +02:00
|
|
|
assert.equal(
|
|
|
|
new_syntax,
|
2020-07-29 22:14:07 +02:00
|
|
|
"[copenhagen.png](/user_uploads/4/cb/rue1c-MlMUjDAUdkRrEM4BTJ/copenhagen.png)",
|
2020-07-15 00:34:28 +02:00
|
|
|
);
|
2023-11-02 20:47:30 +01:00
|
|
|
assert.equal($textarea, $("textarea#compose-textarea"));
|
2021-02-28 01:26:48 +01:00
|
|
|
});
|
2019-11-21 05:24:55 +01:00
|
|
|
let compose_ui_autosize_textarea_called = false;
|
2023-01-09 07:02:05 +01:00
|
|
|
override_rewire(compose_ui, "autosize_textarea", () => {
|
2019-11-21 05:24:55 +01:00
|
|
|
compose_ui_autosize_textarea_called = true;
|
2021-02-28 01:26:48 +01:00
|
|
|
});
|
2019-11-21 05:24:55 +01:00
|
|
|
on_upload_success_callback(file, response);
|
2023-04-12 13:10:40 +02:00
|
|
|
|
2021-06-10 08:32:54 +02:00
|
|
|
assert.ok(compose_ui_replace_syntax_called);
|
|
|
|
assert.ok(compose_ui_autosize_textarea_called);
|
2017-11-25 22:22:36 +01:00
|
|
|
|
2019-11-21 05:24:55 +01:00
|
|
|
response = {
|
|
|
|
body: {
|
|
|
|
uri: undefined,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
compose_ui_replace_syntax_called = false;
|
|
|
|
compose_ui_autosize_textarea_called = false;
|
|
|
|
on_upload_success_callback(file, response);
|
|
|
|
assert.equal(compose_ui_replace_syntax_called, false);
|
|
|
|
assert.equal(compose_ui_autosize_textarea_called, false);
|
|
|
|
|
2023-01-09 07:43:39 +01:00
|
|
|
mock_template("compose_banner/upload_banner.hbs", false, (data) => {
|
|
|
|
assert.equal(data.banner_type, "error");
|
|
|
|
assert.equal(data.banner_text, "Some error message");
|
2023-12-28 07:50:10 +01:00
|
|
|
return "<banner-stub>";
|
2023-01-09 07:43:39 +01:00
|
|
|
});
|
2019-11-21 05:24:55 +01:00
|
|
|
state = {
|
|
|
|
type: "error",
|
2021-05-10 07:02:14 +02:00
|
|
|
details: "Some error",
|
2019-11-21 05:24:55 +01:00
|
|
|
message: "Some error message",
|
|
|
|
};
|
|
|
|
const on_info_visible_callback = callbacks["info-visible"];
|
2023-01-09 07:43:39 +01:00
|
|
|
$("#compose_banners .upload_banner .upload_msg").text("");
|
2020-03-07 12:44:17 +01:00
|
|
|
compose_ui_replace_syntax_called = false;
|
|
|
|
const on_restriction_failed_callback = callbacks["restriction-failed"];
|
2019-11-21 05:24:55 +01:00
|
|
|
on_info_visible_callback();
|
2023-11-02 20:47:30 +01:00
|
|
|
override_rewire(compose_ui, "replace_syntax", (old_syntax, new_syntax, $textarea) => {
|
2020-03-07 12:44:17 +01:00
|
|
|
compose_ui_replace_syntax_called = true;
|
2020-04-17 17:37:06 +02:00
|
|
|
assert.equal(old_syntax, "[translated: Uploading copenhagen.png…]()");
|
2020-03-07 12:44:17 +01:00
|
|
|
assert.equal(new_syntax, "");
|
2023-11-02 20:47:30 +01:00
|
|
|
assert.equal($textarea, $("textarea#compose-textarea"));
|
2021-02-28 01:26:48 +01:00
|
|
|
});
|
2020-03-07 12:44:17 +01:00
|
|
|
on_restriction_failed_callback(file, null, null);
|
2021-06-10 08:32:54 +02:00
|
|
|
assert.ok(compose_ui_replace_syntax_called);
|
2020-03-07 12:44:17 +01:00
|
|
|
compose_ui_replace_syntax_called = false;
|
2023-11-02 19:29:54 +01:00
|
|
|
$("textarea#compose-textarea").val("user modified text");
|
2020-03-07 12:44:17 +01:00
|
|
|
on_restriction_failed_callback(file, null, null);
|
2021-06-10 08:32:54 +02:00
|
|
|
assert.ok(compose_ui_replace_syntax_called);
|
2023-11-02 19:29:54 +01:00
|
|
|
assert.equal($("textarea#compose-textarea").val(), "user modified text");
|
2019-11-21 05:24:55 +01:00
|
|
|
|
|
|
|
state = {
|
|
|
|
type: "error",
|
|
|
|
message: "No Internet connection",
|
|
|
|
};
|
|
|
|
on_info_visible_callback();
|
|
|
|
|
|
|
|
state = {
|
|
|
|
type: "error",
|
|
|
|
details: "Upload Error",
|
|
|
|
};
|
|
|
|
on_info_visible_callback();
|
|
|
|
|
2023-10-06 22:02:43 +02:00
|
|
|
let hide_upload_banner_called = false;
|
|
|
|
override_rewire(upload, "hide_upload_banner", (_uppy, config) => {
|
|
|
|
hide_upload_banner_called = true;
|
|
|
|
assert.equal(config.mode, "compose");
|
|
|
|
});
|
|
|
|
|
2019-11-21 05:24:55 +01:00
|
|
|
const on_upload_error_callback = callbacks["upload-error"];
|
2023-01-09 07:43:39 +01:00
|
|
|
$("#compose_banners .upload_banner .upload_msg").text("");
|
2020-03-07 12:54:07 +01:00
|
|
|
compose_ui_replace_syntax_called = false;
|
2019-11-21 05:24:55 +01:00
|
|
|
response = {
|
|
|
|
body: {
|
|
|
|
msg: "Response message",
|
|
|
|
},
|
|
|
|
};
|
2020-03-07 12:54:07 +01:00
|
|
|
on_upload_error_callback(file, null, response);
|
2021-06-10 08:32:54 +02:00
|
|
|
assert.ok(compose_ui_replace_syntax_called);
|
2019-11-21 05:24:55 +01:00
|
|
|
|
2020-03-07 12:54:07 +01:00
|
|
|
compose_ui_replace_syntax_called = false;
|
2024-05-15 04:24:25 +02:00
|
|
|
on_upload_error_callback(file, null, undefined);
|
2021-06-10 08:32:54 +02:00
|
|
|
assert.ok(compose_ui_replace_syntax_called);
|
2023-03-28 07:54:27 +02:00
|
|
|
|
2023-01-09 07:43:39 +01:00
|
|
|
$("#compose_banners .upload_banner .upload_msg").text("");
|
2023-10-06 22:02:43 +02:00
|
|
|
assert.ok(hide_upload_banner_called);
|
2023-11-02 19:29:54 +01:00
|
|
|
$("textarea#compose-textarea").val("user modified text");
|
2020-03-07 12:54:07 +01:00
|
|
|
on_upload_error_callback(file, null);
|
2021-06-10 08:32:54 +02:00
|
|
|
assert.ok(compose_ui_replace_syntax_called);
|
2023-11-02 19:29:54 +01:00
|
|
|
assert.equal($("textarea#compose-textarea").val(), "user modified text");
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|
2023-06-16 12:49:02 +02:00
|
|
|
|
2023-09-21 06:25:07 +02:00
|
|
|
test("main_file_drop_compose_mode", ({override, override_rewire}) => {
|
2023-06-16 12:49:02 +02:00
|
|
|
uppy_stub = function () {
|
|
|
|
return {
|
|
|
|
setMeta() {},
|
|
|
|
use() {},
|
|
|
|
cancelAll() {},
|
|
|
|
on() {},
|
|
|
|
getFiles() {},
|
|
|
|
removeFile() {},
|
|
|
|
};
|
|
|
|
};
|
|
|
|
upload.initialize();
|
|
|
|
|
|
|
|
let prevent_default_counter = 0;
|
|
|
|
const drag_event = {
|
|
|
|
preventDefault() {
|
|
|
|
prevent_default_counter += 1;
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
// dragover event test
|
2023-11-08 20:34:01 +01:00
|
|
|
const dragover_handler = $(".app, #navbar-fixed-container").get_on_handler("dragover");
|
2023-06-16 12:49:02 +02:00
|
|
|
dragover_handler(drag_event);
|
|
|
|
assert.equal(prevent_default_counter, 1);
|
|
|
|
|
|
|
|
// dragenter event test
|
2023-11-08 20:34:01 +01:00
|
|
|
const dragenter_handler = $(".app, #navbar-fixed-container").get_on_handler("dragenter");
|
2023-06-16 12:49:02 +02:00
|
|
|
dragenter_handler(drag_event);
|
|
|
|
assert.equal(prevent_default_counter, 2);
|
|
|
|
|
|
|
|
const files = ["file1", "file2"];
|
|
|
|
const drop_event = {
|
|
|
|
target: "target",
|
|
|
|
preventDefault() {
|
|
|
|
prevent_default_counter += 1;
|
|
|
|
},
|
|
|
|
originalEvent: {
|
|
|
|
dataTransfer: {
|
|
|
|
files,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
$(".message_edit_form form").last = () => ({length: 0});
|
|
|
|
|
2023-11-08 20:34:01 +01:00
|
|
|
const drop_handler = $(".app, #navbar-fixed-container").get_on_handler("drop");
|
2023-06-16 12:49:02 +02:00
|
|
|
|
|
|
|
// Test drop on compose box
|
|
|
|
let upload_files_called = false;
|
|
|
|
override_rewire(upload, "upload_files", () => {
|
|
|
|
upload_files_called = true;
|
|
|
|
});
|
2023-09-21 06:25:07 +02:00
|
|
|
override(compose_state, "composing", () => true);
|
2023-06-16 12:49:02 +02:00
|
|
|
drop_handler(drop_event);
|
|
|
|
assert.equal(upload_files_called, true);
|
|
|
|
assert.equal(prevent_default_counter, 3);
|
|
|
|
|
|
|
|
// Test reply to message if no edit and compose box open
|
|
|
|
upload_files_called = false;
|
2023-09-21 06:25:07 +02:00
|
|
|
override(compose_state, "composing", () => false);
|
2023-06-16 12:49:02 +02:00
|
|
|
const msg = {
|
|
|
|
type: "stream",
|
|
|
|
stream: "Denmark",
|
|
|
|
topic: "python",
|
|
|
|
sender_full_name: "Bob Roberts",
|
|
|
|
sender_id: 40,
|
|
|
|
};
|
|
|
|
let compose_actions_start_called = false;
|
|
|
|
let compose_actions_respond_to_message_called = false;
|
2024-02-20 01:25:16 +01:00
|
|
|
override(message_lists, "current", {
|
2023-06-16 12:49:02 +02:00
|
|
|
selected_message() {
|
|
|
|
return msg;
|
|
|
|
},
|
|
|
|
});
|
|
|
|
compose_actions.start = () => {
|
|
|
|
compose_actions_start_called = true;
|
|
|
|
};
|
2023-10-06 01:43:50 +02:00
|
|
|
compose_reply.respond_to_message = () => {
|
2023-06-16 12:49:02 +02:00
|
|
|
compose_actions_respond_to_message_called = true;
|
|
|
|
};
|
|
|
|
drop_handler(drop_event);
|
|
|
|
assert.equal(upload_files_called, true);
|
|
|
|
assert.equal(compose_actions_start_called, false);
|
|
|
|
assert.equal(compose_actions_respond_to_message_called, true);
|
|
|
|
|
2023-09-06 23:04:07 +02:00
|
|
|
// Test drop on Recent Conversations view
|
2023-06-16 12:49:02 +02:00
|
|
|
compose_actions_respond_to_message_called = false;
|
2024-02-20 01:25:16 +01:00
|
|
|
override(message_lists, "current", {
|
2023-06-16 12:49:02 +02:00
|
|
|
selected_message() {
|
|
|
|
return undefined;
|
|
|
|
},
|
|
|
|
});
|
|
|
|
upload_files_called = false;
|
|
|
|
drop_handler(drop_event);
|
|
|
|
assert.equal(upload_files_called, true);
|
|
|
|
assert.equal(compose_actions_start_called, true);
|
|
|
|
assert.equal(compose_actions_respond_to_message_called, false);
|
|
|
|
});
|
|
|
|
|
2023-09-21 06:25:07 +02:00
|
|
|
test("main_file_drop_edit_mode", ({override, override_rewire}) => {
|
2023-06-16 12:49:02 +02:00
|
|
|
uppy_stub = function () {
|
|
|
|
return {
|
|
|
|
setMeta() {},
|
|
|
|
use() {},
|
|
|
|
cancelAll() {},
|
|
|
|
on() {},
|
|
|
|
getFiles() {},
|
|
|
|
removeFile() {},
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2024-05-15 03:39:14 +02:00
|
|
|
upload.setup_upload(upload.edit_config(40));
|
2023-06-16 12:49:02 +02:00
|
|
|
upload.initialize();
|
2023-09-21 06:25:07 +02:00
|
|
|
override(compose_state, "composing", () => false);
|
2023-06-16 12:49:02 +02:00
|
|
|
let prevent_default_counter = 0;
|
|
|
|
const drag_event = {
|
|
|
|
preventDefault() {
|
|
|
|
prevent_default_counter += 1;
|
|
|
|
},
|
|
|
|
};
|
2024-01-17 07:53:40 +01:00
|
|
|
const $drag_drop_container = $(`#message-row-1-${CSS.escape(40)} .message_edit_form`);
|
2023-06-16 12:49:02 +02:00
|
|
|
|
|
|
|
// Dragover event test
|
2023-11-08 20:34:01 +01:00
|
|
|
const dragover_handler = $(".app, #navbar-fixed-container").get_on_handler("dragover");
|
2023-06-16 12:49:02 +02:00
|
|
|
dragover_handler(drag_event);
|
|
|
|
assert.equal(prevent_default_counter, 1);
|
|
|
|
// Dragenter event test
|
2023-11-08 20:34:01 +01:00
|
|
|
const dragenter_handler = $(".app, #navbar-fixed-container").get_on_handler("dragenter");
|
2023-06-16 12:49:02 +02:00
|
|
|
dragenter_handler(drag_event);
|
|
|
|
assert.equal(prevent_default_counter, 2);
|
|
|
|
|
|
|
|
const files = ["file1", "file2"];
|
|
|
|
const drop_event = {
|
|
|
|
target: "target",
|
|
|
|
preventDefault() {
|
|
|
|
prevent_default_counter += 1;
|
|
|
|
},
|
|
|
|
originalEvent: {
|
|
|
|
dataTransfer: {
|
|
|
|
files,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
2023-11-08 20:34:01 +01:00
|
|
|
const drop_handler = $(".app, #navbar-fixed-container").get_on_handler("drop");
|
2023-06-16 12:49:02 +02:00
|
|
|
let upload_files_called = false;
|
|
|
|
let dropped_row_id = -1;
|
|
|
|
override_rewire(upload, "upload_files", (_, config) => {
|
|
|
|
dropped_row_id = config.row;
|
|
|
|
upload_files_called = true;
|
|
|
|
});
|
|
|
|
$(".message_edit_form form").last = () => ({length: 1});
|
2023-09-21 06:25:07 +02:00
|
|
|
override(rows, "get_message_id", () => 40);
|
2023-06-16 12:49:02 +02:00
|
|
|
|
|
|
|
// Edit box which registered the event handler no longer exists.
|
|
|
|
$drag_drop_container.closest = (element) => {
|
|
|
|
assert.equal(element, "html");
|
|
|
|
return {length: 0};
|
|
|
|
};
|
|
|
|
|
|
|
|
drop_handler(drop_event);
|
|
|
|
assert.equal(upload_files_called, false);
|
|
|
|
|
|
|
|
$drag_drop_container.closest = (element) => {
|
|
|
|
assert.equal(element, "html");
|
|
|
|
return {length: 1};
|
|
|
|
};
|
|
|
|
|
|
|
|
// Drag and dropped in one of the edit boxes. The event would be taken care of by
|
|
|
|
// drag_drop_container event handlers.
|
|
|
|
|
2023-09-21 06:25:07 +02:00
|
|
|
override(rows, "get_message_id", () => 40);
|
2023-06-16 12:49:02 +02:00
|
|
|
// Edit box open
|
|
|
|
$(".message_edit_form form").last = () => ({length: 1});
|
|
|
|
drop_handler(drop_event);
|
|
|
|
assert.equal(upload_files_called, true);
|
|
|
|
assert.equal(dropped_row_id, 40);
|
|
|
|
});
|