Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

node tests: Add test() wrapper for lightbox.

Steve Howell92e611a787b4
diff --git a/frontend_tests/node_tests/lightbox.js b/frontend_tests/node_tests/lightbox.js
index f53d5c2335f..b23ee8a984d 100644
--- a/frontend_tests/node_tests/lightbox.js
+++ b/frontend_tests/node_tests/lightbox.js
@@ -23,7 +23,14 @@ const rows = zrequire("rows");
const lightbox = zrequire("lightbox");
-run_test("pan_and_zoom", (override) => {
+function test(label, f) {
+ run_test(label, (override) => {
+ lightbox.clear_for_testing();
+ f(override);
+ });
+}
+
+test("pan_and_zoom", (override) => {
const img = $.create("img-stub");
const link = $.create("link-stub");
const msg = $.create("msg-stub");
@@ -54,7 +61,7 @@ run_test("pan_and_zoom", (override) => {
assert.equal(fetched_zid, 1234);
});
-run_test("youtube", (override) => {
+test("youtube", (override) => {
const href = "https://youtube.com/some-random-clip";
const img = $.create("img-stub");
const link = $.create("link-stub");
diff --git a/static/js/lightbox.js b/static/js/lightbox.js
index 4ff51d9fa94..ae9af3e8432 100644
--- a/static/js/lightbox.js
+++ b/static/js/lightbox.js
@@ -12,6 +12,11 @@ let is_open = false;
// memoized instead of being looked up multiple times.
const asset_map = new Map();
+export function clear_for_testing() {
+ is_open = false;
+ asset_map.clear();
+}
+
export function render_lightbox_list_images(preview_source) {
if (!is_open) {
const images = Array.prototype.slice.call($(".focused_table .message_inline_image img"));