snapshot of https://github.com/zulip/zulip.git @ 48c69911c7dd4e03b20552eb3bd77ad8151c1357 (2026-09-15)
Some checks failed
Code scanning / CodeQL (push) Failing after 15s
Zulip production suite / Ubuntu 22.04 production build (push) Failing after 26s
Zulip production suite / Debian 12 production install with custom db name and user (push) Has been skipped
Zulip production suite / Ubuntu 22.04 production install and PostgreSQL upgrade with pgroonga (push) Has been skipped
Zulip production suite / Ubuntu 24.04 production install (push) Has been skipped
Zulip production suite / Ubuntu 26.04 production install (push) Has been skipped
Zulip production suite / Debian 13 production install (push) Has been skipped
Zulip production suite / 7.0 Version Upgrade (push) Has been skipped
Zulip production suite / 8.0 Version Upgrade (push) Has been skipped
Zulip production suite / 6.0 Version Upgrade (push) Has been skipped
Zulip production suite / 10.0 Version Upgrade (push) Has been skipped
Zulip production suite / 9.0 Version Upgrade (push) Has been skipped
Zulip production suite / 12.0 Version Upgrade (push) Has been skipped
Zulip production suite / 11.0 Version Upgrade (push) Has been skipped
GitHub Actions Security Analysis with zizmor / zizmor (push) Failing after 3s
Zulip CI / Debian 12 (Python 3.11, backend + documentation) (push) Failing after 26s
Zulip CI / Ubuntu 22.04 (Python 3.10, backend + frontend) (push) Failing after 3s
Zulip CI / Ubuntu 24.04 (Python 3.12, backend) (push) Failing after 25s
Zulip CI / Ubuntu 26.04 (Python 3.14, backend) (push) Failing after 25s
Zulip CI / Debian 13 (Python 3.13, backend) (push) Failing after 28s
Zulip production suite / Required jobs (push) Has been cancelled
Zulip CI / Required jobs (push) Has been cancelled
API Documentation Update Check / check-feature-level-updated (push) Has been cancelled
API Documentation Update Check / notify-if-api-docs-changed (push) Has been cancelled
Some checks failed
Code scanning / CodeQL (push) Failing after 15s
Zulip production suite / Ubuntu 22.04 production build (push) Failing after 26s
Zulip production suite / Debian 12 production install with custom db name and user (push) Has been skipped
Zulip production suite / Ubuntu 22.04 production install and PostgreSQL upgrade with pgroonga (push) Has been skipped
Zulip production suite / Ubuntu 24.04 production install (push) Has been skipped
Zulip production suite / Ubuntu 26.04 production install (push) Has been skipped
Zulip production suite / Debian 13 production install (push) Has been skipped
Zulip production suite / 7.0 Version Upgrade (push) Has been skipped
Zulip production suite / 8.0 Version Upgrade (push) Has been skipped
Zulip production suite / 6.0 Version Upgrade (push) Has been skipped
Zulip production suite / 10.0 Version Upgrade (push) Has been skipped
Zulip production suite / 9.0 Version Upgrade (push) Has been skipped
Zulip production suite / 12.0 Version Upgrade (push) Has been skipped
Zulip production suite / 11.0 Version Upgrade (push) Has been skipped
GitHub Actions Security Analysis with zizmor / zizmor (push) Failing after 3s
Zulip CI / Debian 12 (Python 3.11, backend + documentation) (push) Failing after 26s
Zulip CI / Ubuntu 22.04 (Python 3.10, backend + frontend) (push) Failing after 3s
Zulip CI / Ubuntu 24.04 (Python 3.12, backend) (push) Failing after 25s
Zulip CI / Ubuntu 26.04 (Python 3.14, backend) (push) Failing after 25s
Zulip CI / Debian 13 (Python 3.13, backend) (push) Failing after 28s
Zulip production suite / Required jobs (push) Has been cancelled
Zulip CI / Required jobs (push) Has been cancelled
API Documentation Update Check / check-feature-level-updated (push) Has been cancelled
API Documentation Update Check / notify-if-api-docs-changed (push) Has been cancelled
This commit is contained in:
128
web/tests/clipboard_handler.test.cjs
Normal file
128
web/tests/clipboard_handler.test.cjs
Normal file
@@ -0,0 +1,128 @@
|
||||
"use strict";
|
||||
|
||||
const assert = require("node:assert/strict");
|
||||
|
||||
const {JSDOM} = require("jsdom");
|
||||
|
||||
const {make_stream} = require("./lib/example_stream.cjs");
|
||||
const {make_user} = require("./lib/example_user.cjs");
|
||||
const {zrequire, mock_esm} = require("./lib/namespace.cjs");
|
||||
const {run_test} = require("./lib/test.cjs");
|
||||
|
||||
const settings_config = zrequire("settings_config");
|
||||
mock_esm("../src/user_settings", {
|
||||
user_settings: {
|
||||
web_channel_default_view: settings_config.web_channel_default_view_values.channel_feed.code,
|
||||
},
|
||||
});
|
||||
const clipboard_handler = zrequire("clipboard_handler");
|
||||
const stream_data = zrequire("stream_data");
|
||||
const people = zrequire("people");
|
||||
|
||||
const hamlet = make_user({
|
||||
user_id: 15,
|
||||
email: "hamlet@example.com",
|
||||
full_name: "Hamlet",
|
||||
});
|
||||
|
||||
people.add_active_user(hamlet);
|
||||
|
||||
run_test("copy_link_to_clipboard", async ({override}) => {
|
||||
const stream = make_stream({
|
||||
name: "Stream",
|
||||
description: "Color and Lights",
|
||||
stream_id: 1,
|
||||
subscribed: true,
|
||||
});
|
||||
stream_data.add_sub_for_tests(stream);
|
||||
const {window} = new JSDOM();
|
||||
global.document = window.document;
|
||||
|
||||
// Mock DataTransfer for testing purposes
|
||||
class MockDataTransfer {
|
||||
constructor() {
|
||||
this.data = {};
|
||||
}
|
||||
|
||||
setData(type, value) {
|
||||
this.data[type] = value;
|
||||
}
|
||||
|
||||
getData(type) {
|
||||
return this.data[type] || "";
|
||||
}
|
||||
}
|
||||
|
||||
// Store the copy event callback and clipboardData
|
||||
let clipboardData;
|
||||
let copyEventCallback;
|
||||
override(window.document, "addEventListener", (event, callback) => {
|
||||
if (event === "copy") {
|
||||
copyEventCallback = callback;
|
||||
}
|
||||
});
|
||||
|
||||
// Stub execCommand to trigger the copy event
|
||||
override(window.document, "execCommand", (command) => {
|
||||
if (command === "copy" && copyEventCallback) {
|
||||
const copyEvent = new window.Event("copy", {bubbles: true, cancelable: true});
|
||||
copyEvent.clipboardData = new MockDataTransfer();
|
||||
copyEventCallback(copyEvent);
|
||||
clipboardData = copyEvent.clipboardData;
|
||||
}
|
||||
return true;
|
||||
});
|
||||
|
||||
// Helper function to simulate clipboard handling
|
||||
async function simulateClipboardData(link) {
|
||||
await clipboard_handler.copy_link_to_clipboard(link);
|
||||
return {
|
||||
plainText: clipboardData.getData("text/plain"),
|
||||
htmlText: clipboardData.getData("text/html"),
|
||||
markdownText: clipboardData.getData("text/x-gfm"),
|
||||
};
|
||||
}
|
||||
|
||||
const normal_stream_with_topic =
|
||||
"http://zulip.zulipdev.com/#narrow/channel/1-Stream/topic/normal.20topic";
|
||||
const normal_stream_with_topic_and_message =
|
||||
"http://zulip.zulipdev.com/#narrow/channel/1-Stream/topic/normal.20topic/near/1";
|
||||
const normal_stream = "http://zulip.zulipdev.com/#narrow/channel/1-Stream/";
|
||||
const dm_message = "http://zulip.zulipdev.com/#narrow/dm/15-dm/near/43";
|
||||
|
||||
let clipboardDataResult = await simulateClipboardData(normal_stream_with_topic);
|
||||
assert.equal(clipboardDataResult.plainText, normal_stream_with_topic);
|
||||
assert.equal(
|
||||
clipboardDataResult.htmlText,
|
||||
`<a href="http://zulip.zulipdev.com/#narrow/channel/1-Stream/topic/normal.20topic">#Stream > normal topic</a>`,
|
||||
);
|
||||
assert.equal(
|
||||
clipboardDataResult.markdownText,
|
||||
`[#Stream > normal topic](http://zulip.zulipdev.com/#narrow/channel/1-Stream/topic/normal.20topic)`,
|
||||
);
|
||||
|
||||
clipboardDataResult = await simulateClipboardData(normal_stream_with_topic_and_message);
|
||||
assert.equal(clipboardDataResult.plainText, normal_stream_with_topic_and_message);
|
||||
assert.equal(
|
||||
clipboardDataResult.htmlText,
|
||||
`<a href="http://zulip.zulipdev.com/#narrow/channel/1-Stream/topic/normal.20topic/near/1">#Stream > normal topic @ 💬</a>`,
|
||||
);
|
||||
assert.equal(
|
||||
clipboardDataResult.markdownText,
|
||||
`[#Stream > normal topic @ 💬](http://zulip.zulipdev.com/#narrow/channel/1-Stream/topic/normal.20topic/near/1)`,
|
||||
);
|
||||
|
||||
clipboardDataResult = await simulateClipboardData(normal_stream);
|
||||
assert.equal(clipboardDataResult.plainText, normal_stream);
|
||||
assert.equal(
|
||||
clipboardDataResult.htmlText,
|
||||
`<a href="http://zulip.zulipdev.com/#narrow/channel/1-Stream/">#Stream</a>`,
|
||||
);
|
||||
assert.equal(
|
||||
clipboardDataResult.markdownText,
|
||||
`[#Stream](http://zulip.zulipdev.com/#narrow/channel/1-Stream/)`,
|
||||
);
|
||||
|
||||
clipboardDataResult = await simulateClipboardData(dm_message);
|
||||
assert.equal(clipboardDataResult.plainText, dm_message);
|
||||
});
|
||||
Reference in New Issue
Block a user