mirror of
https://github.com/zulip/zulip.git
synced 2025-11-03 13:33:24 +00:00
For most functions that we were using __Rewire__ for,
it's better to just use the override helper, which
use __Rewire__ under the hood, but also resets
the reference at the end of run_tests.
Another nice thing about override() is that it reports
when you never actually needed the mock, and this
commit fixes the instances found here.
I didn't replace every call to __Rewire__. The
remaining ones fall under these categories:
* I looked for ") =>" in my code sweep,
so I missed stuff like "noop" helpers.
* Sometimes we directly update something
in a module that's not a function. This
is generally evil, and we should use setters.
* Some tests have setup() helpers or similar
that complicated this code sweep, so I
simply punted.
* Somes modules rely on intra-test leaks. We
should fix those, but I just punted for the
main code sweep.
87 lines
2.0 KiB
JavaScript
87 lines
2.0 KiB
JavaScript
"use strict";
|
|
|
|
const {strict: assert} = require("assert");
|
|
|
|
const {mock_module, set_global, zrequire} = require("../zjsunit/namespace");
|
|
const {run_test} = require("../zjsunit/test");
|
|
const $ = require("../zjsunit/zjquery");
|
|
|
|
set_global("Image", class Image {});
|
|
mock_module("overlays", {
|
|
close_overlay: () => {},
|
|
|
|
close_active: () => {},
|
|
open_overlay: () => {},
|
|
});
|
|
mock_module("popovers", {
|
|
hide_all: () => {},
|
|
});
|
|
|
|
const message_store = mock_module("message_store");
|
|
const rows = zrequire("rows");
|
|
|
|
const lightbox = zrequire("lightbox");
|
|
|
|
run_test("pan_and_zoom", (override) => {
|
|
const img = $.create("img-stub");
|
|
const link = $.create("link-stub");
|
|
const msg = $.create("msg-stub");
|
|
|
|
$(img).closest = () => [];
|
|
|
|
img.set_parent(link);
|
|
link.closest = () => msg;
|
|
|
|
override(rows, "id", (row) => {
|
|
assert.equal(row, msg);
|
|
return 1234;
|
|
});
|
|
|
|
img.attr("src", "example");
|
|
|
|
let fetched_zid;
|
|
|
|
message_store.get = (zid) => {
|
|
fetched_zid = zid;
|
|
return "message-stub";
|
|
};
|
|
|
|
override(lightbox, "render_lightbox_list_images", () => {});
|
|
|
|
lightbox.open(img);
|
|
|
|
assert.equal(fetched_zid, 1234);
|
|
});
|
|
|
|
run_test("youtube", (override) => {
|
|
const href = "https://youtube.com/some-random-clip";
|
|
const img = $.create("img-stub");
|
|
const link = $.create("link-stub");
|
|
const msg = $.create("msg-stub");
|
|
|
|
override(rows, "id", (row) => {
|
|
assert.equal(row, msg);
|
|
return 4321;
|
|
});
|
|
|
|
$(img).attr("src", href);
|
|
|
|
$(img).closest = (sel) => {
|
|
if (sel === ".youtube-video") {
|
|
// We just need a nonempty array to
|
|
// set is_youtube_video to true.
|
|
return ["whatever"];
|
|
}
|
|
return [];
|
|
};
|
|
|
|
img.set_parent(link);
|
|
link.closest = () => msg;
|
|
link.attr("href", href);
|
|
|
|
override(lightbox, "render_lightbox_list_images", () => {});
|
|
|
|
lightbox.open(img);
|
|
assert.equal($(".image-actions .open").attr("href"), href);
|
|
});
|