2020-08-01 03:43:15 +02:00
|
|
|
"use strict";
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
var common = require("../casper_lib/common.js");
|
2018-03-20 19:32:38 +01:00
|
|
|
|
|
|
|
common.start_and_log_in();
|
|
|
|
|
|
|
|
casper.then(function () {
|
2020-07-15 01:29:15 +02:00
|
|
|
casper.test.info("Sending messages");
|
2018-03-20 19:32:38 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
// setup environment: several messages to different topics
|
|
|
|
common.then_send_many([
|
2020-07-15 00:34:28 +02:00
|
|
|
{stream: "Verona", subject: "copy-paste-subject #1", content: "copy paste test A"},
|
2018-03-20 19:32:38 +01:00
|
|
|
|
2020-07-15 00:34:28 +02:00
|
|
|
{stream: "Verona", subject: "copy-paste-subject #1", content: "copy paste test B"},
|
2018-03-20 19:32:38 +01:00
|
|
|
|
2020-07-15 00:34:28 +02:00
|
|
|
{stream: "Verona", subject: "copy-paste-subject #2", content: "copy paste test C"},
|
2018-03-20 19:32:38 +01:00
|
|
|
|
2020-07-15 00:34:28 +02:00
|
|
|
{stream: "Verona", subject: "copy-paste-subject #2", content: "copy paste test D"},
|
2018-03-20 19:32:38 +01:00
|
|
|
|
2020-07-15 00:34:28 +02:00
|
|
|
{stream: "Verona", subject: "copy-paste-subject #2", content: "copy paste test E"},
|
2018-03-20 19:32:38 +01:00
|
|
|
|
2020-07-15 00:34:28 +02:00
|
|
|
{stream: "Verona", subject: "copy-paste-subject #3", content: "copy paste test F"},
|
2018-03-20 19:32:38 +01:00
|
|
|
|
2020-07-15 00:34:28 +02:00
|
|
|
{stream: "Verona", subject: "copy-paste-subject #3", content: "copy paste test G"},
|
2018-03-20 19:32:38 +01:00
|
|
|
]);
|
|
|
|
|
|
|
|
common.wait_for_receive(function () {
|
2020-07-15 00:34:28 +02:00
|
|
|
common.expected_messages(
|
|
|
|
"zhome",
|
|
|
|
[
|
|
|
|
"Verona > copy-paste-subject #1",
|
|
|
|
"Verona > copy-paste-subject #2",
|
|
|
|
"Verona > copy-paste-subject #3",
|
|
|
|
],
|
|
|
|
[
|
|
|
|
"<p>copy paste test A</p>",
|
|
|
|
"<p>copy paste test B</p>",
|
|
|
|
"<p>copy paste test C</p>",
|
|
|
|
"<p>copy paste test D</p>",
|
|
|
|
"<p>copy paste test E</p>",
|
|
|
|
"<p>copy paste test F</p>",
|
|
|
|
"<p>copy paste test G</p>",
|
|
|
|
]
|
|
|
|
);
|
2018-03-20 19:32:38 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
casper.then(function () {
|
2020-07-15 01:29:15 +02:00
|
|
|
casper.test.info("Messages were sent successfully");
|
2018-03-20 19:32:38 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
function get_message_node(message) {
|
|
|
|
return $('.message_row .message_content:contains("' + message + '")').get(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
function copy_messages(start_message, end_message) {
|
2020-07-15 00:34:28 +02:00
|
|
|
return casper.evaluate(
|
|
|
|
function (get_message_node, start_message, end_message) {
|
|
|
|
// select messages from start_message to end_message
|
|
|
|
var selectedRange = document.createRange();
|
|
|
|
selectedRange.setStart(get_message_node(start_message));
|
|
|
|
selectedRange.setEnd(get_message_node(end_message));
|
|
|
|
window.getSelection().removeAllRanges();
|
|
|
|
window.getSelection().addRange(selectedRange);
|
|
|
|
|
|
|
|
// Remove existing copy/paste divs, which may linger from the previous
|
|
|
|
// example. (The code clears these out with a zero-second timeout, which
|
|
|
|
// is probably sufficient for human users, but which causes problems here.)
|
|
|
|
$("#copytempdiv").remove();
|
|
|
|
|
|
|
|
// emulate copy event
|
|
|
|
$("body").trigger($.Event("keydown", {which: 67, ctrlKey: true}));
|
|
|
|
|
|
|
|
// find temp div with copied text
|
|
|
|
var temp_div = $("#copytempdiv");
|
|
|
|
return temp_div
|
|
|
|
.children("p")
|
|
|
|
.get()
|
|
|
|
.map(function (p) {
|
|
|
|
return p.textContent;
|
|
|
|
});
|
|
|
|
},
|
|
|
|
{
|
|
|
|
get_message_node: get_message_node,
|
|
|
|
start_message: start_message,
|
|
|
|
end_message: end_message,
|
|
|
|
}
|
|
|
|
);
|
2018-03-20 19:32:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// test copying first message from topic
|
|
|
|
casper.then(function () {
|
2020-07-15 01:29:15 +02:00
|
|
|
var actual_copied_lines = copy_messages("copy paste test C", "copy paste test C");
|
2018-03-20 19:32:38 +01:00
|
|
|
var expected_copied_lines = [];
|
2020-07-15 00:34:28 +02:00
|
|
|
casper.test.assertEquals(
|
|
|
|
actual_copied_lines,
|
|
|
|
expected_copied_lines,
|
|
|
|
"Copying was handled by browser"
|
|
|
|
);
|
2018-03-20 19:32:38 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
// test copying last message from topic
|
|
|
|
casper.then(function () {
|
2020-07-15 01:29:15 +02:00
|
|
|
var actual_copied_lines = copy_messages("copy paste test E", "copy paste test E");
|
2018-03-20 19:32:38 +01:00
|
|
|
var expected_copied_lines = [];
|
2020-07-15 00:34:28 +02:00
|
|
|
casper.test.assertEquals(
|
|
|
|
actual_copied_lines,
|
|
|
|
expected_copied_lines,
|
|
|
|
"Copying was handled by browser"
|
|
|
|
);
|
2018-03-20 19:32:38 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
// test copying two first messages from topic
|
|
|
|
casper.then(function () {
|
2020-07-15 01:29:15 +02:00
|
|
|
var actual_copied_lines = copy_messages("copy paste test C", "copy paste test D");
|
2020-07-23 04:32:20 +02:00
|
|
|
var expected_copied_lines = ["Desdemona: copy paste test C", "Desdemona: copy paste test D"];
|
2020-07-15 00:34:28 +02:00
|
|
|
casper.test.assertEquals(
|
|
|
|
actual_copied_lines,
|
|
|
|
expected_copied_lines,
|
|
|
|
"Copying was handled by custom handler"
|
|
|
|
);
|
2018-03-20 19:32:38 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
// test copying all messages from topic
|
|
|
|
casper.then(function () {
|
2020-07-15 01:29:15 +02:00
|
|
|
var actual_copied_lines = copy_messages("copy paste test C", "copy paste test E");
|
2020-07-15 00:34:28 +02:00
|
|
|
var expected_copied_lines = [
|
2020-07-23 04:32:20 +02:00
|
|
|
"Desdemona: copy paste test C",
|
|
|
|
"Desdemona: copy paste test D",
|
|
|
|
"Desdemona: copy paste test E",
|
2020-07-15 00:34:28 +02:00
|
|
|
];
|
|
|
|
casper.test.assertEquals(
|
|
|
|
actual_copied_lines,
|
|
|
|
expected_copied_lines,
|
|
|
|
"Copying was handled by custom handler"
|
|
|
|
);
|
2018-03-20 19:32:38 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
// test copying last message from previous topic and first message from next topic
|
|
|
|
casper.then(function () {
|
2020-07-15 01:29:15 +02:00
|
|
|
var actual_copied_lines = copy_messages("copy paste test B", "copy paste test C");
|
2018-03-20 19:32:38 +01:00
|
|
|
var expected_copied_lines = [
|
2020-07-15 01:29:15 +02:00
|
|
|
"Verona > copy-paste-subject #1 Today",
|
2020-07-23 04:32:20 +02:00
|
|
|
"Desdemona: copy paste test B",
|
2020-07-15 01:29:15 +02:00
|
|
|
"Verona > copy-paste-subject #2 Today",
|
2020-07-23 04:32:20 +02:00
|
|
|
"Desdemona: copy paste test C",
|
2018-03-20 19:32:38 +01:00
|
|
|
];
|
2020-07-15 00:34:28 +02:00
|
|
|
casper.test.assertEquals(
|
|
|
|
actual_copied_lines,
|
|
|
|
expected_copied_lines,
|
|
|
|
"Copying was handled by custom handler"
|
|
|
|
);
|
2018-03-20 19:32:38 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
// test copying last message from previous topic and all messages from next topic
|
|
|
|
casper.then(function () {
|
2020-07-15 01:29:15 +02:00
|
|
|
var actual_copied_lines = copy_messages("copy paste test B", "copy paste test E");
|
2018-03-20 19:32:38 +01:00
|
|
|
var expected_copied_lines = [
|
2020-07-15 01:29:15 +02:00
|
|
|
"Verona > copy-paste-subject #1 Today",
|
2020-07-23 04:32:20 +02:00
|
|
|
"Desdemona: copy paste test B",
|
2020-07-15 01:29:15 +02:00
|
|
|
"Verona > copy-paste-subject #2 Today",
|
2020-07-23 04:32:20 +02:00
|
|
|
"Desdemona: copy paste test C",
|
|
|
|
"Desdemona: copy paste test D",
|
|
|
|
"Desdemona: copy paste test E",
|
2018-03-20 19:32:38 +01:00
|
|
|
];
|
2020-07-15 00:34:28 +02:00
|
|
|
casper.test.assertEquals(
|
|
|
|
actual_copied_lines,
|
|
|
|
expected_copied_lines,
|
|
|
|
"Copying was handled by custom handler"
|
|
|
|
);
|
2018-03-20 19:32:38 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
// test copying all messages from previous topic and first message from next topic
|
|
|
|
casper.then(function () {
|
2020-07-15 01:29:15 +02:00
|
|
|
var actual_copied_lines = copy_messages("copy paste test A", "copy paste test C");
|
2018-03-20 19:32:38 +01:00
|
|
|
var expected_copied_lines = [
|
2020-07-15 01:29:15 +02:00
|
|
|
"Verona > copy-paste-subject #1 Today",
|
2020-07-23 04:32:20 +02:00
|
|
|
"Desdemona: copy paste test A",
|
|
|
|
"Desdemona: copy paste test B",
|
2020-07-15 01:29:15 +02:00
|
|
|
"Verona > copy-paste-subject #2 Today",
|
2020-07-23 04:32:20 +02:00
|
|
|
"Desdemona: copy paste test C",
|
2018-03-20 19:32:38 +01:00
|
|
|
];
|
2020-07-15 00:34:28 +02:00
|
|
|
casper.test.assertEquals(
|
|
|
|
actual_copied_lines,
|
|
|
|
expected_copied_lines,
|
|
|
|
"Copying was handled by custom handler"
|
|
|
|
);
|
2018-03-20 19:32:38 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
// test copying message from several topics
|
|
|
|
casper.then(function () {
|
2020-07-15 01:29:15 +02:00
|
|
|
var actual_copied_lines = copy_messages("copy paste test B", "copy paste test F");
|
2018-03-20 19:32:38 +01:00
|
|
|
var expected_copied_lines = [
|
2020-07-15 01:29:15 +02:00
|
|
|
"Verona > copy-paste-subject #1 Today",
|
2020-07-23 04:32:20 +02:00
|
|
|
"Desdemona: copy paste test B",
|
2020-07-15 01:29:15 +02:00
|
|
|
"Verona > copy-paste-subject #2 Today",
|
2020-07-23 04:32:20 +02:00
|
|
|
"Desdemona: copy paste test C",
|
|
|
|
"Desdemona: copy paste test D",
|
|
|
|
"Desdemona: copy paste test E",
|
2020-07-15 01:29:15 +02:00
|
|
|
"Verona > copy-paste-subject #3 Today",
|
2020-07-23 04:32:20 +02:00
|
|
|
"Desdemona: copy paste test F",
|
2018-03-20 19:32:38 +01:00
|
|
|
];
|
2020-07-15 00:34:28 +02:00
|
|
|
casper.test.assertEquals(
|
|
|
|
actual_copied_lines,
|
|
|
|
expected_copied_lines,
|
|
|
|
"Copying was handled by custom handler"
|
|
|
|
);
|
2018-03-20 19:32:38 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
// Run the above queued actions.
|
|
|
|
casper.run(function () {
|
|
|
|
casper.test.done();
|
|
|
|
});
|