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");
|
|
|
|
const {run_test} = require("./lib/test");
|
|
|
|
const $ = require("./lib/zjquery");
|
2020-12-01 00:02:16 +01:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
set_global("Image", class Image {});
|
2023-02-22 23:04:10 +01:00
|
|
|
mock_esm("../src/overlays", {
|
2022-11-17 23:33:43 +01:00
|
|
|
close_overlay() {},
|
2021-03-06 17:37:51 +01:00
|
|
|
|
2022-11-17 23:33:43 +01:00
|
|
|
close_active() {},
|
|
|
|
open_overlay() {},
|
2018-07-16 20:50:57 +02:00
|
|
|
});
|
2023-02-22 23:04:10 +01:00
|
|
|
mock_esm("../src/popovers", {
|
2022-11-17 23:33:43 +01:00
|
|
|
hide_all() {},
|
2018-07-16 20:50:57 +02:00
|
|
|
});
|
2023-02-22 23:04:10 +01:00
|
|
|
const rows = mock_esm("../src/rows");
|
2019-05-21 17:36:39 +02:00
|
|
|
|
2023-02-22 23:04:10 +01:00
|
|
|
const message_store = mock_esm("../src/message_store");
|
2021-03-06 17:37:51 +01:00
|
|
|
|
2020-12-01 23:21:38 +01:00
|
|
|
const lightbox = zrequire("lightbox");
|
|
|
|
|
2021-03-14 13:26:24 +01:00
|
|
|
function test(label, f) {
|
2022-07-10 01:06:33 +02:00
|
|
|
run_test(label, (helpers) => {
|
2021-03-14 13:26:24 +01:00
|
|
|
lightbox.clear_for_testing();
|
2022-07-10 01:06:33 +02:00
|
|
|
f(helpers);
|
2021-03-14 13:26:24 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-07-10 01:06:33 +02:00
|
|
|
test("pan_and_zoom", ({override}) => {
|
2022-01-25 11:36:19 +01:00
|
|
|
const $img = $.create("img-stub");
|
|
|
|
const $link = $.create("link-stub");
|
|
|
|
const $msg = $.create("msg-stub");
|
2020-02-10 23:21:06 +01:00
|
|
|
|
2022-08-18 20:49:42 +02:00
|
|
|
$img.closest = () => [];
|
2020-02-10 17:59:40 +01:00
|
|
|
|
2022-01-25 11:36:19 +01:00
|
|
|
$img.set_parent($link);
|
|
|
|
$link.closest = () => $msg;
|
2021-02-22 17:01:29 +01:00
|
|
|
|
2022-07-10 01:06:33 +02:00
|
|
|
override(rows, "id", ($row) => {
|
2022-01-25 11:36:19 +01:00
|
|
|
assert.equal($row, $msg);
|
2021-02-22 17:01:29 +01:00
|
|
|
return 1234;
|
|
|
|
});
|
|
|
|
|
2022-01-25 11:36:19 +01:00
|
|
|
$img.attr("src", "example");
|
2020-02-10 23:21:06 +01:00
|
|
|
|
|
|
|
let fetched_zid;
|
|
|
|
|
|
|
|
message_store.get = (zid) => {
|
|
|
|
fetched_zid = zid;
|
2020-07-15 01:29:15 +02:00
|
|
|
return "message-stub";
|
2020-02-10 23:21:06 +01:00
|
|
|
};
|
2019-05-21 17:36:39 +02:00
|
|
|
|
2023-09-14 05:38:58 +02:00
|
|
|
$.create(
|
|
|
|
".focused-message-list .message_inline_image img, .focused-message-list .message_inline_video video",
|
|
|
|
{children: []},
|
|
|
|
);
|
2023-09-14 07:41:33 +02:00
|
|
|
const open_image = lightbox.build_open_media_function();
|
2022-01-25 11:36:19 +01:00
|
|
|
open_image($img);
|
2020-02-10 23:21:06 +01:00
|
|
|
|
|
|
|
assert.equal(fetched_zid, 1234);
|
2018-07-16 20:50:57 +02:00
|
|
|
});
|
2019-05-21 17:36:39 +02:00
|
|
|
|
2022-07-10 01:06:33 +02:00
|
|
|
test("youtube", ({override}) => {
|
2020-07-15 01:29:15 +02:00
|
|
|
const href = "https://youtube.com/some-random-clip";
|
2022-01-25 11:36:19 +01:00
|
|
|
const $img = $.create("img-stub");
|
|
|
|
const $link = $.create("link-stub");
|
|
|
|
const $msg = $.create("msg-stub");
|
2020-02-10 23:21:06 +01:00
|
|
|
|
2022-07-10 01:06:33 +02:00
|
|
|
override(rows, "id", ($row) => {
|
2022-01-25 11:36:19 +01:00
|
|
|
assert.equal($row, $msg);
|
2021-02-22 17:01:29 +01:00
|
|
|
return 4321;
|
|
|
|
});
|
2020-02-21 17:29:23 +01:00
|
|
|
|
2022-08-18 20:49:42 +02:00
|
|
|
$img.attr("src", href);
|
2020-02-10 23:21:06 +01:00
|
|
|
|
2022-08-18 20:49:42 +02:00
|
|
|
$img.closest = (sel) => {
|
2020-07-15 01:29:15 +02:00
|
|
|
if (sel === ".youtube-video") {
|
2020-02-10 23:21:06 +01:00
|
|
|
// We just need a nonempty array to
|
|
|
|
// set is_youtube_video to true.
|
2020-07-15 01:29:15 +02:00
|
|
|
return ["whatever"];
|
2020-02-10 23:21:06 +01:00
|
|
|
}
|
|
|
|
return [];
|
|
|
|
};
|
|
|
|
|
2022-01-25 11:36:19 +01:00
|
|
|
$img.set_parent($link);
|
|
|
|
$link.closest = () => $msg;
|
|
|
|
$link.attr("href", href);
|
2019-05-21 17:36:39 +02:00
|
|
|
|
2023-09-14 05:38:58 +02:00
|
|
|
$.create(
|
|
|
|
".focused-message-list .message_inline_image img, .focused-message-list .message_inline_video video",
|
|
|
|
{children: []},
|
|
|
|
);
|
2019-05-21 17:36:39 +02:00
|
|
|
|
2023-09-14 07:41:33 +02:00
|
|
|
const open_image = lightbox.build_open_media_function();
|
2022-01-25 11:36:19 +01:00
|
|
|
open_image($img);
|
2023-09-14 07:41:33 +02:00
|
|
|
assert.equal($(".media-actions .open").attr("href"), href);
|
2019-05-21 17:36:39 +02:00
|
|
|
});
|