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: Avoid __Rewire__ for clipboard API.

Steve Howell7cf62cd6b113
diff --git a/frontend_tests/node_tests/popovers.js b/frontend_tests/node_tests/popovers.js
index d72ad4ea8ea..58a5d7a17da 100644
--- a/frontend_tests/node_tests/popovers.js
+++ b/frontend_tests/node_tests/popovers.js
@@ -43,8 +43,6 @@ const message_edit = zrequire("message_edit");
// Bypass some scary code that runs when we import the module.
const popovers = with_field($.fn, "popover", noop, () => zrequire("popovers"));
-popovers.__Rewire__("ClipboardJS", noop);
-
const alice = {
full_name: "Alice Smith",
@@ -98,6 +96,7 @@ function make_image_stubber() {
function test_ui(label, f) {
run_test(label, (override) => {
+ override(popovers, "clipboard_enable", noop);
popovers.register_click_handlers();
f(override);
});
diff --git a/static/js/popovers.js b/static/js/popovers.js
index 4276ed4e2a1..4c25af2f250 100644
--- a/static/js/popovers.js
+++ b/static/js/popovers.js
@@ -54,6 +54,12 @@ let userlist_placement = "right";
let list_of_popovers = [];
+export function clipboard_enable(arg) {
+ // arg is a selector or element
+ // We extract this function for testing purpose.
+ return new ClipboardJS(arg);
+}
+
function elem_to_user_id(elem) {
return Number.parseInt(elem.attr("data-user-id"), 10);
}
@@ -115,7 +121,7 @@ function init_email_clipboard() {
*/
if (copy_email_icon[0]) {
copy_email_icon.removeClass("hide_copy_icon");
- const copy_email_clipboard = new ClipboardJS(copy_email_icon[0]);
+ const copy_email_clipboard = clipboard_enable(copy_email_icon[0]);
copy_email_clipboard.on("success", copy_email_handler);
}
}
@@ -1251,7 +1257,7 @@ export function register_click_handlers() {
e.preventDefault();
});
- new ClipboardJS(".copy_link");
+ clipboard_enable(".copy_link");
$("body").on("click", ".copy_link", function (e) {
hide_actions_popover();
@@ -1273,7 +1279,7 @@ export function register_click_handlers() {
e.preventDefault();
});
- new ClipboardJS(".copy_mention_syntax");
+ clipboard_enable(".copy_mention_syntax");
$("body").on("click", ".copy_mention_syntax", (e) => {
hide_all();